Class: Test::Diff::ReadableDiffer

Inherits:
Differ
  • Object
show all
Defined in:
lib/test-unit-ext/diff.rb

Instance Method Summary collapse

Methods inherited from Differ

#initialize

Constructor Details

This class inherits a constructor from Test::Diff::Differ

Instance Method Details

#diff(options = {}) ⇒ Object



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/test-unit-ext/diff.rb', line 251

def diff(options={})
  result = []
  matcher = SequenceMatcher.new(@from, @to)
  matcher.operations.each do |args|
    tag, from_start, from_end, to_start, to_end = args
    case tag
    when :replace
      result.concat(diff_lines(from_start, from_end, to_start, to_end))
    when :delete
      result.concat(tag_deleted(@from[from_start...from_end]))
    when :insert
      result.concat(tag_inserted(@to[to_start...to_end]))
    when :equal
      result.concat(tag_equal(@from[from_start...from_end]))
    else
      raise "unknown tag: #{tag}"
    end
  end
  result
end