summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/diff/lcs/change.rb4
-rw-r--r--spec/change_spec.rb24
2 files changed, 28 insertions, 0 deletions
diff --git a/lib/diff/lcs/change.rb b/lib/diff/lcs/change.rb
index 9229069..8dae83b 100644
--- a/lib/diff/lcs/change.rb
+++ b/lib/diff/lcs/change.rb
@@ -41,6 +41,8 @@ class Diff::LCS::Change
[ @action, @position, @element ]
end
+ alias to_ary to_a
+
def self.from_a(arr)
arr = arr.flatten(1)
case arr.size
@@ -132,6 +134,8 @@ class Diff::LCS::ContextChange < Diff::LCS::Change
]
end
+ alias to_ary to_a
+
def inspect(*args)
to_a.inspect
end
diff --git a/spec/change_spec.rb b/spec/change_spec.rb
index dfe385f..5128dc1 100644
--- a/spec/change_spec.rb
+++ b/spec/change_spec.rb
@@ -62,4 +62,28 @@ describe Diff::LCS::Change do
it { should_not be_finished_a }
it { should be_finished_b }
end
+
+ describe "as array" do
+ it "should be converted" do
+ action, position, element = described_class.new('!', 0, 'element')
+ expect(action).to eq '!'
+ expect(position).to eq 0
+ expect(element).to eq 'element'
+ end
+ end
+end
+
+describe Diff::LCS::ContextChange do
+ describe "as array" do
+ it "should be converted" do
+ action, (old_position, old_element), (new_position, new_element) =
+ described_class.new('!', 1, 'old_element', 2, 'new_element')
+
+ expect(action).to eq '!'
+ expect(old_position).to eq 1
+ expect(old_element).to eq 'old_element'
+ expect(new_position).to eq 2
+ expect(new_element).to eq 'new_element'
+ end
+ end
end