diff-lcs 1.4 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d49f14f7f3242c9aa114b5352864185acb447e05775f21292907f30944a4e57
4
- data.tar.gz: f72bf7376cb029d39e9fea818361afa99dea8c27440d483a2de04ee3b8864c6b
3
+ metadata.gz: f8c970551b0fef2c712a6dbdc87453ecbd383a6c5b69f0c1e20e7525a9f4d1ef
4
+ data.tar.gz: 6a46ef91155a305417163c3e92503b567e47bf69413e697101b613ed8665c016
5
5
  SHA512:
6
- metadata.gz: 9a217015cd26e5ca24d9398f9497c119bfd7251290f20f30e8a30ba880ed1f12fdf669fe8d0a019273fbe7e8e6362de67351f799a1d3ac3c0e9ef91c078609a6
7
- data.tar.gz: ebc14cb8fb1e0c949fcfce752da8c30c6005dbc62c62b371e6a520b7a485d16e7b36d2aa44dc7e395abca16fd3498c4aab154e2d880392d655abb613d5951185
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
data/Rakefile CHANGED
@@ -24,22 +24,11 @@ _spec = Hoe.spec 'diff-lcs' do
24
24
  extra_dev_deps << ['hoe-gemspec2', '~> 1.1']
25
25
  extra_dev_deps << ['hoe-git', '~> 1.6']
26
26
  extra_dev_deps << ['hoe-rubygems', '~> 1.0']
27
- extra_dev_deps << ['hoe-travis', '~> 1.2']
28
27
  extra_dev_deps << ['rspec', '>= 2.0', '< 4']
29
28
  extra_dev_deps << ['rake', '>= 10.0', '< 14']
30
29
  extra_dev_deps << ['rdoc', '>= 0']
31
30
  end
32
31
 
33
- require "rspec/core/rake_task"
34
-
35
- desc "Run all specifications"
36
- RSpec::Core::RakeTask.new(:spec) do |t|
37
- rspec_dirs = %w(spec lib)
38
- t.rspec_opts = []
39
- t.rspec_opts << "-I#{rspec_dirs.join(":")}" unless rspec_dirs.empty?
40
- end
41
- task :default => :spec
42
-
43
32
  if RUBY_VERSION >= '2.0' && RUBY_ENGINE == 'ruby'
44
33
  namespace :spec do
45
34
  desc "Runs test coverage. Only works Ruby 2.0+ and assumes 'simplecov' is installed."
@@ -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'
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
@@ -19,7 +19,7 @@ class Diff::LCS::Block
19
19
  end
20
20
 
21
21
  def diff_size
22
- @insert.size - @remove.size
22
+ (@insert.size - @remove.size).abs
23
23
  end
24
24
 
25
25
  def op
@@ -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
@@ -54,4 +55,44 @@ describe 'Diff::LCS Issues' do
54
55
  ]
55
56
  end
56
57
  end
58
+
59
+ describe "issue #57" do
60
+ it 'should fail with a correct error' do
61
+ expect {
62
+ actual = {:category=>"app.rack.request"}
63
+ expected = {:category=>"rack.middleware", :title=>"Anonymous Middleware"}
64
+ expect(actual).to eq(expected)
65
+ }.to raise_error(RSpec::Expectations::ExpectationNotMetError)
66
+ end
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
57
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,30 +36,33 @@ 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)
39
- case flag
40
- when '-c', '-u'
41
- clean_output_timestamp(data)
42
- else
43
- data
44
- end
44
+ data =
45
+ case flag
46
+ when '-c', '-u'
47
+ clean_output_timestamp(data)
48
+ else
49
+ data
50
+ end
51
+ data.gsub(/\r\n?/, "\n")
45
52
  end
46
53
 
47
54
  def clean_output_timestamp(data)
48
55
  data.gsub(
49
56
  %r{
50
- [-*+]{3}
51
- \s
52
- spec/fixtures/(\w+)
53
- \s
57
+ ^
58
+ [-+*]{3}
59
+ \s*
60
+ spec/fixtures/(\S+)
61
+ \s*
54
62
  \d{4}-\d\d-\d\d
55
- \s
63
+ \s*
56
64
  \d\d:\d\d:\d\d(?:\.\d+)
57
- \s
65
+ \s*
58
66
  (?:[-+]\d{4}|Z)
59
67
  }x,
60
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'
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
@@ -66,20 +66,6 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.0'
69
- - !ruby/object:Gem::Dependency
70
- name: hoe-travis
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '1.2'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '1.2'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: rspec
85
71
  requirement: !ruby/object:Gem::Requirement