diff-lcs 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e25465dc42f53e6fbecbb5f1d5fb9507b4e8687aee1b5bd010b456ca409b559d
4
- data.tar.gz: 0c5618a13890bc917f81b9f52053945f3aa0a8c5e2c1d07bb47559f5dd0b1e62
3
+ metadata.gz: f8c970551b0fef2c712a6dbdc87453ecbd383a6c5b69f0c1e20e7525a9f4d1ef
4
+ data.tar.gz: 6a46ef91155a305417163c3e92503b567e47bf69413e697101b613ed8665c016
5
5
  SHA512:
6
- metadata.gz: '07578eb0c1c939b9f45a0b8dbc53576d13a04f72c4ecccf52d79fe5d984d41c1f8cdf58471de228bc76af6898bc1ed6ebddc58df04068c901653600b6670f003'
7
- data.tar.gz: d4ace7d0c9b03c518a2ce1b7537da8c767f1cfd3f3d025a7bf5206df61b6c44863239a8cbf4601f5464a3a35115a4891bca665b1792f1cb860b2cde3103b43bb
6
+ metadata.gz: 9612854483a3dc37cab0f7ec561d23c4ff2c4d190c4d526c18ae45de8c42a2b48f4809fc7da78de524703a7424b7bfd128bb6705424ffa8c139d7a8a59eea10f
7
+ data.tar.gz: 16586385ffdfd194afd04f1da73ba3b358b7f324f3dfa5c76b8d37e4ffee0eff257ae7c718d85164d02130c9424b04b130521f87dc4d812d9426bbba6806dfd2
data/History.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # History
2
2
 
3
+ ## 1.4.2 / 2020-06-23
4
+
5
+ - Camille Drapier fixed a small issue with RuboCop configuration. [#59][]
6
+ - Applied another fix (and unit test) to fix an issue for the Chef team.
7
+ [#60][], [#61][]
8
+
9
+ ## 1.4.1 / 2020-06-23
10
+
11
+ - Fix an issue where diff sizes could be negative, and they should be. [#57][],
12
+ [#58][]
13
+
3
14
  ## 1.4 / 2020-06-23
4
15
 
5
16
  - Ruby versions lower than 2.4 are soft-deprecated and will not be run as
@@ -245,3 +256,8 @@
245
256
  [#49]: https://github.com/halostatue/diff-lcs/pull/49
246
257
  [#52]: https://github.com/halostatue/diff-lcs/pull/52
247
258
  [#53]: https://github.com/halostatue/diff-lcs/issues/53
259
+ [#57]: https://github.com/halostatue/diff-lcs/issues/57
260
+ [#58]: https://github.com/halostatue/diff-lcs/pull/58
261
+ [#59]: https://github.com/halostatue/diff-lcs/pull/59
262
+ [#60]: https://github.com/halostatue/diff-lcs/issues/60
263
+ [#61]: https://github.com/halostatue/diff-lcs/pull/61
@@ -49,7 +49,7 @@ module Diff; end unless defined? Diff # rubocop:disable Style/Documentation
49
49
  # a x b y c z p d q
50
50
  # a b c a x b y c z
51
51
  module Diff::LCS
52
- VERSION = '1.4.1'
52
+ VERSION = '1.4.2'
53
53
  end
54
54
 
55
55
  require 'diff/lcs/callbacks'
@@ -3,7 +3,7 @@
3
3
  unless 0.respond_to?(:positive?)
4
4
  class Fixnum # rubocop:disable Lint/UnifiedInteger, Style/Documentation
5
5
  def positive?
6
- self > 0 # rubocop:disable Styel/NumericPredicate
6
+ self > 0 # rubocop:disable Style/NumericPredicate
7
7
  end
8
8
  end
9
9
  end
@@ -2,12 +2,12 @@
2
2
 
3
3
  require 'diff/lcs/block'
4
4
 
5
- # A Hunk is a group of Blocks which overlap because of the context
6
- # surrounding each block. (So if we're not using context, every hunk will
7
- # contain one block.) Used in the diff program (bin/diff).
5
+ # A Hunk is a group of Blocks which overlap because of the context surrounding
6
+ # each block. (So if we're not using context, every hunk will contain one
7
+ # block.) Used in the diff program (bin/ldiff).
8
8
  class Diff::LCS::Hunk
9
- # Create a hunk using references to both the old and new data, as well as
10
- # the piece of data.
9
+ # Create a hunk using references to both the old and new data, as well as the
10
+ # piece of data.
11
11
  def initialize(data_old, data_new, piece, flag_context, file_length_difference)
12
12
  # At first, a hunk will have just one Block in it
13
13
  @blocks = [Diff::LCS::Block.new(piece)]
@@ -61,17 +61,20 @@ class Diff::LCS::Hunk
61
61
  return if context.nil? or context.zero?
62
62
 
63
63
  add_start = context > @start_old ? @start_old : context
64
+
64
65
  @start_old -= add_start
65
66
  @start_new -= add_start
66
67
 
68
+ old_size = @data_old.size
69
+
67
70
  add_end =
68
- if (@end_old + context) > @data_old.size
69
- @data_old.size - @end_old
71
+ if (@end_old + context) > old_size
72
+ old_size - @end_old
70
73
  else
71
74
  context
72
75
  end
73
76
 
74
- add_end = @max_diff_size if add_end > @max_diff_size
77
+ add_end = @max_diff_size if add_end >= old_size
75
78
 
76
79
  @end_old += add_end
77
80
  @end_new += add_end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'spec_helper'
4
+ require 'diff/lcs/hunk'
4
5
 
5
6
  describe 'Diff::LCS Issues' do
6
7
  include Diff::LCS::SpecHelper::Matchers
@@ -64,4 +65,34 @@ describe 'Diff::LCS Issues' do
64
65
  }.to raise_error(RSpec::Expectations::ExpectationNotMetError)
65
66
  end
66
67
  end
68
+
69
+ describe "issue #60" do
70
+ it 'should produce unified output with correct context' do
71
+ old_data = <<-DATA_OLD.strip.split("\n").map(&:chomp)
72
+ {
73
+ "name": "x",
74
+ "description": "hi"
75
+ }
76
+ DATA_OLD
77
+
78
+ new_data = <<-DATA_NEW.strip.split("\n").map(&:chomp)
79
+ {
80
+ "name": "x",
81
+ "description": "lo"
82
+ }
83
+ DATA_NEW
84
+
85
+ diff = ::Diff::LCS.diff(old_data, new_data)
86
+ hunk = ::Diff::LCS::Hunk.new(old_data, new_data, diff.first, 3, 0)
87
+
88
+ expect(hunk.diff(:unified)).to eq(<<-EXPECTED.chomp)
89
+ @@ -1,5 +1,5 @@
90
+ {
91
+ "name": "x",
92
+ - "description": "hi"
93
+ + "description": "lo"
94
+ }
95
+ EXPECTED
96
+ end
97
+ end
67
98
  end
@@ -10,6 +10,11 @@ RSpec.describe 'bin/ldiff' do
10
10
  let(:output_diff_e) { read_fixture('-e') }
11
11
  let(:output_diff_f) { read_fixture('-f') }
12
12
  let(:output_diff_u) { read_fixture('-u') }
13
+ let(:output_diff_chef) { read_fixture('-u', base: 'output.diff.chef') }
14
+
15
+ specify do
16
+ expect(run_ldiff('-u', left: 'old-chef', right: 'new-chef')).to eq(output_diff_chef)
17
+ end
13
18
 
14
19
  specify do
15
20
  expect(run_ldiff).to eq(output_diff)
@@ -31,8 +36,8 @@ RSpec.describe 'bin/ldiff' do
31
36
  expect(run_ldiff('-u')).to eq(output_diff_u)
32
37
  end
33
38
 
34
- def read_fixture(flag = nil)
35
- clean_data(IO.binread("spec/fixtures/ldiff/output.diff#{flag}"), flag)
39
+ def read_fixture(flag = nil, base: 'output.diff')
40
+ clean_data(IO.binread("spec/fixtures/ldiff/#{base}#{flag}"), flag)
36
41
  end
37
42
 
38
43
  def clean_data(data, flag)
@@ -49,14 +54,15 @@ RSpec.describe 'bin/ldiff' do
49
54
  def clean_output_timestamp(data)
50
55
  data.gsub(
51
56
  %r{
52
- [-*+]{3}
53
- \s
54
- spec/fixtures/(\w+)
55
- \s
57
+ ^
58
+ [-+*]{3}
59
+ \s*
60
+ spec/fixtures/(\S+)
61
+ \s*
56
62
  \d{4}-\d\d-\d\d
57
- \s
63
+ \s*
58
64
  \d\d:\d\d:\d\d(?:\.\d+)
59
- \s
65
+ \s*
60
66
  (?:[-+]\d{4}|Z)
61
67
  }x,
62
68
  '*** spec/fixtures/\1 0000-00-00 00:00:00.000000000 -0000'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diff-lcs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Austin Ziegler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-23 00:00:00.000000000 Z
11
+ date: 2020-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hoe-doofus