Class: Test::Diff::Differ
- Inherits:
-
Object
- Object
- Test::Diff::Differ
- Defined in:
- lib/test-unit-ext/diff.rb
Instance Method Summary collapse
- #compare ⇒ Object
-
#initialize(from, to) ⇒ Differ
constructor
A new instance of Differ.
Constructor Details
#initialize(from, to) ⇒ Differ
Returns a new instance of Differ.
128 129 130 131 |
# File 'lib/test-unit-ext/diff.rb', line 128 def initialize(from, to) @from = from @to = to end |
Instance Method Details
#compare ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/test-unit-ext/diff.rb', line 133 def compare 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(fancy_replace(from_start, from_end, to_start, to_end)) when :delete result.concat(tagging('-', @from[from_start..from_end])) when :insert result.concat(tagging('+', @to[to_start..to_end])) when :equal result.concat(tagging(' ', @from[from_start..from_end])) else raise "unknown tag: #{tag}" end end result end |