diff-lcs 1.6.2 → 2.0.0.beta.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.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +65 -4
  3. data/CONTRIBUTING.md +91 -35
  4. data/CONTRIBUTORS.md +19 -9
  5. data/LICENCE.md +39 -11
  6. data/Manifest.txt +91 -83
  7. data/README.md +13 -9
  8. data/Rakefile +99 -73
  9. data/SECURITY.md +22 -27
  10. data/integration/compare/array_diff_spec.rb +10 -0
  11. data/integration/compare/hash_diff_spec.rb +25 -0
  12. data/integration/compare/string_diff_spec.rb +10 -0
  13. data/integration/rspec_differ_spec.rb +26 -0
  14. data/integration/rspec_expectations_spec.rb +32 -0
  15. data/integration/runner +20 -0
  16. data/lib/diff/lcs/block.rb +29 -24
  17. data/lib/diff/lcs/callbacks.rb +240 -242
  18. data/lib/diff/lcs/change.rb +102 -104
  19. data/lib/diff/lcs/hunk.rb +92 -155
  20. data/lib/diff/lcs/internals.rb +92 -96
  21. data/lib/diff/lcs/ldiff.rb +30 -38
  22. data/lib/diff/lcs/version.rb +1 -1
  23. data/lib/diff/lcs.rb +439 -466
  24. data/licenses/dco.txt +34 -0
  25. data/spec/hunk_spec.rb +32 -45
  26. data/spec/lcs_spec.rb +6 -6
  27. data/spec/ldiff_spec.rb +8 -8
  28. data/spec/spec_helper.rb +17 -27
  29. data/test/fixtures/ldiff/output.diff-c +7 -0
  30. data/test/fixtures/ldiff/output.diff-u +5 -0
  31. data/test/fixtures/ldiff/output.diff.bin2 +1 -0
  32. data/test/fixtures/ldiff/output.diff.bin2-c +1 -0
  33. data/test/fixtures/ldiff/output.diff.bin2-e +1 -0
  34. data/test/fixtures/ldiff/output.diff.bin2-f +1 -0
  35. data/test/fixtures/ldiff/output.diff.bin2-u +1 -0
  36. data/{spec → test}/fixtures/ldiff/output.diff.chef-c +2 -2
  37. data/test/fixtures/ldiff/output.diff.chef-u +9 -0
  38. data/{spec → test}/fixtures/ldiff/output.diff.chef2-c +2 -2
  39. data/{spec → test}/fixtures/ldiff/output.diff.chef2-u +2 -2
  40. data/test/fixtures/ldiff/output.diff.empty.vs.four_lines-c +9 -0
  41. data/test/fixtures/ldiff/output.diff.empty.vs.four_lines-u +7 -0
  42. data/test/fixtures/ldiff/output.diff.four_lines.vs.empty-c +9 -0
  43. data/test/fixtures/ldiff/output.diff.four_lines.vs.empty-u +7 -0
  44. data/test/fixtures/ldiff/output.diff.issue95_trailing_context-c +9 -0
  45. data/test/fixtures/ldiff/output.diff.issue95_trailing_context-u +6 -0
  46. data/{spec → test}/fixtures/ldiff/output.diff.missing_new_line1-c +2 -2
  47. data/test/fixtures/ldiff/output.diff.missing_new_line1-u +9 -0
  48. data/{spec → test}/fixtures/ldiff/output.diff.missing_new_line2-c +2 -2
  49. data/test/fixtures/ldiff/output.diff.missing_new_line2-u +9 -0
  50. data/test/test_block.rb +34 -0
  51. data/test/test_change.rb +234 -0
  52. data/test/test_diff.rb +53 -0
  53. data/test/test_helper.rb +225 -0
  54. data/test/test_hunk.rb +72 -0
  55. data/test/test_issues.rb +168 -0
  56. data/test/test_lcs.rb +47 -0
  57. data/test/test_ldiff.rb +89 -0
  58. data/test/test_patch.rb +362 -0
  59. data/test/test_sdiff.rb +167 -0
  60. data/test/test_traverse_balanced.rb +322 -0
  61. data/test/test_traverse_sequences.rb +187 -0
  62. metadata +199 -110
  63. data/.rspec +0 -1
  64. data/bin/htmldiff +0 -35
  65. data/lib/diff/lcs/backports.rb +0 -13
  66. data/lib/diff/lcs/htmldiff.rb +0 -160
  67. data/mise.toml +0 -5
  68. data/spec/fixtures/ldiff/output.diff-c +0 -7
  69. data/spec/fixtures/ldiff/output.diff-e +0 -3
  70. data/spec/fixtures/ldiff/output.diff-f +0 -3
  71. data/spec/fixtures/ldiff/output.diff-u +0 -5
  72. data/spec/fixtures/ldiff/output.diff.bin2 +0 -1
  73. data/spec/fixtures/ldiff/output.diff.bin2-c +0 -1
  74. data/spec/fixtures/ldiff/output.diff.bin2-e +0 -1
  75. data/spec/fixtures/ldiff/output.diff.bin2-f +0 -1
  76. data/spec/fixtures/ldiff/output.diff.bin2-u +0 -1
  77. data/spec/fixtures/ldiff/output.diff.chef-e +0 -3
  78. data/spec/fixtures/ldiff/output.diff.chef-f +0 -3
  79. data/spec/fixtures/ldiff/output.diff.chef-u +0 -9
  80. data/spec/fixtures/ldiff/output.diff.chef2-e +0 -7
  81. data/spec/fixtures/ldiff/output.diff.chef2-f +0 -7
  82. data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-c +0 -9
  83. data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-u +0 -7
  84. data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-c +0 -9
  85. data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-u +0 -7
  86. data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-c +0 -9
  87. data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-u +0 -6
  88. data/spec/fixtures/ldiff/output.diff.missing_new_line1-u +0 -9
  89. data/spec/fixtures/ldiff/output.diff.missing_new_line2-u +0 -9
  90. /data/{docs → licenses}/COPYING.txt +0 -0
  91. /data/{docs → licenses}/artistic.txt +0 -0
  92. /data/{spec → test}/fixtures/123_x +0 -0
  93. /data/{spec → test}/fixtures/456_x +0 -0
  94. /data/{spec → test}/fixtures/aX +0 -0
  95. /data/{spec → test}/fixtures/bXaX +0 -0
  96. /data/{spec → test}/fixtures/ds1.csv +0 -0
  97. /data/{spec → test}/fixtures/ds2.csv +0 -0
  98. /data/{spec → test}/fixtures/empty +0 -0
  99. /data/{spec → test}/fixtures/file1.bin +0 -0
  100. /data/{spec → test}/fixtures/file2.bin +0 -0
  101. /data/{spec → test}/fixtures/four_lines +0 -0
  102. /data/{spec → test}/fixtures/four_lines_with_missing_new_line +0 -0
  103. /data/{spec → test}/fixtures/ldiff/diff.missing_new_line1-e +0 -0
  104. /data/{spec → test}/fixtures/ldiff/diff.missing_new_line1-f +0 -0
  105. /data/{spec → test}/fixtures/ldiff/diff.missing_new_line2-e +0 -0
  106. /data/{spec → test}/fixtures/ldiff/diff.missing_new_line2-f +0 -0
  107. /data/{spec → test}/fixtures/ldiff/error.diff.chef-e +0 -0
  108. /data/{spec → test}/fixtures/ldiff/error.diff.chef-f +0 -0
  109. /data/{spec → test}/fixtures/ldiff/error.diff.missing_new_line1-e +0 -0
  110. /data/{spec → test}/fixtures/ldiff/error.diff.missing_new_line1-f +0 -0
  111. /data/{spec → test}/fixtures/ldiff/error.diff.missing_new_line2-e +0 -0
  112. /data/{spec → test}/fixtures/ldiff/error.diff.missing_new_line2-f +0 -0
  113. /data/{spec → test}/fixtures/ldiff/output.diff +0 -0
  114. /data/{spec → test}/fixtures/ldiff/output.diff.bin1 +0 -0
  115. /data/{spec → test}/fixtures/ldiff/output.diff.bin1-c +0 -0
  116. /data/{spec → test}/fixtures/ldiff/output.diff.bin1-e +0 -0
  117. /data/{spec → test}/fixtures/ldiff/output.diff.bin1-f +0 -0
  118. /data/{spec → test}/fixtures/ldiff/output.diff.bin1-u +0 -0
  119. /data/{spec → test}/fixtures/ldiff/output.diff.chef +0 -0
  120. /data/{spec → test}/fixtures/ldiff/output.diff.chef2 +0 -0
  121. /data/{spec → test}/fixtures/ldiff/output.diff.chef2-d +0 -0
  122. /data/{spec → test}/fixtures/ldiff/output.diff.empty.vs.four_lines +0 -0
  123. /data/{spec → test}/fixtures/ldiff/output.diff.empty.vs.four_lines-e +0 -0
  124. /data/{spec → test}/fixtures/ldiff/output.diff.empty.vs.four_lines-f +0 -0
  125. /data/{spec → test}/fixtures/ldiff/output.diff.four_lines.vs.empty +0 -0
  126. /data/{spec → test}/fixtures/ldiff/output.diff.four_lines.vs.empty-e +0 -0
  127. /data/{spec → test}/fixtures/ldiff/output.diff.four_lines.vs.empty-f +0 -0
  128. /data/{spec → test}/fixtures/ldiff/output.diff.issue95_trailing_context +0 -0
  129. /data/{spec → test}/fixtures/ldiff/output.diff.issue95_trailing_context-e +0 -0
  130. /data/{spec → test}/fixtures/ldiff/output.diff.issue95_trailing_context-f +0 -0
  131. /data/{spec → test}/fixtures/ldiff/output.diff.missing_new_line1 +0 -0
  132. /data/{spec → test}/fixtures/ldiff/output.diff.missing_new_line1-e +0 -0
  133. /data/{spec → test}/fixtures/ldiff/output.diff.missing_new_line1-f +0 -0
  134. /data/{spec → test}/fixtures/ldiff/output.diff.missing_new_line2 +0 -0
  135. /data/{spec → test}/fixtures/ldiff/output.diff.missing_new_line2-e +0 -0
  136. /data/{spec → test}/fixtures/ldiff/output.diff.missing_new_line2-f +0 -0
  137. /data/{spec → test}/fixtures/new-chef +0 -0
  138. /data/{spec → test}/fixtures/new-chef2 +0 -0
  139. /data/{spec → test}/fixtures/old-chef +0 -0
  140. /data/{spec → test}/fixtures/old-chef2 +0 -0
data/licenses/dco.txt ADDED
@@ -0,0 +1,34 @@
1
+ Developer Certificate of Origin
2
+ Version 1.1
3
+
4
+ Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
5
+
6
+ Everyone is permitted to copy and distribute verbatim copies of this
7
+ license document, but changing it is not allowed.
8
+
9
+
10
+ Developer's Certificate of Origin 1.1
11
+
12
+ By making a contribution to this project, I certify that:
13
+
14
+ (a) The contribution was created in whole or in part by me and I
15
+ have the right to submit it under the open source license
16
+ indicated in the file; or
17
+
18
+ (b) The contribution is based upon previous work that, to the best
19
+ of my knowledge, is covered under an appropriate open source
20
+ license and I have the right under that license to submit that
21
+ work with modifications, whether created in whole or in part
22
+ by me, under the same open source license (unless I am
23
+ permitted to submit under a different license), as indicated
24
+ in the file; or
25
+
26
+ (c) The contribution was provided directly to me by some other
27
+ person who certified (a), (b) or (c) and I have not modified
28
+ it.
29
+
30
+ (d) I understand and agree that this project and the contribution
31
+ are public and that a record of the contribution (including all
32
+ personal information I submit with it, including my sign-off) is
33
+ maintained indefinitely and may be redistributed consistent with
34
+ this project or the open source license(s) involved.
data/spec/hunk_spec.rb CHANGED
@@ -2,82 +2,69 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- if String.method_defined?(:encoding)
6
- require "diff/lcs/hunk"
5
+ require "diff/lcs/hunk"
7
6
 
8
- describe Diff::LCS::Hunk do
9
- let(:old_data) { ["Tu a un carté avec {count} itéms".encode("UTF-16LE")] }
10
- let(:new_data) { ["Tu a un carte avec {count} items".encode("UTF-16LE")] }
11
- let(:pieces) { Diff::LCS.diff old_data, new_data }
12
- let(:hunk) { Diff::LCS::Hunk.new(old_data, new_data, pieces[0], 3, 0) }
7
+ describe Diff::LCS::Hunk do
8
+ let(:old_data) { ["Tu a un carté avec {count} itéms".encode("UTF-16LE")] }
9
+ let(:new_data) { ["Tu a un carte avec {count} items".encode("UTF-16LE")] }
10
+ let(:pieces) { Diff::LCS.diff old_data, new_data }
11
+ let(:hunk) { Diff::LCS::Hunk.new(old_data, new_data, pieces[0], 3, 0) }
13
12
 
14
- it "produces a unified diff from the two pieces" do
15
- expected = <<-EXPECTED.gsub(/^\s+/, "").encode("UTF-16LE").chomp
13
+ it "produces a unified diff from the two pieces" do
14
+ expected = <<-EXPECTED.gsub(/^\s+/, "").encode("UTF-16LE").chomp
16
15
  @@ -1 +1 @@
17
16
  -Tu a un carté avec {count} itéms
18
17
  +Tu a un carte avec {count} items
19
- EXPECTED
18
+ EXPECTED
20
19
 
21
- expect(hunk.diff(:unified)).to eq(expected)
22
- end
20
+ expect(hunk.diff(:unified)).to eq(expected)
21
+ end
23
22
 
24
- it "produces a unified diff from the two pieces (last entry)" do
25
- expected = <<-EXPECTED.gsub(/^\s+/, "").encode("UTF-16LE").chomp
23
+ it "produces a unified diff from the two pieces (last entry)" do
24
+ expected = <<-EXPECTED.gsub(/^\s+/, "").encode("UTF-16LE").chomp
26
25
  @@ -1 +1 @@
27
26
  -Tu a un carté avec {count} itéms
28
27
  +Tu a un carte avec {count} items
29
28
  \
30
- EXPECTED
29
+ EXPECTED
31
30
 
32
- expect(hunk.diff(:unified, true)).to eq(expected)
33
- end
31
+ expect(hunk.diff(:unified, true)).to eq(expected)
32
+ end
34
33
 
35
- it "produces a context diff from the two pieces" do
36
- expected = <<-EXPECTED.gsub(/^\s+/, "").encode("UTF-16LE").chomp
34
+ it "produces a context diff from the two pieces" do
35
+ expected = <<-EXPECTED.gsub(/^\s+/, "").encode("UTF-16LE").chomp
37
36
  ***************
38
37
  *** 1 ****
39
38
  ! Tu a un carté avec {count} itéms
40
39
  --- 1 ----
41
40
  ! Tu a un carte avec {count} items
42
- EXPECTED
41
+ EXPECTED
43
42
 
44
- expect(hunk.diff(:context)).to eq(expected)
45
- end
43
+ expect(hunk.diff(:context)).to eq(expected)
44
+ end
46
45
 
47
- it "produces an old diff from the two pieces" do
48
- expected = <<-EXPECTED.gsub(/^ +/, "").encode("UTF-16LE").chomp
46
+ it "produces an old diff from the two pieces" do
47
+ expected = <<-EXPECTED.gsub(/^ +/, "").encode("UTF-16LE").chomp
49
48
  1c1
50
49
  < Tu a un carté avec {count} itéms
51
50
  ---
52
51
  > Tu a un carte avec {count} items
53
52
 
54
- EXPECTED
55
-
56
- expect(hunk.diff(:old)).to eq(expected)
57
- end
58
-
59
- it "produces a reverse ed diff from the two pieces" do
60
- expected = <<-EXPECTED.gsub(/^ +/, "").encode("UTF-16LE").chomp
61
- c1
62
- Tu a un carte avec {count} items
63
- .
64
-
65
- EXPECTED
53
+ EXPECTED
66
54
 
67
- expect(hunk.diff(:reverse_ed)).to eq(expected)
68
- end
55
+ expect(hunk.diff(:old)).to eq(expected)
56
+ end
69
57
 
70
- context "with empty first data set" do
71
- let(:old_data) { [] }
58
+ context "with empty first data set" do
59
+ let(:old_data) { [] }
72
60
 
73
- it "produces a unified diff" do
74
- expected = <<-EXPECTED.gsub(/^\s+/, "").encode("UTF-16LE").chomp
61
+ it "produces a unified diff" do
62
+ expected = <<-EXPECTED.gsub(/^\s+/, "").encode("UTF-16LE").chomp
75
63
  @@ -0,0 +1 @@
76
64
  +Tu a un carte avec {count} items
77
- EXPECTED
65
+ EXPECTED
78
66
 
79
- expect(hunk.diff(:unified)).to eq(expected)
80
- end
67
+ expect(hunk.diff(:unified)).to eq(expected)
81
68
  end
82
69
  end
83
70
  end
data/spec/lcs_spec.rb CHANGED
@@ -31,26 +31,26 @@ describe Diff::LCS::Internals, ".lcs" do
31
31
  end
32
32
  end
33
33
 
34
- describe Diff::LCS, ".LCS" do
34
+ describe Diff::LCS, ".lcs" do
35
35
  include Diff::LCS::SpecHelper::Matchers
36
36
 
37
- it "returns the correct compacted values from Diff::LCS.LCS" do
38
- res = Diff::LCS.LCS(seq1, seq2)
37
+ it "returns the correct compacted values from Diff::LCS.lcs" do
38
+ res = Diff::LCS.lcs(seq1, seq2)
39
39
  expect(res).to eq(correct_lcs)
40
40
  expect(res.compact).to eq(res)
41
41
  end
42
42
 
43
43
  it "is transitive" do
44
- res = Diff::LCS.LCS(seq2, seq1)
44
+ res = Diff::LCS.lcs(seq2, seq1)
45
45
  expect(res).to eq(correct_lcs)
46
46
  expect(res.compact).to eq(res)
47
47
  end
48
48
 
49
49
  it "returns %W(h e l l o) with (hello, hello)" do
50
- expect(Diff::LCS.LCS(hello, hello)).to eq(hello.chars)
50
+ expect(Diff::LCS.lcs(hello, hello)).to eq(hello.chars)
51
51
  end
52
52
 
53
53
  it "returns hello_ary with (hello_ary, hello_ary)" do
54
- expect(Diff::LCS.LCS(hello_ary, hello_ary)).to eq(hello_ary)
54
+ expect(Diff::LCS.lcs(hello_ary, hello_ary)).to eq(hello_ary)
55
55
  end
56
56
  end
data/spec/ldiff_spec.rb CHANGED
@@ -17,7 +17,7 @@ RSpec.describe "bin/ldiff" do
17
17
  {:name => "diff.bin2", :left => "file1.bin", :right => "file2.bin", :diff => 1},
18
18
  {:name => "diff.chef", :left => "old-chef", :right => "new-chef", :diff => 1},
19
19
  {:name => "diff.chef2", :left => "old-chef2", :right => "new-chef2", :diff => 1}
20
- ].product([nil, "-e", "-f", "-c", "-u"]).map { |(fixture, flag)|
20
+ ].product([nil, "-c", "-u"]).map { |(fixture, flag)|
21
21
  fixture = fixture.dup
22
22
  fixture[:flag] = flag
23
23
  fixture
@@ -27,11 +27,11 @@ RSpec.describe "bin/ldiff" do
27
27
  def self.test_ldiff(fixture)
28
28
  desc = [
29
29
  fixture[:flag],
30
- "spec/fixtures/#{fixture[:left]}",
31
- "spec/fixtures/#{fixture[:right]}",
30
+ "test/fixtures/#{fixture[:left]}",
31
+ "test/fixtures/#{fixture[:right]}",
32
32
  "#",
33
33
  "=>",
34
- "spec/fixtures/ldiff/output.#{fixture[:name]}#{fixture[:flag]}"
34
+ "test/fixtures/ldiff/output.#{fixture[:name]}#{fixture[:flag]}"
35
35
  ].join(" ")
36
36
 
37
37
  it desc do
@@ -49,7 +49,7 @@ RSpec.describe "bin/ldiff" do
49
49
  def read_fixture(options, mode: "output", allow_missing: false)
50
50
  fixture = options.fetch(:name)
51
51
  flag = options.fetch(:flag)
52
- name = "spec/fixtures/ldiff/#{mode}.#{fixture}#{flag}"
52
+ name = "test/fixtures/ldiff/#{mode}.#{fixture}#{flag}"
53
53
 
54
54
  return "" if !::File.exist?(name) && allow_missing
55
55
 
@@ -74,7 +74,7 @@ RSpec.describe "bin/ldiff" do
74
74
  ^
75
75
  [-+*]{3}
76
76
  \s*
77
- spec/fixtures/(\S+)
77
+ test/fixtures/(\S+)
78
78
  \s*
79
79
  \d{4}-\d\d-\d\d
80
80
  \s*
@@ -82,7 +82,7 @@ RSpec.describe "bin/ldiff" do
82
82
  \s*
83
83
  (?:[-+]\d{4}|Z)
84
84
  }x,
85
- '*** spec/fixtures/\1 0000-00-00 :00 =>:00 =>00.000000000 -0000'
85
+ '*** test/fixtures/\1 0000-00-00 :00 =>:00 =>00.000000000 -0000'
86
86
  )
87
87
  end
88
88
 
@@ -92,7 +92,7 @@ RSpec.describe "bin/ldiff" do
92
92
  right = options.fetch(:right)
93
93
 
94
94
  stdout, stderr = capture_subprocess_io do
95
- system("ruby -Ilib bin/ldiff #{flag} spec/fixtures/#{left} spec/fixtures/#{right}")
95
+ system("ruby -Ilib bin/ldiff #{flag} test/fixtures/#{left} test/fixtures/#{right}")
96
96
  end
97
97
 
98
98
  [clean_data(stdout, flag), stderr, $?.exitstatus]
data/spec/spec_helper.rb CHANGED
@@ -1,35 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "rubygems"
4
- require "pathname"
5
-
6
- require "psych" if RUBY_VERSION >= "1.9"
3
+ $LOAD_PATH.unshift File.expand_path(__dir__, "../lib")
7
4
 
8
- if ENV["COVERAGE"]
9
- require "simplecov"
10
- require "simplecov-lcov"
5
+ require "rubygems"
6
+ require "simplecov"
7
+ require "simplecov-lcov"
11
8
 
12
- SimpleCov::Formatter::LcovFormatter.config do |config|
13
- config.report_with_single_file = true
14
- config.lcov_file_name = "lcov.info"
15
- end
9
+ require "diff/lcs"
16
10
 
17
- SimpleCov.start "test_frameworks" do
18
- enable_coverage :branch
19
- primary_coverage :branch
20
- formatter SimpleCov::Formatter::MultiFormatter.new([
21
- SimpleCov::Formatter::HTMLFormatter,
22
- SimpleCov::Formatter::LcovFormatter,
23
- SimpleCov::Formatter::SimpleFormatter
24
- ])
25
- end
11
+ SimpleCov::Formatter::LcovFormatter.config do |config|
12
+ config.report_with_single_file = true
13
+ config.lcov_file_name = "lcov.info"
26
14
  end
27
15
 
28
- file = Pathname.new(__FILE__).expand_path
29
- path = file.parent
30
- parent = path.parent
31
-
32
- $:.unshift parent.join("lib")
16
+ SimpleCov.start "test_frameworks" do
17
+ enable_coverage :branch
18
+ primary_coverage :branch
19
+ formatter SimpleCov::Formatter::MultiFormatter.new([
20
+ SimpleCov::Formatter::HTMLFormatter,
21
+ SimpleCov::Formatter::LcovFormatter,
22
+ SimpleCov::Formatter::SimpleFormatter
23
+ ])
24
+ end
33
25
 
34
26
  module CaptureSubprocessIO
35
27
  def _synchronize
@@ -64,8 +56,6 @@ module CaptureSubprocessIO
64
56
  private :_capture_subprocess_io
65
57
  end
66
58
 
67
- require "diff-lcs"
68
-
69
59
  module Diff::LCS::SpecHelper
70
60
  def hello
71
61
  "hello"
@@ -0,0 +1,7 @@
1
+ *** test/fixtures/aX 2020-06-23 11:15:32.000000000 -0400
2
+ --- test/fixtures/bXaX 2020-06-23 11:15:32.000000000 -0400
3
+ ***************
4
+ *** 1 ****
5
+ ! aX
6
+ --- 1 ----
7
+ ! bXaX
@@ -0,0 +1,5 @@
1
+ --- test/fixtures/aX 2020-06-23 11:15:32.000000000 -0400
2
+ +++ test/fixtures/bXaX 2020-06-23 11:15:32.000000000 -0400
3
+ @@ -1 +1 @@
4
+ -aX
5
+ +bXaX
@@ -0,0 +1 @@
1
+ Binary files test/fixtures/file1.bin and test/fixtures/file2.bin differ
@@ -0,0 +1 @@
1
+ Binary files test/fixtures/file1.bin and test/fixtures/file2.bin differ
@@ -0,0 +1 @@
1
+ Binary files test/fixtures/file1.bin and test/fixtures/file2.bin differ
@@ -0,0 +1 @@
1
+ Binary files test/fixtures/file1.bin and test/fixtures/file2.bin differ
@@ -0,0 +1 @@
1
+ Binary files test/fixtures/file1.bin and test/fixtures/file2.bin differ
@@ -1,5 +1,5 @@
1
- *** spec/fixtures/old-chef 2020-06-23 23:18:20.000000000 -0400
2
- --- spec/fixtures/new-chef 2020-06-23 23:18:20.000000000 -0400
1
+ *** test/fixtures/old-chef 2020-06-23 23:18:20.000000000 -0400
2
+ --- test/fixtures/new-chef 2020-06-23 23:18:20.000000000 -0400
3
3
  ***************
4
4
  *** 1,4 ****
5
5
  {
@@ -0,0 +1,9 @@
1
+ --- test/fixtures/old-chef 2020-06-23 23:18:20.000000000 -0400
2
+ +++ test/fixtures/new-chef 2020-06-23 23:18:20.000000000 -0400
3
+ @@ -1,4 +1,4 @@
4
+ {
5
+ "name": "x",
6
+ - "description": "hi"
7
+ + "description": "lo"
8
+ }
9
+
@@ -1,5 +1,5 @@
1
- *** spec/fixtures/old-chef2 2020-06-30 09:43:35.000000000 -0400
2
- --- spec/fixtures/new-chef2 2020-06-30 09:44:32.000000000 -0400
1
+ *** test/fixtures/old-chef2 2020-06-30 09:43:35.000000000 -0400
2
+ --- test/fixtures/new-chef2 2020-06-30 09:44:32.000000000 -0400
3
3
  ***************
4
4
  *** 1,5 ****
5
5
  recipe[a::default]
@@ -1,5 +1,5 @@
1
- --- spec/fixtures/old-chef2 2020-06-30 09:43:35.000000000 -0400
2
- +++ spec/fixtures/new-chef2 2020-06-30 09:44:32.000000000 -0400
1
+ --- test/fixtures/old-chef2 2020-06-30 09:43:35.000000000 -0400
2
+ +++ test/fixtures/new-chef2 2020-06-30 09:44:32.000000000 -0400
3
3
  @@ -1,5 +1,4 @@
4
4
  recipe[a::default]
5
5
  -recipe[b::default]
@@ -0,0 +1,9 @@
1
+ *** test/fixtures/empty 2025-01-31 12:14:52.856031635 +0100
2
+ --- test/fixtures/four_lines 2025-01-31 12:13:45.476036544 +0100
3
+ ***************
4
+ *** 0 ****
5
+ --- 1,4 ----
6
+ + one
7
+ + two
8
+ + three
9
+ + four
@@ -0,0 +1,7 @@
1
+ --- test/fixtures/empty 2025-01-31 12:14:52.856031635 +0100
2
+ +++ test/fixtures/four_lines 2025-01-31 12:13:45.476036544 +0100
3
+ @@ -0,0 +1,4 @@
4
+ +one
5
+ +two
6
+ +three
7
+ +four
@@ -0,0 +1,9 @@
1
+ *** test/fixtures/four_lines 2025-01-31 12:13:45.476036544 +0100
2
+ --- test/fixtures/empty 2025-01-31 12:14:52.856031635 +0100
3
+ ***************
4
+ *** 1,4 ****
5
+ - one
6
+ - two
7
+ - three
8
+ - four
9
+ --- 0 ----
@@ -0,0 +1,7 @@
1
+ --- test/fixtures/four_lines 2025-01-31 12:13:45.476036544 +0100
2
+ +++ test/fixtures/empty 2025-01-31 12:14:52.856031635 +0100
3
+ @@ -1,4 +0,0 @@
4
+ -one
5
+ -two
6
+ -three
7
+ -four
@@ -0,0 +1,9 @@
1
+ *** test/fixtures/123_x 2025-01-31 17:00:17.070615716 +0100
2
+ --- test/fixtures/456_x 2025-01-31 16:58:26.380624827 +0100
3
+ ***************
4
+ *** 1,2 ****
5
+ ! 123
6
+ x
7
+ --- 1,2 ----
8
+ ! 456
9
+ x
@@ -0,0 +1,6 @@
1
+ --- test/fixtures/123_x 2025-01-31 17:00:17.070615716 +0100
2
+ +++ test/fixtures/456_x 2025-01-31 16:58:26.380624827 +0100
3
+ @@ -1,2 +1,2 @@
4
+ -123
5
+ +456
6
+ x
@@ -1,5 +1,5 @@
1
- *** spec/fixtures/four_lines 2025-01-31 12:17:43.926013315 +0100
2
- --- spec/fixtures/four_lines_with_missing_new_line 2025-01-31 12:17:43.926013315 +0100
1
+ *** test/fixtures/four_lines 2025-01-31 12:17:43.926013315 +0100
2
+ --- test/fixtures/four_lines_with_missing_new_line 2025-01-31 12:17:43.926013315 +0100
3
3
  ***************
4
4
  *** 1,4 ****
5
5
  one
@@ -0,0 +1,9 @@
1
+ --- test/fixtures/four_lines 2025-01-31 12:17:43.926013315 +0100
2
+ +++ test/fixtures/four_lines_with_missing_new_line 2025-01-31 12:17:43.926013315 +0100
3
+ @@ -1,4 +1,4 @@
4
+ one
5
+ two
6
+ three
7
+ -four
8
+ +four
9
+
@@ -1,5 +1,5 @@
1
- *** spec/fixtures/four_lines_with_missing_new_line 2025-01-31 12:17:43.926013315 +0100
2
- --- spec/fixtures/four_lines 2025-01-31 12:17:43.926013315 +0100
1
+ *** test/fixtures/four_lines_with_missing_new_line 2025-01-31 12:17:43.926013315 +0100
2
+ --- test/fixtures/four_lines 2025-01-31 12:17:43.926013315 +0100
3
3
  ***************
4
4
  *** 1,4 ****
5
5
  one
@@ -0,0 +1,9 @@
1
+ --- test/fixtures/four_lines_with_missing_new_line 2025-01-31 12:17:43.926013315 +0100
2
+ +++ test/fixtures/four_lines 2025-01-31 12:17:43.926013315 +0100
3
+ @@ -1,4 +1,4 @@
4
+ one
5
+ two
6
+ three
7
+ -four
8
+
9
+ +four
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "test_helper"
4
+ require "diff/lcs/block"
5
+
6
+ class TestBlock < Minitest::Test
7
+ include Diff::LCS::TestHelper
8
+
9
+ def test_op_unchanged
10
+ block = Diff::LCS::Block.from_chunk([])
11
+ assert_equal "^", block.op
12
+ end
13
+
14
+ def test_op_delete
15
+ changes = [Diff::LCS::Change.new("-", 0, "a")]
16
+ block = Diff::LCS::Block.from_chunk(changes)
17
+ assert_equal "-", block.op
18
+ end
19
+
20
+ def test_op_insert
21
+ changes = [Diff::LCS::Change.new("+", 0, "a")]
22
+ block = Diff::LCS::Block.from_chunk(changes)
23
+ assert_equal "+", block.op
24
+ end
25
+
26
+ def test_op_conflict
27
+ changes = [
28
+ Diff::LCS::Change.new("-", 0, "a"),
29
+ Diff::LCS::Change.new("+", 0, "b")
30
+ ]
31
+ block = Diff::LCS::Block.from_chunk(changes)
32
+ assert_equal "!", block.op
33
+ end
34
+ end