class Test::Unit::UI::Console::ColorizedReadableDiffer

Public Class Methods

new(from, to, runner) click to toggle source
Calls superclass method Test::Unit::Diff::Differ::new
# File test-unit-3.3.4/lib/test/unit/ui/console/testrunner.rb, line 607
def initialize(from, to, runner)
  @runner = runner
  super(from, to)
end

Public Instance Methods

need_diff?(options={}) click to toggle source
# File test-unit-3.3.4/lib/test/unit/ui/console/testrunner.rb, line 612
def need_diff?(options={})
  return false if one_line_all_change?
  operations.each do |tag,|
    return true if [:replace, :equal].include?(tag)
  end
  false
end

Private Instance Methods

color(name) click to toggle source
# File test-unit-3.3.4/lib/test/unit/ui/console/testrunner.rb, line 641
def color(name)
  @runner.__send__(:color, name)
end
cut_off_ratio() click to toggle source
# File test-unit-3.3.4/lib/test/unit/ui/console/testrunner.rb, line 645
def cut_off_ratio
  0
end
default_ratio() click to toggle source
# File test-unit-3.3.4/lib/test/unit/ui/console/testrunner.rb, line 649
def default_ratio
  0
end
diff_line(from_line, to_line) click to toggle source
# File test-unit-3.3.4/lib/test/unit/ui/console/testrunner.rb, line 678
def diff_line(from_line, to_line)
  to_operations = []
  from_line, to_line, _operations = line_operations(from_line, to_line)

  no_replace = true
  _operations.each do |tag,|
    if tag == :replace
      no_replace = false
      break
    end
  end

  output_single("?", color("diff-difference-tag"))
  output_single(" ")
  _operations.each do |tag, from_start, from_end, to_start, to_end|
    from_width = compute_width(from_line, from_start, from_end)
    to_width = compute_width(to_line, to_start, to_end)
    case tag
    when :replace
      output_single(from_line[from_start...from_end],
                    color("diff-deleted"))
      if (from_width < to_width)
        output_single(" " * (to_width - from_width))
      end
      to_operations << Proc.new do
        output_single(to_line[to_start...to_end],
                      color("diff-inserted"))
        if (to_width < from_width)
          output_single(" " * (from_width - to_width))
        end
      end
    when :delete
      output_single(from_line[from_start...from_end],
                    color("diff-deleted"))
      unless no_replace
        to_operations << Proc.new {output_single(" " * from_width)}
      end
    when :insert
      if no_replace
        output_single(to_line[to_start...to_end],
                      color("diff-inserted"))
      else
        output_single(" " * to_width)
        to_operations << Proc.new do
          output_single(to_line[to_start...to_end],
                        color("diff-inserted"))
        end
      end
    when :equal
      output_single(from_line[from_start...from_end])
      unless no_replace
        to_operations << Proc.new {output_single(" " * to_width)}
      end
    else
      raise "unknown tag: #{tag}"
    end
  end
  output("")

  unless to_operations.empty?
    output_single("?", color("diff-difference-tag"))
    output_single(" ")
    to_operations.each do |operation|
      operation.call
    end
    output("")
  end
end
one_line_all_change?() click to toggle source
# File test-unit-3.3.4/lib/test/unit/ui/console/testrunner.rb, line 621
def one_line_all_change?
  return false if operations.size != 1

  tag, from_start, from_end, to_start, to_end = operations.first
  return false if tag != :replace
  return false if [from_start, from_end] != [0, 1]
  return false if [from_start, from_end] != [to_start, to_end]

  _, _, _line_operations = line_operations(@from.first, @to.first)
  _line_operations.size == 1
end
output(something, color=nil) click to toggle source
# File test-unit-3.3.4/lib/test/unit/ui/console/testrunner.rb, line 637
def output(something, color=nil)
  @runner.__send__(:output, something, color)
end
output_single(something, color=nil) click to toggle source
# File test-unit-3.3.4/lib/test/unit/ui/console/testrunner.rb, line 633
def output_single(something, color=nil)
  @runner.__send__(:output_single, something, color)
end
tag(mark, color_name, contents) click to toggle source
# File test-unit-3.3.4/lib/test/unit/ui/console/testrunner.rb, line 653
def tag(mark, color_name, contents)
  _color = color(color_name)
  contents.each do |content|
    output_single(mark, _color)
    output_single(" ")
    output(content)
  end
end
tag_deleted(contents) click to toggle source
# File test-unit-3.3.4/lib/test/unit/ui/console/testrunner.rb, line 662
def tag_deleted(contents)
  tag("-", "diff-deleted-tag", contents)
end
tag_difference(contents) click to toggle source
# File test-unit-3.3.4/lib/test/unit/ui/console/testrunner.rb, line 674
def tag_difference(contents)
  tag("?", "diff-difference-tag", contents)
end
tag_equal(contents) click to toggle source
# File test-unit-3.3.4/lib/test/unit/ui/console/testrunner.rb, line 670
def tag_equal(contents)
  tag(" ", "normal", contents)
end
tag_inserted(contents) click to toggle source
# File test-unit-3.3.4/lib/test/unit/ui/console/testrunner.rb, line 666
def tag_inserted(contents)
  tag("+", "diff-inserted-tag", contents)
end