summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorAkinori MUSHA <knu@idaemons.org>2019-01-24 17:13:24 +0900
committerAustin Ziegler <austin@zieglers.ca>2019-01-26 00:40:04 -0500
commit01e0caeda9ae38b7868f35987844fd9f67aef005 (patch)
tree3c71bfc6beb9d139af5dfd15f120ea0e7fea8d1c /spec
parent8b325657b09ff2e382d626deed38beb02731f96a (diff)
downloaddiff-lcs-01e0caeda9ae38b7868f35987844fd9f67aef005.tar.gz
Add #to_ary to Diff::LCS::Change and Diff::LCS::ContextChange
It would be quite handy if you could write as follows: ```ruby Diff::LCS.sdiff(a, b).each do |action, (old_position, old_element), (new_position, new_element)| case action when '!' # replace when '-' # delete when '+' # insert end end ```
Diffstat (limited to 'spec')
-rw-r--r--spec/change_spec.rb24
1 files changed, 24 insertions, 0 deletions
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