Class: Test::Unit::Diff::UnifiedDiffer

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

Instance Method Summary collapse

Methods inherited from Differ

#initialize

Constructor Details

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

Instance Method Details

#diff(options = {}) ⇒ Object



435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
# File 'lib/test/unit/diff.rb', line 435

def diff(options={})
  groups = SequenceMatcher.new(@from, @to).grouped_operations
  return [] if groups.empty?
  return [] if same_content?(groups)

  show_context = options[:show_context]
  show_context = true if show_context.nil?
  result = ["--- #{options[:from_label]}".rstrip,
            "+++ #{options[: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