add_old_hunk_to_hunk(hunk, oldhunk)
click to toggle source
def add_old_hunk_to_hunk(hunk, oldhunk)
hunk.merge(oldhunk)
end
add_to_output(output, string)
click to toggle source
def add_to_output(output, string)
output << string
end
all_strings?(*args)
click to toggle source
def all_strings?(*args)
args.flatten.all? { |a| String === a}
end
any_multiline_strings?(*args)
click to toggle source
def any_multiline_strings?(*args)
all_strings?(*args) && args.flatten.any? { |a| multiline?(a) }
end
blue(text)
click to toggle source
def blue(text)
color(text, 34)
end
coerce_to_string(string_or_array)
click to toggle source
def coerce_to_string(string_or_array)
return string_or_array unless Array === string_or_array
diffably_stringify(string_or_array).join("\n")
end
color_diff(diff)
click to toggle source
def color_diff(diff)
return diff unless color?
diff.lines.map { |line|
case line[0].chr
when "+"
green line
when "-"
red line
when "@"
line[1].chr == "@" ? blue(line) : normal(line)
else
normal(line)
end
}.join
end
diffably_stringify(array)
click to toggle source
def diffably_stringify(array)
array.map do |entry|
if Array === entry
entry.inspect
else
entry.to_s.gsub("\n", "\\n")
end
end
end
finalize_output(output, final_line)
click to toggle source
def finalize_output(output, final_line)
add_to_output(output, final_line)
add_to_output(output, "\n")
end
green(text)
click to toggle source
def green(text)
color(text, 32)
end
handle_encoding_errors()
click to toggle source
def handle_encoding_errors
if @actual.source_encoding != @expected.source_encoding
"Could not produce a diff because the encoding of the actual string (#{@actual.source_encoding}) "+
"differs from the encoding of the expected string (#{@expected.source_encoding})"
else
"Could not produce a diff because of the encoding of the string (#{@expected.source_encoding})"
end
end
hunks()
click to toggle source
def hunks
@hunks ||= HunkGenerator.new(@actual, @expected).hunks
end
multiline?(string)
click to toggle source
def multiline?(string)
string.include?("\n".encode(string.encoding))
end
no_numbers?(*args)
click to toggle source
def no_numbers?(*args)
args.flatten.none? { |a| Numeric === a}
end
no_procs?(*args)
click to toggle source
def no_procs?(*args)
args.flatten.none? { |a| Proc === a}
end
normal(text)
click to toggle source
def normal(text)
color(text, 0)
end
object_to_string(object)
click to toggle source
def object_to_string(object)
object = @object_preparer.call(object)
case object
when Hash
object.keys.sort_by { |k| k.to_s }.map do |key|
pp_key = PP.singleline_pp(key, "")
pp_value = PP.singleline_pp(object[key], "")
"#{pp_key} => #{pp_value},"
end.join("\n")
when String
object =~ /\n/ ? object : object.inspect
else
PP.pp(object,"")
end
end
pick_encoding(source_a, source_b)
click to toggle source
def pick_encoding(source_a, source_b)
Encoding.compatible?(source_a, source_b) || Encoding.default_external
end
red(text)
click to toggle source
def red(text)
color(text, 31)
end