diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/hunk_spec.rb | 65 |
1 files changed, 37 insertions, 28 deletions
diff --git a/spec/hunk_spec.rb b/spec/hunk_spec.rb index 0741b87..dc6f532 100644 --- a/spec/hunk_spec.rb +++ b/spec/hunk_spec.rb @@ -15,49 +15,58 @@ describe "Diff::LCS::Hunk" do 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 pieces' do - expected = -(<<-EOD.encode('UTF-16LE').chomp) -@@ -1,2 +1,2 @@ --Tu avec carté {count} itém has -+Tu avec carte {count} item has -EOD + expected = (<<-EOD.gsub(/^\s+/,'').encode('UTF-16LE').chomp) + @@ -1,2 +1,2 @@ + -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 pieces' do - expected = -(<<-EOD.encode('UTF-16LE').chomp) -*************** -*** 1,2 **** -!Tu avec carté {count} itém has ---- 1,2 ---- -!Tu avec carte {count} item has -EOD + expected = (<<-EOD.gsub(/^\s+/,'').encode('UTF-16LE').chomp) + *************** + *** 1,2 **** + !Tu avec carté {count} itém has + --- 1,2 ---- + !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 pieces' do - expected = -(<<-EOD.encode('UTF-16LE').chomp) -1,2c1,2 -< Tu avec carté {count} itém has ---- -> Tu avec carte {count} item has - -EOD + expected = (<<-EOD.gsub(/^ +/,'').encode('UTF-16LE').chomp) + 1,2c1,2 + < Tu avec carté {count} itém has + --- + > Tu avec carte {count} item has + + 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 pieces' do - expected = -(<<-EOD.encode('UTF-16LE').chomp) -c1,2 -Tu avec carte {count} item has -. + expected = (<<-EOD.gsub(/^ +/,'').encode('UTF-16LE').chomp) + c1,2 + Tu avec carte {count} item has + . -EOD + EOD expect(hunk.diff(:reverse_ed).to_s == expected).to eql true end + + context 'with empty first data set' do + let(:old_data) { [] } + + it 'should be able to produce a unified diff' do + expected = (<<-EOD.gsub(/^\s+/,'').encode('UTF-16LE').chomp) + @@ -1 +1,2 @@ + +Tu avec carte {count} item has + EOD + expect(hunk.diff(:unified).to_s == expected).to eql true + end + end + end end |