Module: Test::Unit::Diff

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

Defined Under Namespace

Classes: Differ, ReadableDiffer, SequenceMatcher, UnifiedDiffer

Class Method Summary collapse

Class Method Details

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



532
533
534
535
# File 'lib/test/unit/diff.rb', line 532

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



514
515
516
517
518
# File 'lib/test/unit/diff.rb', line 514

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



520
521
522
# File 'lib/test/unit/diff.rb', line 520

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

.need_fold?(diff) ⇒ Boolean

Returns:

  • (Boolean)


510
511
512
# File 'lib/test/unit/diff.rb', line 510

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

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



524
525
526
# File 'lib/test/unit/diff.rb', line 524

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

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



528
529
530
# File 'lib/test/unit/diff.rb', line 528

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