diff options
author | Austin Ziegler <austin@zieglers.ca> | 2013-03-30 17:12:43 -0400 |
---|---|---|
committer | Austin Ziegler <austin@zieglers.ca> | 2013-03-30 17:14:19 -0400 |
commit | 4122e0b9e52fd6fc659dd5f1fc9f844a43ff02cf (patch) | |
tree | c97177a9dd6f3c3f84a09dcf87947908480177e4 /spec | |
parent | a72fbdc67d2be6937fd94baf9372bbb994b01be1 (diff) | |
download | diff-lcs-4122e0b9e52fd6fc659dd5f1fc9f844a43ff02cf.tar.gz |
Finalizing encoding-aware diff fixes.
* Diff::LCS::Hunk could not properly generate a difference for
comparison sets that are not US-ASCII-compatible because of the use of
literal regular expressions and strings. Jon Rowe (JonRowe) found this
in rspec/rspec-expectations#219 and provided a first pass
implementation in diff-lcs#15. I've reworked it because of test
failures in Rubinius when running in Ruby 1.9 mode. This coerces the
added values to the encoding of the old dataset (as determined by the
first piece of the old dataset).
https://github.com/rspec/rspec-expectations/issues/219
https://github.com/halostatue/diff-lcs/pull/15
* Adding Travis CI testing for Ruby 2.0.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/hunk_spec.rb | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/spec/hunk_spec.rb b/spec/hunk_spec.rb index 9c21bce..0741b87 100644 --- a/spec/hunk_spec.rb +++ b/spec/hunk_spec.rb @@ -2,38 +2,42 @@ require 'spec_helper' -describe "Diff::LCS::Hunk" do +def h(v) + v.to_s.bytes.to_a.map { |e| "%02x" % e }.join +end +describe "Diff::LCS::Hunk" do if String.method_defined?(:encoding) let(:old_data) { ["Tu avec carté {count} itém has".encode('UTF-16LE')] } let(:new_data) { ["Tu avec carte {count} item has".encode('UTF-16LE')] } - let(:peices) { Diff::LCS.diff old_data, new_data } - let(:hunk) { Diff::LCS::Hunk.new(old_data, new_data, peices[0], 3, 0) } + let(:pieces) { Diff::LCS.diff old_data, new_data } + let(:hunk) { Diff::LCS::Hunk.new(old_data, new_data, pieces[0], 3, 0) } - it 'should be able to produce a unified diff from the two peices' do + it 'should be able to produce a unified diff from the two pieces' do expected = (<<-EOD.encode('UTF-16LE').chomp) @@ -1,2 +1,2 @@ -Tu avec carté {count} itém has +-Tu avec carté {count} itém has +Tu avec carte {count} item has EOD expect(hunk.diff(:unified).to_s == expected).to eql true end - it 'should be able to produce a context diff from the two peices' do + it 'should be able to produce a context diff from the two pieces' do expected = (<<-EOD.encode('UTF-16LE').chomp) *************** *** 1,2 **** -Tu avec carté {count} itém has +!Tu avec carté {count} itém has --- 1,2 ---- -Tu avec carte {count} item has +!Tu avec carte {count} item has EOD + expect(hunk.diff(:context).to_s == expected).to eql true end - it 'should be able to produce an old diff from the two peices' do + it 'should be able to produce an old diff from the two pieces' do expected = (<<-EOD.encode('UTF-16LE').chomp) 1,2c1,2 @@ -45,7 +49,7 @@ EOD expect(hunk.diff(:old).to_s == expected).to eql true end - it 'should be able to produce a reverse ed diff from the two peices' do + it 'should be able to produce a reverse ed diff from the two pieces' do expected = (<<-EOD.encode('UTF-16LE').chomp) c1,2 |