summaryrefslogtreecommitdiff
path: root/spec/issues_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/issues_spec.rb')
-rw-r--r--spec/issues_spec.rb31
1 files changed, 31 insertions, 0 deletions
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