diff-lcs 1.1.3 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +1 -0
  3. data/Code-of-Conduct.md +74 -0
  4. data/Contributing.md +119 -0
  5. data/History.md +400 -0
  6. data/{License.rdoc → License.md} +6 -5
  7. data/Manifest.txt +36 -4
  8. data/README.rdoc +35 -23
  9. data/Rakefile +106 -11
  10. data/bin/htmldiff +7 -4
  11. data/bin/ldiff +4 -1
  12. data/docs/COPYING.txt +21 -22
  13. data/docs/artistic.txt +127 -0
  14. data/lib/diff/lcs/array.rb +1 -15
  15. data/lib/diff/lcs/backports.rb +9 -0
  16. data/lib/diff/lcs/block.rb +4 -18
  17. data/lib/diff/lcs/callbacks.rb +233 -230
  18. data/lib/diff/lcs/change.rb +114 -109
  19. data/lib/diff/lcs/htmldiff.rb +17 -18
  20. data/lib/diff/lcs/hunk.rb +232 -116
  21. data/lib/diff/lcs/internals.rb +308 -0
  22. data/lib/diff/lcs/ldiff.rb +138 -177
  23. data/lib/diff/lcs/string.rb +1 -15
  24. data/lib/diff/lcs.rb +597 -963
  25. data/lib/diff-lcs.rb +1 -3
  26. data/spec/change_spec.rb +89 -0
  27. data/spec/diff_spec.rb +32 -16
  28. data/spec/fixtures/aX +1 -0
  29. data/spec/fixtures/bXaX +1 -0
  30. data/spec/fixtures/ds1.csv +50 -0
  31. data/spec/fixtures/ds2.csv +51 -0
  32. data/spec/fixtures/ldiff/output.diff +4 -0
  33. data/spec/fixtures/ldiff/output.diff-c +7 -0
  34. data/spec/fixtures/ldiff/output.diff-e +3 -0
  35. data/spec/fixtures/ldiff/output.diff-f +3 -0
  36. data/spec/fixtures/ldiff/output.diff-u +5 -0
  37. data/spec/fixtures/ldiff/output.diff.chef +4 -0
  38. data/spec/fixtures/ldiff/output.diff.chef-c +15 -0
  39. data/spec/fixtures/ldiff/output.diff.chef-e +3 -0
  40. data/spec/fixtures/ldiff/output.diff.chef-f +3 -0
  41. data/spec/fixtures/ldiff/output.diff.chef-u +9 -0
  42. data/spec/fixtures/ldiff/output.diff.chef2 +7 -0
  43. data/spec/fixtures/ldiff/output.diff.chef2-c +20 -0
  44. data/spec/fixtures/ldiff/output.diff.chef2-d +7 -0
  45. data/spec/fixtures/ldiff/output.diff.chef2-e +7 -0
  46. data/spec/fixtures/ldiff/output.diff.chef2-f +7 -0
  47. data/spec/fixtures/ldiff/output.diff.chef2-u +16 -0
  48. data/spec/fixtures/new-chef +4 -0
  49. data/spec/fixtures/new-chef2 +17 -0
  50. data/spec/fixtures/old-chef +4 -0
  51. data/spec/fixtures/old-chef2 +14 -0
  52. data/spec/hunk_spec.rb +83 -0
  53. data/spec/issues_spec.rb +154 -0
  54. data/spec/lcs_spec.rb +36 -16
  55. data/spec/ldiff_spec.rb +87 -0
  56. data/spec/patch_spec.rb +198 -172
  57. data/spec/sdiff_spec.rb +99 -89
  58. data/spec/spec_helper.rb +149 -59
  59. data/spec/traverse_balanced_spec.rb +191 -167
  60. data/spec/traverse_sequences_spec.rb +105 -51
  61. metadata +218 -99
  62. data/.gemtest +0 -0
  63. data/History.rdoc +0 -54
  64. data/diff-lcs.gemspec +0 -51
  65. data/docs/artistic.html +0 -289
@@ -1,286 +1,310 @@
1
- # -*- ruby encoding: utf-8 -*-
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe "Diff::LCS.traverse_balanced" do
5
+ describe 'Diff::LCS.traverse_balanced' do
6
6
  include Diff::LCS::SpecHelper::Matchers
7
7
 
8
- shared_examples "with a #change callback" do |s1, s2, result|
9
- it "should traverse s1 -> s2 correctly" do
8
+ shared_examples 'with a #change callback' do |s1, s2, result|
9
+ it 'traverses s1 -> s2 correctly' do
10
10
  traversal = balanced_traversal(s1, s2, :balanced_callback)
11
- traversal.result.should == result
11
+ expect(traversal.result).to eq(result)
12
12
  end
13
13
 
14
- it "should traverse s2 -> s1 correctly" do
14
+ it 'traverses s2 -> s1 correctly' do
15
15
  traversal = balanced_traversal(s2, s1, :balanced_callback)
16
- traversal.result.should == balanced_reverse(result)
16
+ expect(traversal.result).to eq(balanced_reverse(result))
17
17
  end
18
18
  end
19
19
 
20
- shared_examples "without a #change callback" do |s1, s2, result|
21
- it "should traverse s1 -> s2 correctly" do
20
+ shared_examples 'without a #change callback' do |s1, s2, result|
21
+ it 'traverses s1 -> s2 correctly' do
22
22
  traversal = balanced_traversal(s1, s2, :balanced_callback_no_change)
23
- traversal.result.should == map_to_no_change(result)
23
+ expect(traversal.result).to eq(map_to_no_change(result))
24
24
  end
25
25
 
26
- it "should traverse s2 -> s1 correctly" do
26
+ it 'traverses s2 -> s1 correctly' do
27
27
  traversal = balanced_traversal(s2, s1, :balanced_callback_no_change)
28
- traversal.result.should == map_to_no_change(balanced_reverse(result))
28
+ expect(traversal.result).to eq(map_to_no_change(balanced_reverse(result)))
29
29
  end
30
30
  end
31
31
 
32
- describe "sequences %w(a b c) & %w(a x c)" do
32
+ describe "identical string sequences ('abc')" do
33
+ s1 = s2 = 'abc'
34
+
35
+ result = [
36
+ ['=', 0, 0],
37
+ ['=', 1, 1],
38
+ ['=', 2, 2]
39
+ ]
40
+
41
+ it_has_behavior 'with a #change callback', s1, s2, result
42
+ it_has_behavior 'without a #change callback', s1, s2, result
43
+ end
44
+
45
+ describe 'identical array sequences %w(a b c)' do
46
+ s1 = s2 = %w(a b c)
47
+
48
+ result = [
49
+ ['=', 0, 0],
50
+ ['=', 1, 1],
51
+ ['=', 2, 2]
52
+ ]
53
+
54
+ it_has_behavior 'with a #change callback', s1, s2, result
55
+ it_has_behavior 'without a #change callback', s1, s2, result
56
+ end
57
+
58
+ describe 'sequences %w(a b c) & %w(a x c)' do
33
59
  s1 = %w(a b c)
34
60
  s2 = %w(a x c)
35
61
 
36
62
  result = [
37
- [ '=', 0, 0 ],
38
- [ '!', 1, 1 ],
39
- [ '=', 2, 2 ]
63
+ ['=', 0, 0],
64
+ ['!', 1, 1],
65
+ ['=', 2, 2]
40
66
  ]
41
67
 
42
- it_has_behavior "with a #change callback", s1, s2, result
43
- it_has_behavior "without a #change callback", s1, s2, result
68
+ it_has_behavior 'with a #change callback', s1, s2, result
69
+ it_has_behavior 'without a #change callback', s1, s2, result
44
70
  end
45
71
 
46
- describe "sequences %w(a x y c) & %w(a v w c)" do
72
+ describe 'sequences %w(a x y c) & %w(a v w c)' do
47
73
  s1 = %w(a x y c)
48
74
  s2 = %w(a v w c)
49
75
 
50
76
  result = [
51
- [ '=', 0, 0 ],
52
- [ '!', 1, 1 ],
53
- [ '!', 2, 2 ],
54
- [ '=', 3, 3 ]
77
+ ['=', 0, 0],
78
+ ['!', 1, 1],
79
+ ['!', 2, 2],
80
+ ['=', 3, 3]
55
81
  ]
56
82
 
57
- it_has_behavior "with a #change callback", s1, s2, result
58
- it_has_behavior "without a #change callback", s1, s2, result
83
+ it_has_behavior 'with a #change callback', s1, s2, result
84
+ it_has_behavior 'without a #change callback', s1, s2, result
59
85
  end
60
86
 
61
- describe "sequences %w(x y c) & %w(v w c)" do
87
+ describe 'sequences %w(x y c) & %w(v w c)' do
62
88
  s1 = %w(x y c)
63
89
  s2 = %w(v w c)
64
90
  result = [
65
- [ '!', 0, 0 ],
66
- [ '!', 1, 1 ],
67
- [ '=', 2, 2 ]
91
+ ['!', 0, 0],
92
+ ['!', 1, 1],
93
+ ['=', 2, 2]
68
94
  ]
69
95
 
70
- it_has_behavior "with a #change callback", s1, s2, result
71
- it_has_behavior "without a #change callback", s1, s2, result
96
+ it_has_behavior 'with a #change callback', s1, s2, result
97
+ it_has_behavior 'without a #change callback', s1, s2, result
72
98
  end
73
99
 
74
- describe "sequences %w(a x y z) & %w(b v w)" do
100
+ describe 'sequences %w(a x y z) & %w(b v w)' do
75
101
  s1 = %w(a x y z)
76
102
  s2 = %w(b v w)
77
103
  result = [
78
- [ '!', 0, 0 ],
79
- [ '!', 1, 1 ],
80
- [ '!', 2, 2 ],
81
- [ '<', 3, 3 ]
104
+ ['!', 0, 0],
105
+ ['!', 1, 1],
106
+ ['!', 2, 2],
107
+ ['<', 3, 3]
82
108
  ]
83
109
 
84
- it_has_behavior "with a #change callback", s1, s2, result
85
- it_has_behavior "without a #change callback", s1, s2, result
110
+ it_has_behavior 'with a #change callback', s1, s2, result
111
+ it_has_behavior 'without a #change callback', s1, s2, result
86
112
  end
87
113
 
88
- describe "sequences %w(a z) & %w(a)" do
114
+ describe 'sequences %w(a z) & %w(a)' do
89
115
  s1 = %w(a z)
90
116
  s2 = %w(a)
91
117
  result = [
92
- [ '=', 0, 0 ],
93
- [ '<', 1, 1 ]
118
+ ['=', 0, 0],
119
+ ['<', 1, 1]
94
120
  ]
95
121
 
96
- it_has_behavior "with a #change callback", s1, s2, result
97
- it_has_behavior "without a #change callback", s1, s2, result
122
+ it_has_behavior 'with a #change callback', s1, s2, result
123
+ it_has_behavior 'without a #change callback', s1, s2, result
98
124
  end
99
125
 
100
- describe "sequences %w(z a) & %w(a)" do
126
+ describe 'sequences %w(z a) & %w(a)' do
101
127
  s1 = %w(z a)
102
128
  s2 = %w(a)
103
129
  result = [
104
- [ '<', 0, 0 ],
105
- [ '=', 1, 0 ]
130
+ ['<', 0, 0],
131
+ ['=', 1, 0]
106
132
  ]
107
133
 
108
- it_has_behavior "with a #change callback", s1, s2, result
109
- it_has_behavior "without a #change callback", s1, s2, result
134
+ it_has_behavior 'with a #change callback', s1, s2, result
135
+ it_has_behavior 'without a #change callback', s1, s2, result
110
136
  end
111
137
 
112
- describe "sequences %w(a b c) & %w(x y z)" do
138
+ describe 'sequences %w(a b c) & %w(x y z)' do
113
139
  s1 = %w(a b c)
114
140
  s2 = %w(x y z)
115
141
  result = [
116
- [ '!', 0, 0 ],
117
- [ '!', 1, 1 ],
118
- [ '!', 2, 2 ]
142
+ ['!', 0, 0],
143
+ ['!', 1, 1],
144
+ ['!', 2, 2]
119
145
  ]
120
146
 
121
- it_has_behavior "with a #change callback", s1, s2, result
122
- it_has_behavior "without a #change callback", s1, s2, result
147
+ it_has_behavior 'with a #change callback', s1, s2, result
148
+ it_has_behavior 'without a #change callback', s1, s2, result
123
149
  end
124
150
 
125
- describe "sequences %w(abcd efgh ijkl mnoopqrstuvwxyz) & []" do
151
+ describe 'sequences %w(abcd efgh ijkl mnoopqrstuvwxyz) & []' do
126
152
  s1 = %w(abcd efgh ijkl mnopqrstuvwxyz)
127
153
  s2 = []
128
154
  result = [
129
- [ '<', 0, 0 ],
130
- [ '<', 1, 0 ],
131
- [ '<', 2, 0 ],
132
- [ '<', 3, 0 ]
155
+ ['<', 0, 0],
156
+ ['<', 1, 0],
157
+ ['<', 2, 0],
158
+ ['<', 3, 0]
133
159
  ]
134
160
 
135
- it_has_behavior "with a #change callback", s1, s2, result
136
- it_has_behavior "without a #change callback", s1, s2, result
161
+ it_has_behavior 'with a #change callback', s1, s2, result
162
+ it_has_behavior 'without a #change callback', s1, s2, result
137
163
  end
138
164
 
139
- describe "strings %Q(a b c) & %Q(a x c)" do
140
- s1 = %Q(a b c)
141
- s2 = %Q(a x c)
165
+ describe 'strings %q(a b c) & %q(a x c)' do
166
+ s1 = 'a b c'
167
+ s2 = 'a x c'
142
168
 
143
169
  result = [
144
- [ '=', 0, 0 ],
145
- [ '=', 1, 1 ],
146
- [ '!', 2, 2 ],
147
- [ '=', 3, 3 ],
148
- [ '=', 4, 4 ]
170
+ ['=', 0, 0],
171
+ ['=', 1, 1],
172
+ ['!', 2, 2],
173
+ ['=', 3, 3],
174
+ ['=', 4, 4]
149
175
  ]
150
176
 
151
- it_has_behavior "with a #change callback", s1, s2, result
152
- it_has_behavior "without a #change callback", s1, s2, result
177
+ it_has_behavior 'with a #change callback', s1, s2, result
178
+ it_has_behavior 'without a #change callback', s1, s2, result
153
179
  end
154
180
 
155
- describe "strings %Q(a x y c) & %Q(a v w c)" do
156
- s1 = %Q(a x y c)
157
- s2 = %Q(a v w c)
181
+ describe 'strings %q(a x y c) & %q(a v w c)' do
182
+ s1 = 'a x y c'
183
+ s2 = 'a v w c'
158
184
 
159
185
  result = [
160
- [ '=', 0, 0 ],
161
- [ '=', 1, 1 ],
162
- [ '!', 2, 2 ],
163
- [ '=', 3, 3 ],
164
- [ '!', 4, 4 ],
165
- [ '=', 5, 5 ],
166
- [ '=', 6, 6 ]
186
+ ['=', 0, 0],
187
+ ['=', 1, 1],
188
+ ['!', 2, 2],
189
+ ['=', 3, 3],
190
+ ['!', 4, 4],
191
+ ['=', 5, 5],
192
+ ['=', 6, 6]
167
193
  ]
168
194
 
169
- it_has_behavior "with a #change callback", s1, s2, result
170
- it_has_behavior "without a #change callback", s1, s2, result
195
+ it_has_behavior 'with a #change callback', s1, s2, result
196
+ it_has_behavior 'without a #change callback', s1, s2, result
171
197
  end
172
198
 
173
- describe "strings %Q(x y c) & %Q(v w c)" do
174
- s1 = %Q(x y c)
175
- s2 = %Q(v w c)
199
+ describe 'strings %q(x y c) & %q(v w c)' do
200
+ s1 = 'x y c'
201
+ s2 = 'v w c'
176
202
  result = [
177
- [ '!', 0, 0 ],
178
- [ '=', 1, 1 ],
179
- [ '!', 2, 2 ],
180
- [ '=', 3, 3 ],
181
- [ '=', 4, 4 ]
203
+ ['!', 0, 0],
204
+ ['=', 1, 1],
205
+ ['!', 2, 2],
206
+ ['=', 3, 3],
207
+ ['=', 4, 4]
182
208
  ]
183
209
 
184
- it_has_behavior "with a #change callback", s1, s2, result
185
- it_has_behavior "without a #change callback", s1, s2, result
210
+ it_has_behavior 'with a #change callback', s1, s2, result
211
+ it_has_behavior 'without a #change callback', s1, s2, result
186
212
  end
187
213
 
188
- describe "strings %Q(a x y z) & %Q(b v w)" do
189
- s1 = %Q(a x y z)
190
- s2 = %Q(b v w)
214
+ describe 'strings %q(a x y z) & %q(b v w)' do
215
+ s1 = 'a x y z'
216
+ s2 = 'b v w'
191
217
  result = [
192
- [ '!', 0, 0 ],
193
- [ '=', 1, 1 ],
194
- [ '!', 2, 2 ],
195
- [ '=', 3, 3 ],
196
- [ '!', 4, 4 ],
197
- [ '<', 5, 5 ],
198
- [ '<', 6, 5 ]
218
+ ['!', 0, 0],
219
+ ['=', 1, 1],
220
+ ['!', 2, 2],
221
+ ['=', 3, 3],
222
+ ['!', 4, 4],
223
+ ['<', 5, 5],
224
+ ['<', 6, 5]
199
225
  ]
200
226
 
201
- it_has_behavior "with a #change callback", s1, s2, result
202
- it_has_behavior "without a #change callback", s1, s2, result
227
+ it_has_behavior 'with a #change callback', s1, s2, result
228
+ it_has_behavior 'without a #change callback', s1, s2, result
203
229
  end
204
230
 
205
- describe "strings %Q(a z) & %Q(a)" do
206
- s1 = %Q(a z)
207
- s2 = %Q(a)
231
+ describe 'strings %q(a z) & %q(a)' do
232
+ s1 = 'a z'
233
+ s2 = 'a'
208
234
  result = [
209
- [ '=', 0, 0 ],
210
- [ '<', 1, 1 ],
211
- [ '<', 2, 1 ]
235
+ ['=', 0, 0],
236
+ ['<', 1, 1],
237
+ ['<', 2, 1]
212
238
  ]
213
239
 
214
- it_has_behavior "with a #change callback", s1, s2, result
215
- it_has_behavior "without a #change callback", s1, s2, result
240
+ it_has_behavior 'with a #change callback', s1, s2, result
241
+ it_has_behavior 'without a #change callback', s1, s2, result
216
242
  end
217
243
 
218
- describe "strings %Q(z a) & %Q(a)" do
219
- s1 = %Q(z a)
220
- s2 = %Q(a)
244
+ describe 'strings %q(z a) & %q(a)' do
245
+ s1 = 'z a'
246
+ s2 = 'a'
221
247
  result = [
222
- [ '<', 0, 0 ],
223
- [ '<', 1, 0 ],
224
- [ '=', 2, 0 ]
248
+ ['<', 0, 0],
249
+ ['<', 1, 0],
250
+ ['=', 2, 0]
225
251
  ]
226
252
 
227
- it_has_behavior "with a #change callback", s1, s2, result
228
- it_has_behavior "without a #change callback", s1, s2, result
253
+ it_has_behavior 'with a #change callback', s1, s2, result
254
+ it_has_behavior 'without a #change callback', s1, s2, result
229
255
  end
230
256
 
231
- describe "strings %Q(a b c) & %Q(x y z)" do
232
- s1 = %Q(a b c)
233
- s2 = %Q(x y z)
257
+ describe 'strings %q(a b c) & %q(x y z)' do
258
+ s1 = 'a b c'
259
+ s2 = 'x y z'
234
260
  result = [
235
- [ '!', 0, 0 ],
236
- [ '=', 1, 1 ],
237
- [ '!', 2, 2 ],
238
- [ '=', 3, 3 ],
239
- [ '!', 4, 4 ]
261
+ ['!', 0, 0],
262
+ ['=', 1, 1],
263
+ ['!', 2, 2],
264
+ ['=', 3, 3],
265
+ ['!', 4, 4]
240
266
  ]
241
267
 
242
- it_has_behavior "with a #change callback", s1, s2, result
243
- it_has_behavior "without a #change callback", s1, s2, result
268
+ it_has_behavior 'with a #change callback', s1, s2, result
269
+ it_has_behavior 'without a #change callback', s1, s2, result
244
270
  end
245
271
 
246
- describe "strings %Q(abcd efgh ijkl mnopqrstuvwxyz) & %Q()" do
247
- s1 = %Q(abcd efgh ijkl mnopqrstuvwxyz)
248
- s2 = ""
272
+ describe 'strings %q(abcd efgh ijkl mnopqrstuvwxyz) & %q()' do
273
+ s1 = 'abcd efgh ijkl mnopqrstuvwxyz'
274
+ s2 = ''
249
275
  result = [
250
- [ '<', 0, 0 ],
251
- [ '<', 1, 0 ],
252
- [ '<', 2, 0 ],
253
- [ '<', 3, 0 ],
254
- [ '<', 4, 0 ],
255
- [ '<', 5, 0 ],
256
- [ '<', 6, 0 ],
257
- [ '<', 7, 0 ],
258
- [ '<', 8, 0 ],
259
- [ '<', 9, 0 ],
260
- [ '<', 10, 0 ],
261
- [ '<', 11, 0 ],
262
- [ '<', 12, 0 ],
263
- [ '<', 13, 0 ],
264
- [ '<', 14, 0 ],
265
- [ '<', 15, 0 ],
266
- [ '<', 16, 0 ],
267
- [ '<', 17, 0 ],
268
- [ '<', 18, 0 ],
269
- [ '<', 19, 0 ],
270
- [ '<', 20, 0 ],
271
- [ '<', 21, 0 ],
272
- [ '<', 22, 0 ],
273
- [ '<', 23, 0 ],
274
- [ '<', 24, 0 ],
275
- [ '<', 25, 0 ],
276
- [ '<', 26, 0 ],
277
- [ '<', 27, 0 ],
278
- [ '<', 28, 0 ],
276
+ ['<', 0, 0],
277
+ ['<', 1, 0],
278
+ ['<', 2, 0],
279
+ ['<', 3, 0],
280
+ ['<', 4, 0],
281
+ ['<', 5, 0],
282
+ ['<', 6, 0],
283
+ ['<', 7, 0],
284
+ ['<', 8, 0],
285
+ ['<', 9, 0],
286
+ ['<', 10, 0],
287
+ ['<', 11, 0],
288
+ ['<', 12, 0],
289
+ ['<', 13, 0],
290
+ ['<', 14, 0],
291
+ ['<', 15, 0],
292
+ ['<', 16, 0],
293
+ ['<', 17, 0],
294
+ ['<', 18, 0],
295
+ ['<', 19, 0],
296
+ ['<', 20, 0],
297
+ ['<', 21, 0],
298
+ ['<', 22, 0],
299
+ ['<', 23, 0],
300
+ ['<', 24, 0],
301
+ ['<', 25, 0],
302
+ ['<', 26, 0],
303
+ ['<', 27, 0],
304
+ ['<', 28, 0]
279
305
  ]
280
306
 
281
- it_has_behavior "with a #change callback", s1, s2, result
282
- it_has_behavior "without a #change callback", s1, s2, result
307
+ it_has_behavior 'with a #change callback', s1, s2, result
308
+ it_has_behavior 'without a #change callback', s1, s2, result
283
309
  end
284
310
  end
285
-
286
- # vim: ft=ruby