In Files

  • test-unit-3.3.7/lib/test/unit/diff.rb

Class/Module Index [+]

Quicksearch

Test::Unit::Diff::UnifiedDiffer

Public Instance Methods

diff(options={}) click to toggle source
 
               # File test-unit-3.3.7/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