diff-lcs 1.5.1 → 2.0.0

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 (132) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +581 -0
  3. data/CODE_OF_CONDUCT.md +166 -0
  4. data/CONTRIBUTING.md +127 -0
  5. data/CONTRIBUTORS.md +59 -0
  6. data/LICENCE.md +68 -0
  7. data/Manifest.txt +99 -35
  8. data/README.md +105 -0
  9. data/Rakefile +107 -96
  10. data/SECURITY.md +36 -0
  11. data/integration/compare/array_diff_spec.rb +10 -0
  12. data/integration/compare/hash_diff_spec.rb +25 -0
  13. data/integration/compare/string_diff_spec.rb +10 -0
  14. data/integration/rspec_differ_spec.rb +26 -0
  15. data/integration/rspec_expectations_spec.rb +32 -0
  16. data/integration/runner +20 -0
  17. data/lib/diff/lcs/block.rb +29 -24
  18. data/lib/diff/lcs/callbacks.rb +240 -242
  19. data/lib/diff/lcs/change.rb +102 -104
  20. data/lib/diff/lcs/hunk.rb +110 -157
  21. data/lib/diff/lcs/internals.rb +92 -96
  22. data/lib/diff/lcs/ldiff.rb +81 -73
  23. data/lib/diff/lcs/version.rb +7 -0
  24. data/lib/diff/lcs.rb +440 -466
  25. data/{docs → licenses}/artistic.txt +1 -1
  26. data/licenses/dco.txt +34 -0
  27. data/spec/hunk_spec.rb +33 -46
  28. data/spec/issues_spec.rb +32 -32
  29. data/spec/lcs_spec.rb +6 -6
  30. data/spec/ldiff_spec.rb +27 -16
  31. data/spec/patch_spec.rb +1 -1
  32. data/spec/spec_helper.rb +98 -108
  33. data/test/fixtures/123_x +2 -0
  34. data/test/fixtures/456_x +2 -0
  35. data/test/fixtures/empty +0 -0
  36. data/test/fixtures/file1.bin +0 -0
  37. data/test/fixtures/file2.bin +0 -0
  38. data/test/fixtures/four_lines +4 -0
  39. data/test/fixtures/four_lines_with_missing_new_line +4 -0
  40. data/test/fixtures/ldiff/diff.missing_new_line1-e +1 -0
  41. data/test/fixtures/ldiff/diff.missing_new_line1-f +1 -0
  42. data/test/fixtures/ldiff/diff.missing_new_line2-e +1 -0
  43. data/test/fixtures/ldiff/diff.missing_new_line2-f +1 -0
  44. data/test/fixtures/ldiff/error.diff.chef-e +2 -0
  45. data/test/fixtures/ldiff/error.diff.chef-f +2 -0
  46. data/test/fixtures/ldiff/error.diff.missing_new_line1-e +1 -0
  47. data/test/fixtures/ldiff/error.diff.missing_new_line1-f +1 -0
  48. data/test/fixtures/ldiff/error.diff.missing_new_line2-e +1 -0
  49. data/test/fixtures/ldiff/error.diff.missing_new_line2-f +1 -0
  50. data/test/fixtures/ldiff/output.diff-c +7 -0
  51. data/test/fixtures/ldiff/output.diff-u +5 -0
  52. data/test/fixtures/ldiff/output.diff.bin1 +0 -0
  53. data/test/fixtures/ldiff/output.diff.bin1-c +0 -0
  54. data/test/fixtures/ldiff/output.diff.bin1-e +0 -0
  55. data/test/fixtures/ldiff/output.diff.bin1-f +0 -0
  56. data/test/fixtures/ldiff/output.diff.bin1-u +0 -0
  57. data/test/fixtures/ldiff/output.diff.bin2 +1 -0
  58. data/test/fixtures/ldiff/output.diff.bin2-c +1 -0
  59. data/test/fixtures/ldiff/output.diff.bin2-e +1 -0
  60. data/test/fixtures/ldiff/output.diff.bin2-f +1 -0
  61. data/test/fixtures/ldiff/output.diff.bin2-u +1 -0
  62. data/{spec → test}/fixtures/ldiff/output.diff.chef-c +2 -2
  63. data/test/fixtures/ldiff/output.diff.chef-u +9 -0
  64. data/{spec → test}/fixtures/ldiff/output.diff.chef2-c +2 -2
  65. data/{spec → test}/fixtures/ldiff/output.diff.chef2-u +2 -2
  66. data/test/fixtures/ldiff/output.diff.empty.vs.four_lines +5 -0
  67. data/test/fixtures/ldiff/output.diff.empty.vs.four_lines-c +9 -0
  68. data/test/fixtures/ldiff/output.diff.empty.vs.four_lines-e +6 -0
  69. data/test/fixtures/ldiff/output.diff.empty.vs.four_lines-f +6 -0
  70. data/test/fixtures/ldiff/output.diff.empty.vs.four_lines-u +7 -0
  71. data/test/fixtures/ldiff/output.diff.four_lines.vs.empty +5 -0
  72. data/test/fixtures/ldiff/output.diff.four_lines.vs.empty-c +9 -0
  73. data/test/fixtures/ldiff/output.diff.four_lines.vs.empty-e +1 -0
  74. data/test/fixtures/ldiff/output.diff.four_lines.vs.empty-f +1 -0
  75. data/test/fixtures/ldiff/output.diff.four_lines.vs.empty-u +7 -0
  76. data/test/fixtures/ldiff/output.diff.issue95_trailing_context +4 -0
  77. data/test/fixtures/ldiff/output.diff.issue95_trailing_context-c +9 -0
  78. data/{spec/fixtures/ldiff/output.diff-e → test/fixtures/ldiff/output.diff.issue95_trailing_context-e} +1 -1
  79. data/{spec/fixtures/ldiff/output.diff-f → test/fixtures/ldiff/output.diff.issue95_trailing_context-f} +1 -1
  80. data/test/fixtures/ldiff/output.diff.issue95_trailing_context-u +6 -0
  81. data/test/fixtures/ldiff/output.diff.missing_new_line1 +5 -0
  82. data/test/fixtures/ldiff/output.diff.missing_new_line1-c +14 -0
  83. data/test/fixtures/ldiff/output.diff.missing_new_line1-e +0 -0
  84. data/test/fixtures/ldiff/output.diff.missing_new_line1-f +0 -0
  85. data/test/fixtures/ldiff/output.diff.missing_new_line1-u +9 -0
  86. data/test/fixtures/ldiff/output.diff.missing_new_line2 +5 -0
  87. data/test/fixtures/ldiff/output.diff.missing_new_line2-c +14 -0
  88. data/test/fixtures/ldiff/output.diff.missing_new_line2-e +0 -0
  89. data/test/fixtures/ldiff/output.diff.missing_new_line2-f +0 -0
  90. data/test/fixtures/ldiff/output.diff.missing_new_line2-u +9 -0
  91. data/test/test_block.rb +34 -0
  92. data/test/test_change.rb +234 -0
  93. data/test/test_diff.rb +53 -0
  94. data/test/test_helper.rb +225 -0
  95. data/test/test_hunk.rb +72 -0
  96. data/test/test_issues.rb +168 -0
  97. data/test/test_lcs.rb +47 -0
  98. data/test/test_ldiff.rb +89 -0
  99. data/test/test_patch.rb +362 -0
  100. data/test/test_sdiff.rb +167 -0
  101. data/test/test_traverse_balanced.rb +322 -0
  102. data/test/test_traverse_sequences.rb +187 -0
  103. metadata +211 -103
  104. data/.rspec +0 -1
  105. data/Code-of-Conduct.md +0 -74
  106. data/Contributing.md +0 -121
  107. data/History.md +0 -431
  108. data/License.md +0 -41
  109. data/README.rdoc +0 -84
  110. data/bin/htmldiff +0 -35
  111. data/lib/diff/lcs/backports.rb +0 -9
  112. data/lib/diff/lcs/htmldiff.rb +0 -158
  113. data/spec/fixtures/ldiff/output.diff-c +0 -7
  114. data/spec/fixtures/ldiff/output.diff-u +0 -5
  115. data/spec/fixtures/ldiff/output.diff.chef-e +0 -3
  116. data/spec/fixtures/ldiff/output.diff.chef-f +0 -3
  117. data/spec/fixtures/ldiff/output.diff.chef-u +0 -9
  118. data/spec/fixtures/ldiff/output.diff.chef2-e +0 -7
  119. data/spec/fixtures/ldiff/output.diff.chef2-f +0 -7
  120. /data/{docs → licenses}/COPYING.txt +0 -0
  121. /data/{spec → test}/fixtures/aX +0 -0
  122. /data/{spec → test}/fixtures/bXaX +0 -0
  123. /data/{spec → test}/fixtures/ds1.csv +0 -0
  124. /data/{spec → test}/fixtures/ds2.csv +0 -0
  125. /data/{spec → test}/fixtures/ldiff/output.diff +0 -0
  126. /data/{spec → test}/fixtures/ldiff/output.diff.chef +0 -0
  127. /data/{spec → test}/fixtures/ldiff/output.diff.chef2 +0 -0
  128. /data/{spec → test}/fixtures/ldiff/output.diff.chef2-d +0 -0
  129. /data/{spec → test}/fixtures/new-chef +0 -0
  130. /data/{spec → test}/fixtures/new-chef2 +0 -0
  131. /data/{spec → test}/fixtures/old-chef +0 -0
  132. /data/{spec → test}/fixtures/old-chef2 +0 -0
@@ -1,158 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "cgi"
4
-
5
- # Produce a simple HTML diff view.
6
- class Diff::LCS::HTMLDiff
7
- class << self
8
- attr_accessor :can_expand_tabs # :nodoc:
9
- end
10
- self.can_expand_tabs = true
11
-
12
- class Callbacks # :nodoc:
13
- attr_accessor :output
14
- attr_accessor :match_class
15
- attr_accessor :only_a_class
16
- attr_accessor :only_b_class
17
-
18
- def initialize(output, options = {})
19
- @output = output
20
- options ||= {}
21
-
22
- @match_class = options[:match_class] || "match"
23
- @only_a_class = options[:only_a_class] || "only_a"
24
- @only_b_class = options[:only_b_class] || "only_b"
25
- end
26
-
27
- def htmlize(element, css_class)
28
- element = "&nbsp;" if element.empty?
29
- %(<pre class="#{__send__(css_class)}">#{element}</pre>\n)
30
- end
31
- private :htmlize
32
-
33
- # This will be called with both lines are the same
34
- def match(event)
35
- @output << htmlize(event.old_element, :match_class)
36
- end
37
-
38
- # This will be called when there is a line in A that isn't in B
39
- def discard_a(event)
40
- @output << htmlize(event.old_element, :only_a_class)
41
- end
42
-
43
- # This will be called when there is a line in B that isn't in A
44
- def discard_b(event)
45
- @output << htmlize(event.new_element, :only_b_class)
46
- end
47
- end
48
-
49
- # standard:disable Style/HashSyntax
50
- DEFAULT_OPTIONS = {
51
- :expand_tabs => nil,
52
- :output => nil,
53
- :css => nil,
54
- :title => nil
55
- }.freeze
56
- # standard:enable Style/HashSyntax
57
-
58
- # standard:disable Layout/HeredocIndentation
59
- DEFAULT_CSS = <<-CSS
60
- body { margin: 0; }
61
- .diff
62
- {
63
- border: 1px solid black;
64
- margin: 1em 2em;
65
- }
66
- p
67
- {
68
- margin-left: 2em;
69
- }
70
- pre
71
- {
72
- padding-left: 1em;
73
- margin: 0;
74
- font-family: Inconsolata, Consolas, Lucida, Courier, monospaced;
75
- white-space: pre;
76
- }
77
- .match { }
78
- .only_a
79
- {
80
- background-color: #fdd;
81
- color: red;
82
- text-decoration: line-through;
83
- }
84
- .only_b
85
- {
86
- background-color: #ddf;
87
- color: blue;
88
- border-left: 3px solid blue
89
- }
90
- h1 { margin-left: 2em; }
91
- CSS
92
- # standard:enable Layout/HeredocIndentation
93
-
94
- def initialize(left, right, options = nil)
95
- @left = left
96
- @right = right
97
- @options = options
98
-
99
- @options = DEFAULT_OPTIONS.dup if @options.nil?
100
- end
101
-
102
- def verify_options
103
- @options[:expand_tabs] ||= 4
104
- @options[:expand_tabs] = 4 if @options[:expand_tabs].negative?
105
-
106
- @options[:output] ||= $stdout
107
-
108
- @options[:css] ||= DEFAULT_CSS.dup
109
-
110
- @options[:title] ||= "diff"
111
- end
112
- private :verify_options
113
-
114
- attr_reader :options
115
-
116
- def run
117
- verify_options
118
-
119
- if @options[:expand_tabs].positive? && self.class.can_expand_tabs
120
- formatter = Text::Format.new
121
- formatter.tabstop = @options[:expand_tabs]
122
-
123
- @left.map! { |line| formatter.expand(line.chomp) }
124
- @right.map! { |line| formatter.expand(line.chomp) }
125
- end
126
-
127
- @left.map! { |line| CGI.escapeHTML(line.chomp) }
128
- @right.map! { |line| CGI.escapeHTML(line.chomp) }
129
-
130
- # standard:disable Layout/HeredocIndentation
131
- @options[:output] << <<-OUTPUT
132
- <html>
133
- <head>
134
- <title>#{@options[:title]}</title>
135
- <style type="text/css">
136
- #{@options[:css]}
137
- </style>
138
- </head>
139
- <body>
140
- <h1>#{@options[:title]}</h1>
141
- <p>Legend: <span class="only_a">Only in Old</span>&nbsp;
142
- <span class="only_b">Only in New</span></p>
143
- <div class="diff">
144
- OUTPUT
145
- # standard:enable Layout/HeredocIndentation
146
-
147
- callbacks = Callbacks.new(@options[:output])
148
- Diff::LCS.traverse_sequences(@left, @right, callbacks)
149
-
150
- # standard:disable Layout/HeredocIndentation
151
- @options[:output] << <<-OUTPUT
152
- </div>
153
- </body>
154
- </html>
155
- OUTPUT
156
- # standard:enable Layout/HeredocIndentation
157
- end
158
- end
@@ -1,7 +0,0 @@
1
- *** spec/fixtures/aX 2020-06-23 11:15:32.000000000 -0400
2
- --- spec/fixtures/bXaX 2020-06-23 11:15:32.000000000 -0400
3
- ***************
4
- *** 1 ****
5
- ! aX
6
- --- 1 ----
7
- ! bXaX
@@ -1,5 +0,0 @@
1
- --- spec/fixtures/aX 2020-06-23 11:15:32.000000000 -0400
2
- +++ spec/fixtures/bXaX 2020-06-23 11:15:32.000000000 -0400
3
- @@ -1 +1 @@
4
- -aX
5
- +bXaX
@@ -1,3 +0,0 @@
1
- 3c
2
- "description": "lo"
3
- .
@@ -1,3 +0,0 @@
1
- c3
2
- "description": "lo"
3
- .
@@ -1,9 +0,0 @@
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
3
- @@ -1,4 +1,4 @@
4
- {
5
- "name": "x",
6
- - "description": "hi"
7
- + "description": "lo"
8
- }
9
-
@@ -1,7 +0,0 @@
1
- 14a
2
- recipe[o::new]
3
- recipe[p::new]
4
- recipe[q::new]
5
- recipe[r::new]
6
- .
7
- 2d
@@ -1,7 +0,0 @@
1
- d2
2
- a14
3
- recipe[o::new]
4
- recipe[p::new]
5
- recipe[q::new]
6
- recipe[r::new]
7
- .
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes