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

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



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

def diff(differ_class, from, to, options={})
  differ = differ_class.new(from.split(/\r?\n/), to.split(/\r?\n/))
  differ.diff(options).join("\n")
end

.fold(string) ⇒ Object



700
701
702
703
704
# File 'lib/test/unit/diff.rb', line 700

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

.folded_readable(from, to, options = {}) ⇒ Object



706
707
708
# File 'lib/test/unit/diff.rb', line 706

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

.need_fold?(diff) ⇒ Boolean

Returns:

  • (Boolean)


696
697
698
# File 'lib/test/unit/diff.rb', line 696

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

.readable(from, to, options = {}) ⇒ Object



710
711
712
# File 'lib/test/unit/diff.rb', line 710

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

.unified(from, to, options = {}) ⇒ Object



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

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