diff-lcs 1.4.4 → 1.6.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 (109) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +518 -0
  3. data/CODE_OF_CONDUCT.md +128 -0
  4. data/CONTRIBUTING.md +71 -0
  5. data/CONTRIBUTORS.md +49 -0
  6. data/{License.md → LICENCE.md} +21 -20
  7. data/Manifest.txt +76 -6
  8. data/README.md +92 -0
  9. data/Rakefile +83 -42
  10. data/SECURITY.md +41 -0
  11. data/bin/htmldiff +4 -4
  12. data/docs/artistic.txt +1 -1
  13. data/lib/diff/lcs/array.rb +1 -1
  14. data/lib/diff/lcs/backports.rb +6 -2
  15. data/lib/diff/lcs/block.rb +4 -4
  16. data/lib/diff/lcs/callbacks.rb +9 -7
  17. data/lib/diff/lcs/change.rb +22 -22
  18. data/lib/diff/lcs/htmldiff.rb +26 -16
  19. data/lib/diff/lcs/hunk.rb +66 -45
  20. data/lib/diff/lcs/internals.rb +24 -20
  21. data/lib/diff/lcs/ldiff.rb +93 -75
  22. data/lib/diff/lcs/version.rb +7 -0
  23. data/lib/diff/lcs.rb +86 -83
  24. data/lib/diff-lcs.rb +1 -1
  25. data/mise.toml +5 -0
  26. data/spec/change_spec.rb +50 -50
  27. data/spec/diff_spec.rb +14 -14
  28. data/spec/fixtures/123_x +2 -0
  29. data/spec/fixtures/456_x +2 -0
  30. data/spec/fixtures/empty +0 -0
  31. data/spec/fixtures/file1.bin +0 -0
  32. data/spec/fixtures/file2.bin +0 -0
  33. data/spec/fixtures/four_lines +4 -0
  34. data/spec/fixtures/four_lines_with_missing_new_line +4 -0
  35. data/spec/fixtures/ldiff/diff.missing_new_line1-e +1 -0
  36. data/spec/fixtures/ldiff/diff.missing_new_line1-f +1 -0
  37. data/spec/fixtures/ldiff/diff.missing_new_line2-e +1 -0
  38. data/spec/fixtures/ldiff/diff.missing_new_line2-f +1 -0
  39. data/spec/fixtures/ldiff/error.diff.chef-e +2 -0
  40. data/spec/fixtures/ldiff/error.diff.chef-f +2 -0
  41. data/spec/fixtures/ldiff/error.diff.missing_new_line1-e +1 -0
  42. data/spec/fixtures/ldiff/error.diff.missing_new_line1-f +1 -0
  43. data/spec/fixtures/ldiff/error.diff.missing_new_line2-e +1 -0
  44. data/spec/fixtures/ldiff/error.diff.missing_new_line2-f +1 -0
  45. data/spec/fixtures/ldiff/output.diff.bin1 +0 -0
  46. data/spec/fixtures/ldiff/output.diff.bin1-c +0 -0
  47. data/spec/fixtures/ldiff/output.diff.bin1-e +0 -0
  48. data/spec/fixtures/ldiff/output.diff.bin1-f +0 -0
  49. data/spec/fixtures/ldiff/output.diff.bin1-u +0 -0
  50. data/spec/fixtures/ldiff/output.diff.bin2 +1 -0
  51. data/spec/fixtures/ldiff/output.diff.bin2-c +1 -0
  52. data/spec/fixtures/ldiff/output.diff.bin2-e +1 -0
  53. data/spec/fixtures/ldiff/output.diff.bin2-f +1 -0
  54. data/spec/fixtures/ldiff/output.diff.bin2-u +1 -0
  55. data/spec/fixtures/ldiff/output.diff.chef +4 -0
  56. data/spec/fixtures/ldiff/output.diff.chef-c +15 -0
  57. data/spec/fixtures/ldiff/output.diff.chef-e +3 -0
  58. data/spec/fixtures/ldiff/output.diff.chef-f +3 -0
  59. data/spec/fixtures/ldiff/output.diff.chef-u +9 -0
  60. data/spec/fixtures/ldiff/output.diff.chef2 +7 -0
  61. data/spec/fixtures/ldiff/output.diff.chef2-c +20 -0
  62. data/spec/fixtures/ldiff/output.diff.chef2-d +7 -0
  63. data/spec/fixtures/ldiff/output.diff.chef2-e +7 -0
  64. data/spec/fixtures/ldiff/output.diff.chef2-f +7 -0
  65. data/spec/fixtures/ldiff/output.diff.chef2-u +16 -0
  66. data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines +5 -0
  67. data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-c +9 -0
  68. data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-e +6 -0
  69. data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-f +6 -0
  70. data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-u +7 -0
  71. data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty +5 -0
  72. data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-c +9 -0
  73. data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-e +1 -0
  74. data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-f +1 -0
  75. data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-u +7 -0
  76. data/spec/fixtures/ldiff/output.diff.issue95_trailing_context +4 -0
  77. data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-c +9 -0
  78. data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-e +3 -0
  79. data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-f +3 -0
  80. data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-u +6 -0
  81. data/spec/fixtures/ldiff/output.diff.missing_new_line1 +5 -0
  82. data/spec/fixtures/ldiff/output.diff.missing_new_line1-c +14 -0
  83. data/spec/fixtures/ldiff/output.diff.missing_new_line1-e +0 -0
  84. data/spec/fixtures/ldiff/output.diff.missing_new_line1-f +0 -0
  85. data/spec/fixtures/ldiff/output.diff.missing_new_line1-u +9 -0
  86. data/spec/fixtures/ldiff/output.diff.missing_new_line2 +5 -0
  87. data/spec/fixtures/ldiff/output.diff.missing_new_line2-c +14 -0
  88. data/spec/fixtures/ldiff/output.diff.missing_new_line2-e +0 -0
  89. data/spec/fixtures/ldiff/output.diff.missing_new_line2-f +0 -0
  90. data/spec/fixtures/ldiff/output.diff.missing_new_line2-u +9 -0
  91. data/spec/fixtures/new-chef +4 -0
  92. data/spec/fixtures/new-chef2 +17 -0
  93. data/spec/fixtures/old-chef +4 -0
  94. data/spec/fixtures/old-chef2 +14 -0
  95. data/spec/hunk_spec.rb +20 -20
  96. data/spec/issues_spec.rb +76 -70
  97. data/spec/lcs_spec.rb +11 -11
  98. data/spec/ldiff_spec.rb +30 -17
  99. data/spec/patch_spec.rb +84 -84
  100. data/spec/sdiff_spec.rb +111 -109
  101. data/spec/spec_helper.rb +162 -161
  102. data/spec/traverse_balanced_spec.rb +191 -189
  103. data/spec/traverse_sequences_spec.rb +31 -33
  104. metadata +112 -63
  105. data/Code-of-Conduct.md +0 -74
  106. data/Contributing.md +0 -118
  107. data/History.md +0 -319
  108. data/README.rdoc +0 -84
  109. data/autotest/discover.rb +0 -3
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,71 @@
1
+ # Contributing
2
+
3
+ Contribution to diff-lcs is encouraged in any form: a bug report, a feature
4
+ request, or code contributions. There are a few DOs and DON'Ts for
5
+ contributions.
6
+
7
+ - DO:
8
+
9
+ - Keep the coding style that already exists for any updated Ruby code (support
10
+ or otherwise). I use [Standard Ruby][standardrb] for linting and formatting.
11
+
12
+ - Use thoughtfully-named topic branches for contributions. Rebase your commits
13
+ into logical chunks as necessary.
14
+
15
+ - Use [quality commit messages][qcm].
16
+
17
+ - Add your name or GitHub handle to `CONTRIBUTORS.md` and a record in the
18
+ `CHANGELOG.md` as a separate commit from your main change. (Follow the style
19
+ in the `CHANGELOG.md` and provide a link to your PR.)
20
+
21
+ - Add or update tests as appropriate for your change. The test suite is
22
+ written in [RSpec][rspec].
23
+
24
+ - Add or update documentation as appropriate for your change. The
25
+ documentation is RDoc; diff-lcs does not use extensions that may be present
26
+ in alternative documentation generators.
27
+
28
+ - DO NOT:
29
+
30
+ - Modify `VERSION` in `lib/diff/lcs/version.rb`. When your patch is accepted
31
+ and a release is made, the version will be updated at that point.
32
+
33
+ - Modify `diff-lcs.gemspec`; it is a generated file. (You _may_ use
34
+ `rake gemspec` to regenerate it if your change involves metadata related to
35
+ gem itself).
36
+
37
+ - Modify the `Gemfile`.
38
+
39
+ ## Test Dependencies
40
+
41
+ diff-lcs uses Ryan Davis's [Hoe][Hoe] to manage the release process, and it adds
42
+ a number of rake tasks. You will mostly be interested in `rake`, which runs
43
+ tests in the same way that `rake spec` does.
44
+
45
+ To assist with the installation of the development dependencies for diff-lcs, I
46
+ have provided a Gemfile pointing to the (generated) `diff-lcs.gemspec` file.
47
+ `minitar.gemspec` file. This will permit you to use `bundle install` to install
48
+ the dependencies.
49
+
50
+ You can run tests with code coverage analysis by running `rake spec:coverage`.
51
+
52
+ ## Workflow
53
+
54
+ Here's the most direct way to get your work merged into the project:
55
+
56
+ - Fork the project.
57
+ - Clone your fork (`git clone git://github.com/<username>/diff-lcs.git`).
58
+ - Create a topic branch to contain your change
59
+ (`git checkout -b my_awesome_feature`).
60
+ - Hack away, add tests. Not necessarily in that order.
61
+ - Make sure everything still passes by running `rake`.
62
+ - If necessary, rebase your commits into logical chunks, without errors.
63
+ - Push the branch up (`git push origin my_awesome_feature`).
64
+ - Create a pull request against halostatue/diff-lcs and describe what your
65
+ change does and the why you think it should be merged.
66
+
67
+ [hoe]: https://github.com/seattlerb/hoe
68
+ [qcm]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
69
+ [release-gem]: https://github.com/rubygems/release-gem
70
+ [rspec]: http://rspec.info/documentation/
71
+ [standardrb]: https://github.com/standardrb/standard
data/CONTRIBUTORS.md ADDED
@@ -0,0 +1,49 @@
1
+ # Contributors
2
+
3
+ - Austin Ziegler (@halostatue) created diff-lcs.
4
+
5
+ Thanks to everyone else who has contributed to diff-lcs over the years:
6
+
7
+ - @ginriki
8
+ - @joshbronson
9
+ - @kevinmook
10
+ - @mckaz
11
+ - Akinori Musha
12
+ - Artem Ignatyev
13
+ - Brandon Fish
14
+ - Baptiste Courtois (@annih)
15
+ - Camille Drapier
16
+ - Cédric Boutillier
17
+ - @earlopain
18
+ - Gregg Kellogg
19
+ - Jagdeep Singh
20
+ - Jason Gladish
21
+ - Jon Rowe
22
+ - Josef Strzibny
23
+ - Josep (@apuratepp)
24
+ - Josh Bronson
25
+ - Jun Aruga
26
+ - Justin Steele
27
+ - Kenichi Kamiya
28
+ - Kensuke Nagae
29
+ - Kevin Ansfield
30
+ - Koichi Ito
31
+ - Mark Friedgan
32
+ - Masato Nakamura
33
+ - Mark Young
34
+ - Michael Granger
35
+ - Myron Marston
36
+ - Nicolas Leger
37
+ - Oleg Orlov
38
+ - Patrick Linnane
39
+ - Paul Kunysch
40
+ - Pete Higgins
41
+ - Peter Goldstein
42
+ - Peter Wagenet
43
+ - Philippe Lafoucrière
44
+ - Ryan Lovelett
45
+ - Scott Steele
46
+ - Simon Courtois
47
+ - Tien (@tiendo1011)
48
+ - Tomas Jura
49
+ - Vít Ondruch
@@ -1,39 +1,40 @@
1
- == License
1
+ # Licence
2
2
 
3
3
  This software is available under three licenses: the GNU GPL version 2 (or at
4
4
  your option, a later version), the Perl Artistic license, or the MIT license.
5
5
  Note that my preference for licensing is the MIT license, but Algorithm::Diff
6
- was dually originally licensed with the Perl Artistic and the GNU GPL ("the
7
- same terms as Perl itself") and given that the Ruby implementation originally
8
- hewed pretty closely to the Perl version, I must maintain the additional
9
- licensing terms.
6
+ was dually originally licensed with the Perl Artistic and the GNU GPL ("the same
7
+ terms as Perl itself") and given that the Ruby implementation originally hewed
8
+ pretty closely to the Perl version, I must maintain the additional licensing
9
+ terms.
10
10
 
11
- * Copyright 2004–2013 Austin Ziegler.
12
- * Adapted from Algorithm::Diff (Perl) by Ned Konz and a Smalltalk version by
11
+ - Copyright 2004–2025 Austin Ziegler and contributors.
12
+ - Adapted from Algorithm::Diff (Perl) by Ned Konz and a Smalltalk version by
13
13
  Mario I. Wolczko.
14
14
 
15
- === MIT License
15
+ ## MIT License
16
16
 
17
17
  Permission is hereby granted, free of charge, to any person obtaining a copy of
18
18
  this software and associated documentation files (the "Software"), to deal in
19
19
  the Software without restriction, including without limitation the rights to
20
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
21
- of the Software, and to permit persons to whom the Software is furnished to do
22
- so, subject to the following conditions:
20
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
21
+ the Software, and to permit persons to whom the Software is furnished to do so,
22
+ subject to the following conditions:
23
23
 
24
24
  The above copyright notice and this permission notice shall be included in all
25
25
  copies or substantial portions of the Software.
26
26
 
27
27
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
- SOFTWARE.
34
-
35
- === Perl Artistic License (version 2)
28
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
29
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
30
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
31
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33
+
34
+ ## Perl Artistic License
35
+
36
36
  See the file docs/artistic.txt in the main distribution.
37
37
 
38
- === GNU GPL version 2
38
+ ## GNU GPL version 2
39
+
39
40
  See the file docs/COPYING.txt in the main distribution.
data/Manifest.txt CHANGED
@@ -1,12 +1,13 @@
1
1
  .rspec
2
- Code-of-Conduct.md
3
- Contributing.md
4
- History.md
5
- License.md
2
+ CHANGELOG.md
3
+ CODE_OF_CONDUCT.md
4
+ CONTRIBUTING.md
5
+ CONTRIBUTORS.md
6
+ LICENCE.md
6
7
  Manifest.txt
7
- README.rdoc
8
+ README.md
8
9
  Rakefile
9
- autotest/discover.rb
10
+ SECURITY.md
10
11
  bin/htmldiff
11
12
  bin/ldiff
12
13
  docs/COPYING.txt
@@ -23,17 +24,86 @@ lib/diff/lcs/hunk.rb
23
24
  lib/diff/lcs/internals.rb
24
25
  lib/diff/lcs/ldiff.rb
25
26
  lib/diff/lcs/string.rb
27
+ lib/diff/lcs/version.rb
28
+ mise.toml
26
29
  spec/change_spec.rb
27
30
  spec/diff_spec.rb
31
+ spec/fixtures/123_x
32
+ spec/fixtures/456_x
28
33
  spec/fixtures/aX
29
34
  spec/fixtures/bXaX
30
35
  spec/fixtures/ds1.csv
31
36
  spec/fixtures/ds2.csv
37
+ spec/fixtures/empty
38
+ spec/fixtures/file1.bin
39
+ spec/fixtures/file2.bin
40
+ spec/fixtures/four_lines
41
+ spec/fixtures/four_lines_with_missing_new_line
42
+ spec/fixtures/ldiff/diff.missing_new_line1-e
43
+ spec/fixtures/ldiff/diff.missing_new_line1-f
44
+ spec/fixtures/ldiff/diff.missing_new_line2-e
45
+ spec/fixtures/ldiff/diff.missing_new_line2-f
46
+ spec/fixtures/ldiff/error.diff.chef-e
47
+ spec/fixtures/ldiff/error.diff.chef-f
48
+ spec/fixtures/ldiff/error.diff.missing_new_line1-e
49
+ spec/fixtures/ldiff/error.diff.missing_new_line1-f
50
+ spec/fixtures/ldiff/error.diff.missing_new_line2-e
51
+ spec/fixtures/ldiff/error.diff.missing_new_line2-f
32
52
  spec/fixtures/ldiff/output.diff
33
53
  spec/fixtures/ldiff/output.diff-c
34
54
  spec/fixtures/ldiff/output.diff-e
35
55
  spec/fixtures/ldiff/output.diff-f
36
56
  spec/fixtures/ldiff/output.diff-u
57
+ spec/fixtures/ldiff/output.diff.bin1
58
+ spec/fixtures/ldiff/output.diff.bin1-c
59
+ spec/fixtures/ldiff/output.diff.bin1-e
60
+ spec/fixtures/ldiff/output.diff.bin1-f
61
+ spec/fixtures/ldiff/output.diff.bin1-u
62
+ spec/fixtures/ldiff/output.diff.bin2
63
+ spec/fixtures/ldiff/output.diff.bin2-c
64
+ spec/fixtures/ldiff/output.diff.bin2-e
65
+ spec/fixtures/ldiff/output.diff.bin2-f
66
+ spec/fixtures/ldiff/output.diff.bin2-u
67
+ spec/fixtures/ldiff/output.diff.chef
68
+ spec/fixtures/ldiff/output.diff.chef-c
69
+ spec/fixtures/ldiff/output.diff.chef-e
70
+ spec/fixtures/ldiff/output.diff.chef-f
71
+ spec/fixtures/ldiff/output.diff.chef-u
72
+ spec/fixtures/ldiff/output.diff.chef2
73
+ spec/fixtures/ldiff/output.diff.chef2-c
74
+ spec/fixtures/ldiff/output.diff.chef2-d
75
+ spec/fixtures/ldiff/output.diff.chef2-e
76
+ spec/fixtures/ldiff/output.diff.chef2-f
77
+ spec/fixtures/ldiff/output.diff.chef2-u
78
+ spec/fixtures/ldiff/output.diff.empty.vs.four_lines
79
+ spec/fixtures/ldiff/output.diff.empty.vs.four_lines-c
80
+ spec/fixtures/ldiff/output.diff.empty.vs.four_lines-e
81
+ spec/fixtures/ldiff/output.diff.empty.vs.four_lines-f
82
+ spec/fixtures/ldiff/output.diff.empty.vs.four_lines-u
83
+ spec/fixtures/ldiff/output.diff.four_lines.vs.empty
84
+ spec/fixtures/ldiff/output.diff.four_lines.vs.empty-c
85
+ spec/fixtures/ldiff/output.diff.four_lines.vs.empty-e
86
+ spec/fixtures/ldiff/output.diff.four_lines.vs.empty-f
87
+ spec/fixtures/ldiff/output.diff.four_lines.vs.empty-u
88
+ spec/fixtures/ldiff/output.diff.issue95_trailing_context
89
+ spec/fixtures/ldiff/output.diff.issue95_trailing_context-c
90
+ spec/fixtures/ldiff/output.diff.issue95_trailing_context-e
91
+ spec/fixtures/ldiff/output.diff.issue95_trailing_context-f
92
+ spec/fixtures/ldiff/output.diff.issue95_trailing_context-u
93
+ spec/fixtures/ldiff/output.diff.missing_new_line1
94
+ spec/fixtures/ldiff/output.diff.missing_new_line1-c
95
+ spec/fixtures/ldiff/output.diff.missing_new_line1-e
96
+ spec/fixtures/ldiff/output.diff.missing_new_line1-f
97
+ spec/fixtures/ldiff/output.diff.missing_new_line1-u
98
+ spec/fixtures/ldiff/output.diff.missing_new_line2
99
+ spec/fixtures/ldiff/output.diff.missing_new_line2-c
100
+ spec/fixtures/ldiff/output.diff.missing_new_line2-e
101
+ spec/fixtures/ldiff/output.diff.missing_new_line2-f
102
+ spec/fixtures/ldiff/output.diff.missing_new_line2-u
103
+ spec/fixtures/new-chef
104
+ spec/fixtures/new-chef2
105
+ spec/fixtures/old-chef
106
+ spec/fixtures/old-chef2
37
107
  spec/hunk_spec.rb
38
108
  spec/issues_spec.rb
39
109
  spec/lcs_spec.rb
data/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # Diff::LCS
2
+
3
+ - home :: https://github.com/halostatue/diff-lcs
4
+ - changelog :: https://github.com/halostatue/diff-lcs/blob/main/CHANGELOG.md
5
+ - code :: https://github.com/halostatue/diff-lcs
6
+ - bugs :: https://github.com/halostatue/diff-lcs/issues
7
+ - rdoc :: http://rubydoc.info/github/halostatue/diff-lcs
8
+
9
+ <a href="https://github.com/halostatue/diff-lcs/actions">
10
+ <img src="https://github.com/halostatue/diff-lcs/workflows/CI/badge.svg" />
11
+ </a>
12
+
13
+ ## Description
14
+
15
+ Diff::LCS computes the difference between two Enumerable sequences using the
16
+ McIlroy-Hunt longest common subsequence (LCS) algorithm. It includes utilities
17
+ to create a simple HTML diff output format and a standard diff-like tool.
18
+
19
+ This is release 1.6.1, providing a simple extension that allows for
20
+ Diff::LCS::Change objects to be treated implicitly as arrays and fixes a number
21
+ of formatting issues.
22
+
23
+ Ruby versions below 2.5 are soft-deprecated, which means that older versions are
24
+ no longer part of the CI test suite. If any changes have been introduced that
25
+ break those versions, bug reports and patches will be accepted, but it will be
26
+ up to the reporter to verify any fixes prior to release. The next major release
27
+ will completely break compatibility.
28
+
29
+ ## Synopsis
30
+
31
+ Using this module is quite simple. By default, Diff::LCS does not extend objects
32
+ with the Diff::LCS interface, but will be called as if it were a function:
33
+
34
+ ```ruby
35
+ require 'diff/lcs'
36
+
37
+ seq1 = %w(a b c e h j l m n p)
38
+ seq2 = %w(b c d e f j k l m r s t)
39
+
40
+ lcs = Diff::LCS.LCS(seq1, seq2)
41
+ diffs = Diff::LCS.diff(seq1, seq2)
42
+ sdiff = Diff::LCS.sdiff(seq1, seq2)
43
+ seq = Diff::LCS.traverse_sequences(seq1, seq2, callback_obj)
44
+ bal = Diff::LCS.traverse_balanced(seq1, seq2, callback_obj)
45
+ seq2 == Diff::LCS.patch!(seq1, diffs)
46
+ seq1 == Diff::LCS.unpatch!(seq2, diffs)
47
+ seq2 == Diff::LCS.patch!(seq1, sdiff)
48
+ seq1 == Diff::LCS.unpatch!(seq2, sdiff)
49
+ ```
50
+
51
+ Objects can be extended with Diff::LCS:
52
+
53
+ ```ruby
54
+ seq1.extend(Diff::LCS)
55
+ lcs = seq1.lcs(seq2)
56
+ diffs = seq1.diff(seq2)
57
+ sdiff = seq1.sdiff(seq2)
58
+ seq = seq1.traverse_sequences(seq2, callback_obj)
59
+ bal = seq1.traverse_balanced(seq2, callback_obj)
60
+ seq2 == seq1.patch!(diffs)
61
+ seq1 == seq2.unpatch!(diffs)
62
+ seq2 == seq1.patch!(sdiff)
63
+ seq1 == seq2.unpatch!(sdiff)
64
+ ```
65
+
66
+ By requiring 'diff/lcs/array' or 'diff/lcs/string', Array or String will be
67
+ extended for use this way.
68
+
69
+ Note that Diff::LCS requires a sequenced enumerable container, which means that
70
+ the order of enumeration is both predictable and consistent for the same set of
71
+ data. While it is theoretically possible to generate a diff for an unordered
72
+ hash, it will only be meaningful if the enumeration of the hashes is consistent.
73
+ In general, this will mean that containers that behave like String or Array will
74
+ perform best.
75
+
76
+ ## History
77
+
78
+ Diff::LCS is a port of Perl's Algorithm::Diff that uses the McIlroy-Hunt longest
79
+ common subsequence (LCS) algorithm to compute intelligent differences between
80
+ two sequenced enumerable containers. The implementation is based on Mario I.
81
+ Wolczko's [Smalltalk version 1.2][smalltalk] (1993) and Ned Konz's Perl version
82
+ [Algorithm::Diff 1.15][perl]. `Diff::LCS#sdiff` and
83
+ `Diff::LCS#traverse_balanced` were originally written for the Perl version by
84
+ Mike Schilli.
85
+
86
+ The algorithm is described in <em>A Fast Algorithm for Computing Longest Common
87
+ Subsequences</em>, CACM, vol.20, no.5, pp.350-353, May 1977, with a few minor
88
+ improvements to improve the speed. A simplified description of the algorithm,
89
+ originally written for the Perl version, was written by Mark-Jason Dominus.
90
+
91
+ [smalltalk]: ftp://st.cs.uiuc.edu/pub/Smalltalk/MANCHESTER/manchester/4.0/diff.st
92
+ [perl]: http://search.cpan.org/~nedkonz/Algorithm-Diff-1.15/
data/Rakefile CHANGED
@@ -1,74 +1,115 @@
1
- # frozen_string_literal: true
1
+ require "rubygems"
2
+ require "rspec"
3
+ require "rspec/core/rake_task"
4
+ require "hoe"
5
+ require "rake/clean"
2
6
 
3
- require 'rubygems'
4
- require 'rspec'
5
- require 'hoe'
7
+ MAINTENANCE = ENV["MAINTENANCE"] == "true"
8
+ BUILD_DOCS = MAINTENANCE || ENV["DOCS"] == "true"
9
+ TRUSTED_RELEASE = ENV["rubygems_release_gem"] == "true"
6
10
 
7
- Hoe.plugin :bundler
8
- Hoe.plugin :doofus
9
- Hoe.plugin :gemspec2
10
- Hoe.plugin :git
11
+ Hoe.plugin :halostatue
12
+ Hoe.plugin :rubygems
11
13
 
12
- if RUBY_VERSION < '1.9'
13
- class Array #:nodoc:
14
+ Hoe.plugins.delete :debug
15
+ Hoe.plugins.delete :newb
16
+ Hoe.plugins.delete :signing
17
+ Hoe.plugins.delete :publish unless BUILD_DOCS
18
+
19
+ if RUBY_VERSION < "1.9"
20
+ class Array # :nodoc:
14
21
  def to_h
15
22
  Hash[*flatten(1)]
16
23
  end
17
24
  end
18
25
 
19
- class Gem::Specification #:nodoc:
20
- def metadata=(*); end
26
+ class Gem::Specification # :nodoc:
27
+ def metadata=(*)
28
+ end
21
29
 
22
- def default_value(*); end
30
+ def default_value(*)
31
+ end
23
32
  end
24
33
 
25
- class Object #:nodoc:
34
+ class Object # :nodoc:
26
35
  def caller_locations(*)
27
36
  []
28
37
  end
29
38
  end
30
39
  end
31
40
 
32
- _spec = Hoe.spec 'diff-lcs' do
33
- developer('Austin Ziegler', 'halostatue@gmail.com')
41
+ _spec = Hoe.spec "diff-lcs" do
42
+ developer("Austin Ziegler", "halostatue@gmail.com")
43
+
44
+ self.trusted_release = TRUSTED_RELEASE
45
+
46
+ require_ruby_version ">= 1.8"
47
+
48
+ self.history_file = "CHANGELOG.md"
49
+ self.readme_file = "README.md"
50
+ self.licenses = ["MIT", "Artistic-1.0-Perl", "GPL-2.0-or-later"]
51
+
52
+ spec_extras[:metadata] = ->(val) {
53
+ val["rubygems_mfa_required"] = "true"
54
+ }
55
+
56
+ extra_dev_deps << ["hoe", "~> 4.0"]
57
+ extra_dev_deps << ["hoe-halostatue", "~> 2.0"]
58
+ extra_dev_deps << ["hoe-rubygems", "~> 1.0"]
59
+ extra_dev_deps << ["rspec", ">= 2.0", "< 4"]
60
+ extra_dev_deps << ["rake", ">= 10.0", "< 14"]
61
+ extra_dev_deps << ["rdoc", ">= 6.3.1", "< 7"]
62
+ end
34
63
 
35
- require_ruby_version '>= 1.8'
64
+ if BUILD_DOCS
65
+ rake_tasks = Rake.application.instance_variable_get(:@tasks)
66
+ tasks = ["publish_docs", "publish_on_announce", "debug_email", "post_blog", "announce"]
67
+ tasks.each do |task|
68
+ rake_tasks.delete(task)
69
+ end
70
+ end
36
71
 
37
- self.history_file = 'History.md'
38
- self.readme_file = 'README.rdoc'
39
- self.licenses = ['MIT', 'Artistic-2.0', 'GPL-2.0+']
72
+ desc "Run all specifications"
73
+ RSpec::Core::RakeTask.new(:spec) do |t|
74
+ rspec_dirs = %w[spec lib].join(":")
75
+ t.rspec_opts = ["-I#{rspec_dirs}"]
76
+ end
40
77
 
41
- extra_dev_deps << ['hoe-doofus', '~> 1.0']
42
- extra_dev_deps << ['hoe-gemspec2', '~> 1.1']
43
- extra_dev_deps << ['hoe-git', '~> 1.6']
44
- extra_dev_deps << ['hoe-rubygems', '~> 1.0']
45
- extra_dev_deps << ['rspec', '>= 2.0', '< 4']
46
- extra_dev_deps << ['rake', '>= 10.0', '< 14']
47
- extra_dev_deps << ['rdoc', '>= 0']
78
+ task :version do
79
+ require "diff/lcs/version"
80
+ puts Diff::LCS::VERSION
48
81
  end
49
82
 
50
- if RUBY_VERSION >= '2.0' && RUBY_ENGINE == 'ruby'
83
+ Rake::Task["spec"].actions.uniq! { |a| a.source_location }
84
+
85
+ # standard:disable Style/HashSyntax
86
+ task :default => :spec unless Rake::Task["default"].prereqs.include?("spec")
87
+ task :test => :spec unless Rake::Task["test"].prereqs.include?("spec")
88
+ # standard:enable Style/HashSyntax
89
+
90
+ if RUBY_VERSION >= "3.0" && RUBY_ENGINE == "ruby"
51
91
  namespace :spec do
52
92
  desc "Runs test coverage. Only works Ruby 2.0+ and assumes 'simplecov' is installed."
53
93
  task :coverage do
54
- ENV['COVERAGE'] = 'yes'
55
- Rake::Task['spec'].execute
94
+ ENV["COVERAGE"] = "true"
95
+ Rake::Task["spec"].execute
56
96
  end
57
97
  end
58
98
  end
59
99
 
60
- task :ruby18 do
61
- puts <<-MESSAGE
62
- You are starting a barebones Ruby 1.8 docker environment. You will need to
63
- do the following:
100
+ if MAINTENANCE
101
+ task ruby18: :package do
102
+ require "diff/lcs/version"
103
+ # standard:disable Layout/HeredocIndentation
104
+ puts <<-MESSAGE
105
+ You are starting a barebones Ruby 1.8 docker environment for testing.
106
+ A snapshot package has been built, so install it with:
64
107
 
65
- - mv Gemfile.lock{,.v2}
66
- - gem install bundler --version 1.17.2 --no-ri --no-rdoc
67
- - ruby -S bundle
68
- - rake
108
+ cd diff-lcs
109
+ gem install pkg/diff-lcs-#{Diff::LCS::VERSION}
69
110
 
70
- Don't forget to restore your Gemfile.lock after testing.
71
-
72
- MESSAGE
73
- sh "docker run -it --rm -v #{Dir.pwd}:/root/diff-lcs bellbind/docker-ruby18-rails2 bash -l"
111
+ MESSAGE
112
+ # standard:enable Layout/HeredocIndentation
113
+ sh "docker run -it --rm -v #{Dir.pwd}:/root/diff-lcs bellbind/docker-ruby18-rails2 bash -l"
114
+ end
74
115
  end
data/SECURITY.md ADDED
@@ -0,0 +1,41 @@
1
+ # diff-lcs Security
2
+
3
+ ## Supported Versions
4
+
5
+ Security reports are accepted for the most recent major release and the previous
6
+ version for a limited time after the initial major release version. After a
7
+ major release, the previous version will receive full support for six months and
8
+ security support for an additional six months (for a total of twelve months).
9
+
10
+ Because diff-lcs 1.x supports a wide range of Ruby versions, security reports
11
+ will only be accepted when they can be demonstrated on Ruby 3.1 or higher.
12
+
13
+ > [!information]
14
+ >
15
+ > There will be a diff-lcs 2.0 released in 2025 which narrows support to modern
16
+ > versions of Ruby only.
17
+ >
18
+ > | Release Date | Support Ends | Security Support Ends |
19
+ > | ------------ | ------------ | --------------------- |
20
+ > | 2025 | +6 months | +12 months |
21
+ >
22
+ > If the 2.0.0 release happens on 2025-07-01, regular support for diff-lcs 1.x
23
+ > will end on 2026-12-31 and security support for diff-lcs 1.x will end on
24
+ > 2026-06-30.
25
+
26
+ ## Reporting a Vulnerability
27
+
28
+ By preference, use the [Tidelift security contact][tidelift]. Tidelift will
29
+ coordinate the fix and disclosure.
30
+
31
+ Alternatively, Send an email to [diff-lcs@halostatue.ca][email] with the text
32
+ `Diff::LCS` in the subject. Emails sent to this address should be encrypted
33
+ using [age][age] with the following public key:
34
+
35
+ ```
36
+ age1fc6ngxmn02m62fej5cl30lrvwmxn4k3q2atqu53aatekmnqfwumqj4g93w
37
+ ```
38
+
39
+ [tidelift]: https://tidelift.com/security
40
+ [email]: mailto:diff-lcs@halostatue.ca
41
+ [age]: https://github.com/FiloSottile/age
data/bin/htmldiff CHANGED
@@ -1,11 +1,11 @@
1
1
  #! /usr/bin/env ruby -w
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'diff/lcs'
5
- require 'diff/lcs/htmldiff'
4
+ require "diff/lcs"
5
+ require "diff/lcs/htmldiff"
6
6
 
7
7
  begin
8
- require 'text/format'
8
+ require "text/format"
9
9
  rescue LoadError
10
10
  Diff::LCS::HTMLDiff.can_expand_tabs = false
11
11
  end
@@ -24,7 +24,7 @@ options = { :title => "diff #{ARGV[0]} #{ARGV[1]}" }
24
24
  htmldiff = Diff::LCS::HTMLDiff.new(left, right, options)
25
25
 
26
26
  if ARGV[2]
27
- File.open(ARGV[2], 'w') do |f|
27
+ File.open(ARGV[2], "w") do |f|
28
28
  htmldiff.options[:output] = f
29
29
  htmldiff.run
30
30
  end
data/docs/artistic.txt CHANGED
@@ -122,6 +122,6 @@ products derived from this software without specific prior written permission.
122
122
 
123
123
  10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
124
124
  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
125
- WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
125
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
126
126
 
127
127
  The End
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'diff/lcs'
3
+ require "diff/lcs"
4
4
 
5
5
  class Array
6
6
  include Diff::LCS
@@ -1,9 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  unless 0.respond_to?(:positive?)
4
- class Fixnum # rubocop:disable Lint/UnifiedInteger, Style/Documentation
4
+ class Fixnum # standard:disable Lint/UnifiedInteger
5
5
  def positive?
6
- self > 0 # rubocop:disable Style/NumericPredicate
6
+ self > 0
7
+ end
8
+
9
+ def negative?
10
+ self < 0
7
11
  end
8
12
  end
9
13
  end
@@ -25,13 +25,13 @@ class Diff::LCS::Block
25
25
  def op
26
26
  case [@remove.empty?, @insert.empty?]
27
27
  when [false, false]
28
- '!'
28
+ "!"
29
29
  when [false, true]
30
- '-'
30
+ "-"
31
31
  when [true, false]
32
- '+'
32
+ "+"
33
33
  else # [true, true]
34
- '^'
34
+ "^"
35
35
  end
36
36
  end
37
37
  end