Class: Test::Diff::UnifiedDiffer
- Defined in:
- lib/test-unit-ext/diff.rb
Instance Method Summary collapse
Methods inherited from Differ
Constructor Details
This class inherits a constructor from Test::Diff::Differ
Instance Method Details
#diff(options = {}) ⇒ Object
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
# File 'lib/test-unit-ext/diff.rb', line 403 def diff(={}) groups = SequenceMatcher.new(@from, @to).grouped_operations return [] if groups.empty? return [] if same_content?(groups) show_context = [:show_context] show_context = true if show_context.nil? result = ["--- #{[:from_label]}".rstrip, "+++ #{[:to_label]}".rstrip] groups.each do |operations| result << format_summary(operations, show_context) operations.each do |args| operation_tag, from_start, from_end, to_start, to_end = args case operation_tag when :replace result.concat(tag("-", @from[from_start...from_end])) result.concat(tag("+", @to[to_start...to_end])) when :delete result.concat(tag("-", @from[from_start...from_end])) when :insert result.concat(tag("+", @to[to_start...to_end])) when :equal result.concat(tag(" ", @from[from_start...from_end])) end end end result end |