diff options
author | Austin Ziegler <austin@zieglers.ca> | 2020-06-23 22:15:28 -0400 |
---|---|---|
committer | Austin Ziegler <austin@zieglers.ca> | 2020-06-23 22:15:28 -0400 |
commit | 9aabe2f63fcb1d15c80e26e00ddea12189dc9547 (patch) | |
tree | be5f7ba9fe54a3453eb20df62f60b8c4912c4589 /spec | |
parent | cef2f827c7d93cfcddc1ea64dfaab8c7ed784d41 (diff) | |
download | diff-lcs-9aabe2f63fcb1d15c80e26e00ddea12189dc9547.tar.gz |
Change when max_diff_size is applied
- This appears to satisfy the issues found in #60 as well as providing the
additional fixes required to properly test ldiff.
Resolves #60
Diffstat (limited to 'spec')
-rw-r--r-- | spec/fixtures/ldiff/output.diff.chef-u | 8 | ||||
-rw-r--r-- | spec/fixtures/new-chef | 4 | ||||
-rw-r--r-- | spec/fixtures/old-chef | 4 | ||||
-rw-r--r-- | spec/issues_spec.rb | 31 | ||||
-rw-r--r-- | spec/ldiff_spec.rb | 9 |
5 files changed, 54 insertions, 2 deletions
diff --git a/spec/fixtures/ldiff/output.diff.chef-u b/spec/fixtures/ldiff/output.diff.chef-u new file mode 100644 index 0000000..9939ecf --- /dev/null +++ b/spec/fixtures/ldiff/output.diff.chef-u @@ -0,0 +1,8 @@ +--- spec/fixtures/old-chef 2020-06-23 21:57:15.000000000 -0400 ++++ spec/fixtures/new-chef 2020-06-23 21:57:29.000000000 -0400 +@@ -1,5 +1,5 @@ + { + "name": "x", +- "description": "hi" ++ "description": "lo" + } diff --git a/spec/fixtures/new-chef b/spec/fixtures/new-chef new file mode 100644 index 0000000..d7babfe --- /dev/null +++ b/spec/fixtures/new-chef @@ -0,0 +1,4 @@ +{ + "name": "x", + "description": "lo" +}
\ No newline at end of file diff --git a/spec/fixtures/old-chef b/spec/fixtures/old-chef new file mode 100644 index 0000000..5f9e38b --- /dev/null +++ b/spec/fixtures/old-chef @@ -0,0 +1,4 @@ +{ + "name": "x", + "description": "hi" +}
\ No newline at end of file diff --git a/spec/issues_spec.rb b/spec/issues_spec.rb index c4542bb..c9a1e53 100644 --- a/spec/issues_spec.rb +++ b/spec/issues_spec.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'spec_helper' +require 'diff/lcs/hunk' describe 'Diff::LCS Issues' do include Diff::LCS::SpecHelper::Matchers @@ -64,4 +65,34 @@ describe 'Diff::LCS Issues' do }.to raise_error(RSpec::Expectations::ExpectationNotMetError) end end + + describe "issue #60" do + it 'should produce unified output with correct context' do + old_data = <<-DATA_OLD.strip.split("\n").map(&:chomp) +{ + "name": "x", + "description": "hi" +} + DATA_OLD + + new_data = <<-DATA_NEW.strip.split("\n").map(&:chomp) +{ + "name": "x", + "description": "lo" +} + DATA_NEW + + diff = ::Diff::LCS.diff(old_data, new_data) + hunk = ::Diff::LCS::Hunk.new(old_data, new_data, diff.first, 3, 0) + + expect(hunk.diff(:unified)).to eq(<<-EXPECTED.chomp) +@@ -1,5 +1,5 @@ + { + "name": "x", +- "description": "hi" ++ "description": "lo" + } + EXPECTED + end + end end diff --git a/spec/ldiff_spec.rb b/spec/ldiff_spec.rb index bd3c1e9..eee6d86 100644 --- a/spec/ldiff_spec.rb +++ b/spec/ldiff_spec.rb @@ -10,6 +10,11 @@ RSpec.describe 'bin/ldiff' do let(:output_diff_e) { read_fixture('-e') } let(:output_diff_f) { read_fixture('-f') } let(:output_diff_u) { read_fixture('-u') } + let(:output_diff_chef) { read_fixture('-u', base: 'output.diff.chef')} + + specify do + expect(run_ldiff('-u', left: 'old-chef', right: 'new-chef')).to eq(output_diff_chef) + end specify do expect(run_ldiff).to eq(output_diff) @@ -31,8 +36,8 @@ RSpec.describe 'bin/ldiff' do expect(run_ldiff('-u')).to eq(output_diff_u) end - def read_fixture(flag = nil) - clean_data(IO.binread("spec/fixtures/ldiff/output.diff#{flag}"), flag) + def read_fixture(flag = nil, base: 'output.diff') + clean_data(IO.binread("spec/fixtures/ldiff/#{base}#{flag}"), flag) end def clean_data(data, flag) |