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



627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
# File 'lib/test/unit/diff.rb', line 627

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