Rename Mutant::Differ to Mutant::Diff

This commit is contained in:
Markus Schirp 2014-05-11 15:04:11 +00:00
parent f8ec4e5e28
commit 336b1b61de
6 changed files with 169 additions and 172 deletions

View file

@ -211,7 +211,7 @@ require 'mutant/cli/classifier'
require 'mutant/cli/classifier/namespace'
require 'mutant/cli/classifier/method'
require 'mutant/color'
require 'mutant/differ'
require 'mutant/diff'
require 'mutant/reporter'
require 'mutant/reporter/null'
require 'mutant/reporter/cli'

View file

@ -2,7 +2,7 @@
module Mutant
# Class to create diffs from source code
class Differ
class Diff
include Adamantium::Flat, Concord.new(:old, :new)
# Return source diff
@ -20,7 +20,7 @@ module Mutant
when 0
nil
when 1
Diff::LCS::Hunk.new(old, new, diffs.first, max_length, 0)
::Diff::LCS::Hunk.new(old, new, diffs.first, max_length, 0)
.diff(:unified) << "\n"
else
$stderr.puts(
@ -55,7 +55,7 @@ module Mutant
# @param [String] old
# @param [String] new
#
# @return [Differ]
# @return [Diff]
#
# @api private
#
@ -85,7 +85,7 @@ module Mutant
# @api private
#
def diffs
Diff::LCS.diff(old, new)
::Diff::LCS.diff(old, new)
end
memoize :diffs
@ -118,5 +118,5 @@ module Mutant
end.format(line)
end
end # Differ
end # Diff
end # Mutant

View file

@ -92,7 +92,7 @@ module Mutant
#
def details
original, current = mutation.original_source, mutation.source
differ = Differ.build(original, current)
differ = Diff.build(original, current)
color? ? differ.colorized_diff : differ.diff
end

View file

@ -0,0 +1,162 @@
# encoding: utf-8
require 'spec_helper'
describe Mutant::Diff do
let(:object) { described_class }
describe '.build' do
subject { object.build(old_string, new_string) }
let(:old_string) { "foo\nbar" }
let(:new_string) { "bar\nbaz" }
it { should eql(Mutant::Diff.new(%w(foo bar), %w(bar baz))) }
end
describe '.colorize_line' do
let(:object) { described_class }
subject { object.colorize_line(line) }
context 'line beginning with "+"' do
let(:line) { '+line' }
it { should eql(Mutant::Color::GREEN.format(line)) }
end
context 'line beginning with "-"' do
let(:line) { '-line' }
it { should eql(Mutant::Color::RED.format(line)) }
end
context 'line beginning in other char' do
let(:line) { ' line' }
it { should eql(line) }
end
end
describe '#diff' do
let(:object) { described_class.new(old, new) }
subject { object.diff }
context 'when there is a diff at begin of hunk' do
let(:old) { %w(foo bar) }
let(:new) { %w(baz bar) }
let(:expectation) do
strip_indent(<<-STR)
@@ -1,3 +1,3 @@
-foo
+baz
bar
STR
end
it { should eql(expectation) }
it_should_behave_like 'an idempotent method'
end
context 'when there is a diff NOT at begin of hunk' do
let(:old) { %w(foo bar) }
let(:new) { %w(foo baz bar) }
let(:expectation) do
strip_indent(<<-STR)
@@ -1,3 +1,4 @@
foo
+baz
bar
STR
end
it { should eql(expectation) }
it_should_behave_like 'an idempotent method'
end
context 'when the diff has a long context at begin' do
let(:old) { %w(foo bar baz boz a b c) }
let(:new) { %w(foo bar baz boz a b c other) }
let(:expectation) do
strip_indent(<<-STR)
@@ -1,8 +1,9 @@
foo
bar
baz
boz
a
b
c
+other
STR
end
it { should eql(expectation) }
it_should_behave_like 'an idempotent method'
end
context 'when the diff has a long context at end, deleting' do
let(:old) { %w(other foo bar baz boz a b c) }
let(:new) { %w(foo bar baz boz a b c) }
let(:expectation) do
strip_indent(<<-STR)
@@ -1,9 +1,8 @@
-other
foo
bar
baz
boz
a
b
c
STR
end
it { should eql(expectation) }
it_should_behave_like 'an idempotent method'
end
context 'when the diff has a long context at end, inserting' do
let(:old) { %w(foo bar baz boz a b c) }
let(:new) { %w(other foo bar baz boz a b c) }
let(:expectation) do
strip_indent(<<-STR)
@@ -1,8 +1,9 @@
+other
foo
bar
baz
boz
a
b
c
STR
end
it { should eql(expectation) }
it_should_behave_like 'an idempotent method'
end
context 'when there is no diff' do
let(:old) { '' }
let(:new) { '' }
it { should be(nil) }
it_should_behave_like 'an idempotent method'
end
end
end

View file

@ -1,123 +0,0 @@
# encoding: utf-8
require 'spec_helper'
describe Mutant::Differ, '#diff' do
let(:object) { described_class.new(old, new) }
subject { object.diff }
context 'when there is a diff at begin of hunk' do
let(:old) { %w(foo bar) }
let(:new) { %w(baz bar) }
let(:expectation) do
strip_indent(<<-STR)
@@ -1,3 +1,3 @@
-foo
+baz
bar
STR
end
it { should eql(expectation) }
it_should_behave_like 'an idempotent method'
end
context 'when there is a diff NOT at begin of hunk' do
let(:old) { %w(foo bar) }
let(:new) { %w(foo baz bar) }
let(:expectation) do
strip_indent(<<-STR)
@@ -1,3 +1,4 @@
foo
+baz
bar
STR
end
it { should eql(expectation) }
it_should_behave_like 'an idempotent method'
end
context 'when the diff has a long context at begin' do
let(:old) { %w(foo bar baz boz a b c) }
let(:new) { %w(foo bar baz boz a b c other) }
let(:expectation) do
strip_indent(<<-STR)
@@ -1,8 +1,9 @@
foo
bar
baz
boz
a
b
c
+other
STR
end
it { should eql(expectation) }
it_should_behave_like 'an idempotent method'
end
context 'when the diff has a long context at end, deleting' do
let(:old) { %w(other foo bar baz boz a b c) }
let(:new) { %w(foo bar baz boz a b c) }
let(:expectation) do
strip_indent(<<-STR)
@@ -1,9 +1,8 @@
-other
foo
bar
baz
boz
a
b
c
STR
end
it { should eql(expectation) }
it_should_behave_like 'an idempotent method'
end
context 'when the diff has a long context at end, inserting' do
let(:old) { %w(foo bar baz boz a b c) }
let(:new) { %w(other foo bar baz boz a b c) }
let(:expectation) do
strip_indent(<<-STR)
@@ -1,8 +1,9 @@
+other
foo
bar
baz
boz
a
b
c
STR
end
it { should eql(expectation) }
it_should_behave_like 'an idempotent method'
end
context 'when there is no diff' do
let(:old) { '' }
let(:new) { '' }
it { should be(nil) }
it_should_behave_like 'an idempotent method'
end
end

View file

@ -1,42 +0,0 @@
# encoding: utf-8
require 'spec_helper'
describe Mutant::Differ do
let(:object) { described_class }
describe '.build' do
subject { object.build(old_string, new_string) }
let(:old_string) { "foo\nbar" }
let(:new_string) { "bar\nbaz" }
it { should eql(Mutant::Differ.new(%w(foo bar), %w(bar baz))) }
end
describe '.colorize_line' do
let(:object) { described_class }
subject { object.colorize_line(line) }
context 'line beginning with "+"' do
let(:line) { '+line' }
it { should eql(Mutant::Color::GREEN.format(line)) }
end
context 'line beginning with "-"' do
let(:line) { '-line' }
it { should eql(Mutant::Color::RED.format(line)) }
end
context 'line beginning in other char' do
let(:line) { ' line' }
it { should eql(line) }
end
end
end