Module: Test::Unit::Diff

Defined in:
lib/test/unit/diff.rb

Defined Under Namespace

Classes: Differ, ReadableDiffer, SequenceMatcher, UTF8Line, UnifiedDiffer

Class Method Summary (collapse)

Class Method Details

+ (Object) diff(differ_class, from, to, options = {})



725
726
727
728
729
730
731
732
733
734
735
736
737
# File 'lib/test/unit/diff.rb', line 725

def diff(differ_class, from, to, options={})
  differ = differ_class.new(from.split(/\r?\n/), to.split(/\r?\n/))
  lines = differ.diff(options)
  if Object.const_defined?(:EncodingError)
    begin
      lines.join("\n")
    rescue EncodingError
      lines.collect {|line| line.force_encoding("ASCII-8BIT")}.join("\n")
    end
  else
    lines.join("\n")
  end
end

+ (Object) fold(string)



707
708
709
710
711
# File 'lib/test/unit/diff.rb', line 707

def fold(string)
  string.split(/\r?\n/).collect do |line|
    line.gsub(/(.{78})/, "\\1\n")
  end.join("\n")
end

+ (Object) folded_readable(from, to, options = {})



713
714
715
# File 'lib/test/unit/diff.rb', line 713

def folded_readable(from, to, options={})
  readable(fold(from), fold(to), options)
end

+ (Boolean) need_fold?(diff)



703
704
705
# File 'lib/test/unit/diff.rb', line 703

def need_fold?(diff)
  /^[-+].{79}/ =~ diff
end

+ (Object) readable(from, to, options = {})



717
718
719
# File 'lib/test/unit/diff.rb', line 717

def readable(from, to, options={})
  diff(ReadableDiffer, from, to, options)
end

+ (Object) unified(from, to, options = {})



721
722
723
# File 'lib/test/unit/diff.rb', line 721

def unified(from, to, options={})
  diff(UnifiedDiffer, from, to, options)
end