diff-lcs 1.3 → 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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +518 -0
- data/CODE_OF_CONDUCT.md +128 -0
- data/CONTRIBUTING.md +71 -0
- data/CONTRIBUTORS.md +49 -0
- data/{License.md → LICENCE.md} +21 -20
- data/Manifest.txt +84 -6
- data/README.md +92 -0
- data/Rakefile +104 -46
- data/SECURITY.md +41 -0
- data/bin/htmldiff +9 -6
- data/bin/ldiff +4 -1
- data/docs/artistic.txt +1 -1
- data/lib/diff/lcs/array.rb +2 -2
- data/lib/diff/lcs/backports.rb +13 -0
- data/lib/diff/lcs/block.rb +5 -5
- data/lib/diff/lcs/callbacks.rb +22 -17
- data/lib/diff/lcs/change.rb +44 -51
- data/lib/diff/lcs/htmldiff.rb +25 -14
- data/lib/diff/lcs/hunk.rb +174 -71
- data/lib/diff/lcs/internals.rb +57 -56
- data/lib/diff/lcs/ldiff.rb +101 -79
- data/lib/diff/lcs/string.rb +1 -1
- data/lib/diff/lcs/version.rb +7 -0
- data/lib/diff/lcs.rb +229 -212
- data/lib/diff-lcs.rb +2 -2
- data/mise.toml +5 -0
- data/spec/change_spec.rb +58 -34
- data/spec/diff_spec.rb +13 -9
- data/spec/fixtures/123_x +2 -0
- data/spec/fixtures/456_x +2 -0
- data/spec/fixtures/aX +1 -0
- data/spec/fixtures/bXaX +1 -0
- data/spec/fixtures/empty +0 -0
- data/spec/fixtures/file1.bin +0 -0
- data/spec/fixtures/file2.bin +0 -0
- data/spec/fixtures/four_lines +4 -0
- data/spec/fixtures/four_lines_with_missing_new_line +4 -0
- data/spec/fixtures/ldiff/diff.missing_new_line1-e +1 -0
- data/spec/fixtures/ldiff/diff.missing_new_line1-f +1 -0
- data/spec/fixtures/ldiff/diff.missing_new_line2-e +1 -0
- data/spec/fixtures/ldiff/diff.missing_new_line2-f +1 -0
- data/spec/fixtures/ldiff/error.diff.chef-e +2 -0
- data/spec/fixtures/ldiff/error.diff.chef-f +2 -0
- data/spec/fixtures/ldiff/error.diff.missing_new_line1-e +1 -0
- data/spec/fixtures/ldiff/error.diff.missing_new_line1-f +1 -0
- data/spec/fixtures/ldiff/error.diff.missing_new_line2-e +1 -0
- data/spec/fixtures/ldiff/error.diff.missing_new_line2-f +1 -0
- data/spec/fixtures/ldiff/output.diff +4 -0
- data/spec/fixtures/ldiff/output.diff-c +7 -0
- data/spec/fixtures/ldiff/output.diff-e +3 -0
- data/spec/fixtures/ldiff/output.diff-f +3 -0
- data/spec/fixtures/ldiff/output.diff-u +5 -0
- data/spec/fixtures/ldiff/output.diff.bin1 +0 -0
- data/spec/fixtures/ldiff/output.diff.bin1-c +0 -0
- data/spec/fixtures/ldiff/output.diff.bin1-e +0 -0
- data/spec/fixtures/ldiff/output.diff.bin1-f +0 -0
- data/spec/fixtures/ldiff/output.diff.bin1-u +0 -0
- data/spec/fixtures/ldiff/output.diff.bin2 +1 -0
- data/spec/fixtures/ldiff/output.diff.bin2-c +1 -0
- data/spec/fixtures/ldiff/output.diff.bin2-e +1 -0
- data/spec/fixtures/ldiff/output.diff.bin2-f +1 -0
- data/spec/fixtures/ldiff/output.diff.bin2-u +1 -0
- data/spec/fixtures/ldiff/output.diff.chef +4 -0
- data/spec/fixtures/ldiff/output.diff.chef-c +15 -0
- data/spec/fixtures/ldiff/output.diff.chef-e +3 -0
- data/spec/fixtures/ldiff/output.diff.chef-f +3 -0
- data/spec/fixtures/ldiff/output.diff.chef-u +9 -0
- data/spec/fixtures/ldiff/output.diff.chef2 +7 -0
- data/spec/fixtures/ldiff/output.diff.chef2-c +20 -0
- data/spec/fixtures/ldiff/output.diff.chef2-d +7 -0
- data/spec/fixtures/ldiff/output.diff.chef2-e +7 -0
- data/spec/fixtures/ldiff/output.diff.chef2-f +7 -0
- data/spec/fixtures/ldiff/output.diff.chef2-u +16 -0
- data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines +5 -0
- data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-c +9 -0
- data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-e +6 -0
- data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-f +6 -0
- data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-u +7 -0
- data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty +5 -0
- data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-c +9 -0
- data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-e +1 -0
- data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-f +1 -0
- data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-u +7 -0
- data/spec/fixtures/ldiff/output.diff.issue95_trailing_context +4 -0
- data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-c +9 -0
- data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-e +3 -0
- data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-f +3 -0
- data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-u +6 -0
- data/spec/fixtures/ldiff/output.diff.missing_new_line1 +5 -0
- data/spec/fixtures/ldiff/output.diff.missing_new_line1-c +14 -0
- data/spec/fixtures/ldiff/output.diff.missing_new_line1-e +0 -0
- data/spec/fixtures/ldiff/output.diff.missing_new_line1-f +0 -0
- data/spec/fixtures/ldiff/output.diff.missing_new_line1-u +9 -0
- data/spec/fixtures/ldiff/output.diff.missing_new_line2 +5 -0
- data/spec/fixtures/ldiff/output.diff.missing_new_line2-c +14 -0
- data/spec/fixtures/ldiff/output.diff.missing_new_line2-e +0 -0
- data/spec/fixtures/ldiff/output.diff.missing_new_line2-f +0 -0
- data/spec/fixtures/ldiff/output.diff.missing_new_line2-u +9 -0
- data/spec/fixtures/new-chef +4 -0
- data/spec/fixtures/new-chef2 +17 -0
- data/spec/fixtures/old-chef +4 -0
- data/spec/fixtures/old-chef2 +14 -0
- data/spec/hunk_spec.rb +49 -38
- data/spec/issues_spec.rb +132 -21
- data/spec/lcs_spec.rb +3 -3
- data/spec/ldiff_spec.rb +83 -30
- data/spec/patch_spec.rb +14 -20
- data/spec/sdiff_spec.rb +83 -81
- data/spec/spec_helper.rb +220 -165
- data/spec/traverse_balanced_spec.rb +138 -136
- data/spec/traverse_sequences_spec.rb +7 -9
- metadata +127 -77
- data/Code-of-Conduct.md +0 -74
- data/Contributing.md +0 -83
- data/History.md +0 -220
- data/README.rdoc +0 -84
- data/autotest/discover.rb +0 -1
data/spec/spec_helper.rb
CHANGED
|
@@ -1,46 +1,70 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require 'psych'
|
|
3
|
+
require "rubygems"
|
|
4
|
+
require "pathname"
|
|
6
5
|
|
|
7
|
-
if
|
|
8
|
-
require 'coveralls'
|
|
9
|
-
Coveralls.wear!
|
|
10
|
-
elsif ENV['COVERAGE']
|
|
11
|
-
require 'simplecov'
|
|
6
|
+
require "psych" if RUBY_VERSION >= "1.9"
|
|
12
7
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
rescue LoadError
|
|
17
|
-
nil
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
formatters = [ SimpleCov::Formatter::HTMLFormatter ]
|
|
8
|
+
if ENV["COVERAGE"]
|
|
9
|
+
require "simplecov"
|
|
10
|
+
require "simplecov-lcov"
|
|
21
11
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
formatters << SimpleCov::Formatter::VimFormatter
|
|
27
|
-
}
|
|
28
|
-
require_do('simplecov-sublime-ruby-coverage') {
|
|
29
|
-
formatters << SimpleCov::Formatter::SublimeRubyCoverageFormatter
|
|
30
|
-
}
|
|
12
|
+
SimpleCov::Formatter::LcovFormatter.config do |config|
|
|
13
|
+
config.report_with_single_file = true
|
|
14
|
+
config.lcov_file_name = "lcov.info"
|
|
15
|
+
end
|
|
31
16
|
|
|
32
|
-
SimpleCov.start do
|
|
33
|
-
|
|
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
|
+
])
|
|
34
25
|
end
|
|
35
26
|
end
|
|
36
27
|
|
|
37
|
-
file
|
|
38
|
-
path
|
|
28
|
+
file = Pathname.new(__FILE__).expand_path
|
|
29
|
+
path = file.parent
|
|
39
30
|
parent = path.parent
|
|
40
31
|
|
|
41
|
-
$:.unshift parent.join(
|
|
32
|
+
$:.unshift parent.join("lib")
|
|
33
|
+
|
|
34
|
+
module CaptureSubprocessIO
|
|
35
|
+
def _synchronize
|
|
36
|
+
yield
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def capture_subprocess_io
|
|
40
|
+
_synchronize { _capture_subprocess_io { yield } }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def _capture_subprocess_io
|
|
44
|
+
require "tempfile"
|
|
45
|
+
|
|
46
|
+
captured_stdout, captured_stderr = Tempfile.new("out"), Tempfile.new("err")
|
|
42
47
|
|
|
43
|
-
|
|
48
|
+
orig_stdout, orig_stderr = $stdout.dup, $stderr.dup
|
|
49
|
+
$stdout.reopen captured_stdout
|
|
50
|
+
$stderr.reopen captured_stderr
|
|
51
|
+
|
|
52
|
+
yield
|
|
53
|
+
|
|
54
|
+
$stdout.rewind
|
|
55
|
+
$stderr.rewind
|
|
56
|
+
|
|
57
|
+
[captured_stdout.read, captured_stderr.read]
|
|
58
|
+
ensure
|
|
59
|
+
captured_stdout.unlink
|
|
60
|
+
captured_stderr.unlink
|
|
61
|
+
$stdout.reopen orig_stdout
|
|
62
|
+
$stderr.reopen orig_stderr
|
|
63
|
+
end
|
|
64
|
+
private :_capture_subprocess_io
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
require "diff-lcs"
|
|
44
68
|
|
|
45
69
|
module Diff::LCS::SpecHelper
|
|
46
70
|
def hello
|
|
@@ -48,88 +72,109 @@ module Diff::LCS::SpecHelper
|
|
|
48
72
|
end
|
|
49
73
|
|
|
50
74
|
def hello_ary
|
|
51
|
-
%
|
|
75
|
+
%w[h e l l o]
|
|
52
76
|
end
|
|
53
77
|
|
|
54
78
|
def seq1
|
|
55
|
-
%w
|
|
79
|
+
%w[a b c e h j l m n p]
|
|
56
80
|
end
|
|
57
81
|
|
|
58
82
|
def skipped_seq1
|
|
59
|
-
%w
|
|
83
|
+
%w[a h n p]
|
|
60
84
|
end
|
|
61
85
|
|
|
62
86
|
def seq2
|
|
63
|
-
%w
|
|
87
|
+
%w[b c d e f j k l m r s t]
|
|
64
88
|
end
|
|
65
89
|
|
|
66
90
|
def skipped_seq2
|
|
67
|
-
%w
|
|
91
|
+
%w[d f k r s t]
|
|
68
92
|
end
|
|
69
93
|
|
|
70
94
|
def word_sequence
|
|
71
|
-
%w
|
|
95
|
+
%w[abcd efgh ijkl mnopqrstuvwxyz]
|
|
72
96
|
end
|
|
73
97
|
|
|
74
98
|
def correct_lcs
|
|
75
|
-
%w
|
|
99
|
+
%w[b c e j l m]
|
|
76
100
|
end
|
|
77
101
|
|
|
102
|
+
# standard:disable Layout/ExtraSpacing
|
|
78
103
|
def correct_forward_diff
|
|
79
104
|
[
|
|
80
|
-
[
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
[
|
|
88
|
-
[
|
|
89
|
-
|
|
105
|
+
[
|
|
106
|
+
["-", 0, "a"]
|
|
107
|
+
],
|
|
108
|
+
[
|
|
109
|
+
["+", 2, "d"]
|
|
110
|
+
],
|
|
111
|
+
[
|
|
112
|
+
["-", 4, "h"],
|
|
113
|
+
["+", 4, "f"]
|
|
114
|
+
],
|
|
115
|
+
[
|
|
116
|
+
["+", 6, "k"]
|
|
117
|
+
],
|
|
118
|
+
[
|
|
119
|
+
["-", 8, "n"],
|
|
120
|
+
["+", 9, "r"],
|
|
121
|
+
["-", 9, "p"],
|
|
122
|
+
["+", 10, "s"],
|
|
123
|
+
["+", 11, "t"]
|
|
124
|
+
]
|
|
90
125
|
]
|
|
91
126
|
end
|
|
92
127
|
|
|
93
128
|
def correct_backward_diff
|
|
94
129
|
[
|
|
95
|
-
[ [ '+', 0, 'a' ] ],
|
|
96
|
-
[ [ '-', 2, 'd' ] ],
|
|
97
|
-
[ [ '-', 4, 'f' ],
|
|
98
|
-
[ '+', 4, 'h' ] ],
|
|
99
|
-
[ [ '-', 6, 'k' ] ],
|
|
100
130
|
[
|
|
101
|
-
[
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
[
|
|
105
|
-
|
|
131
|
+
["+", 0, "a"]
|
|
132
|
+
],
|
|
133
|
+
[
|
|
134
|
+
["-", 2, "d"]
|
|
135
|
+
],
|
|
136
|
+
[
|
|
137
|
+
["-", 4, "f"],
|
|
138
|
+
["+", 4, "h"]
|
|
139
|
+
],
|
|
140
|
+
[
|
|
141
|
+
["-", 6, "k"]
|
|
142
|
+
],
|
|
143
|
+
[
|
|
144
|
+
["-", 9, "r"],
|
|
145
|
+
["+", 8, "n"],
|
|
146
|
+
["-", 10, "s"],
|
|
147
|
+
["+", 9, "p"],
|
|
148
|
+
["-", 11, "t"]
|
|
149
|
+
]
|
|
106
150
|
]
|
|
107
151
|
end
|
|
108
152
|
|
|
109
153
|
def correct_forward_sdiff
|
|
110
154
|
[
|
|
111
|
-
[
|
|
112
|
-
[
|
|
113
|
-
[
|
|
114
|
-
[
|
|
115
|
-
[
|
|
116
|
-
[
|
|
117
|
-
[
|
|
118
|
-
[
|
|
119
|
-
[
|
|
120
|
-
[
|
|
121
|
-
[
|
|
122
|
-
[
|
|
123
|
-
[
|
|
155
|
+
["-", [0, "a"], [0, nil]],
|
|
156
|
+
["=", [1, "b"], [0, "b"]],
|
|
157
|
+
["=", [2, "c"], [1, "c"]],
|
|
158
|
+
["+", [3, nil], [2, "d"]],
|
|
159
|
+
["=", [3, "e"], [3, "e"]],
|
|
160
|
+
["!", [4, "h"], [4, "f"]],
|
|
161
|
+
["=", [5, "j"], [5, "j"]],
|
|
162
|
+
["+", [6, nil], [6, "k"]],
|
|
163
|
+
["=", [6, "l"], [7, "l"]],
|
|
164
|
+
["=", [7, "m"], [8, "m"]],
|
|
165
|
+
["!", [8, "n"], [9, "r"]],
|
|
166
|
+
["!", [9, "p"], [10, "s"]],
|
|
167
|
+
["+", [10, nil], [11, "t"]]
|
|
124
168
|
]
|
|
125
169
|
end
|
|
170
|
+
# standard:enable Layout/ExtraSpacing
|
|
126
171
|
|
|
127
172
|
def reverse_sdiff(forward_sdiff)
|
|
128
173
|
forward_sdiff.map { |line|
|
|
129
174
|
line[1], line[2] = line[2], line[1]
|
|
130
175
|
case line[0]
|
|
131
|
-
when
|
|
132
|
-
when
|
|
176
|
+
when "-" then line[0] = "+"
|
|
177
|
+
when "+" then line[0] = "-"
|
|
133
178
|
end
|
|
134
179
|
line
|
|
135
180
|
}
|
|
@@ -144,13 +189,13 @@ module Diff::LCS::SpecHelper
|
|
|
144
189
|
end
|
|
145
190
|
|
|
146
191
|
def format_diffs(diffs)
|
|
147
|
-
diffs.map
|
|
148
|
-
if e.
|
|
192
|
+
diffs.map { |e|
|
|
193
|
+
if e.is_a?(Array)
|
|
149
194
|
e.map { |f| f.to_a.join }.join(", ")
|
|
150
195
|
else
|
|
151
196
|
e.to_a.join
|
|
152
197
|
end
|
|
153
|
-
|
|
198
|
+
}.join("\n")
|
|
154
199
|
end
|
|
155
200
|
|
|
156
201
|
def map_diffs(diffs, klass = Diff::LCS::ContextChange)
|
|
@@ -171,124 +216,134 @@ module Diff::LCS::SpecHelper
|
|
|
171
216
|
|
|
172
217
|
def balanced_reverse(change_result)
|
|
173
218
|
new_result = []
|
|
174
|
-
change_result.each
|
|
175
|
-
line = [
|
|
219
|
+
change_result.each do |line|
|
|
220
|
+
line = [line[0], line[2], line[1]]
|
|
176
221
|
case line[0]
|
|
177
|
-
when
|
|
178
|
-
line[0] =
|
|
179
|
-
when
|
|
180
|
-
line[0] =
|
|
222
|
+
when "<"
|
|
223
|
+
line[0] = ">"
|
|
224
|
+
when ">"
|
|
225
|
+
line[0] = "<"
|
|
181
226
|
end
|
|
182
227
|
new_result << line
|
|
183
|
-
|
|
184
|
-
new_result.sort_by { |line| [
|
|
228
|
+
end
|
|
229
|
+
new_result.sort_by { |line| [line[1], line[2]] }
|
|
185
230
|
end
|
|
186
231
|
|
|
187
232
|
def map_to_no_change(change_result)
|
|
188
233
|
new_result = []
|
|
189
|
-
change_result.each
|
|
234
|
+
change_result.each do |line|
|
|
190
235
|
case line[0]
|
|
191
|
-
when
|
|
192
|
-
new_result << [
|
|
193
|
-
new_result << [
|
|
236
|
+
when "!"
|
|
237
|
+
new_result << ["<", line[1], line[2]]
|
|
238
|
+
new_result << [">", line[1] + 1, line[2]]
|
|
194
239
|
else
|
|
195
240
|
new_result << line
|
|
196
241
|
end
|
|
197
|
-
|
|
242
|
+
end
|
|
198
243
|
new_result
|
|
199
244
|
end
|
|
200
245
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
attr_reader :matched_b
|
|
206
|
-
attr_reader :discards_a
|
|
207
|
-
attr_reader :discards_b
|
|
208
|
-
attr_reader :done_a
|
|
209
|
-
attr_reader :done_b
|
|
210
|
-
|
|
211
|
-
def reset
|
|
212
|
-
@matched_a = []
|
|
213
|
-
@matched_b = []
|
|
214
|
-
@discards_a = []
|
|
215
|
-
@discards_b = []
|
|
216
|
-
@done_a = []
|
|
217
|
-
@done_b = []
|
|
218
|
-
end
|
|
246
|
+
class SimpleCallback
|
|
247
|
+
def initialize
|
|
248
|
+
reset
|
|
249
|
+
end
|
|
219
250
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
251
|
+
attr_reader :matched_a
|
|
252
|
+
attr_reader :matched_b
|
|
253
|
+
attr_reader :discards_a
|
|
254
|
+
attr_reader :discards_b
|
|
255
|
+
attr_reader :done_a
|
|
256
|
+
attr_reader :done_b
|
|
257
|
+
|
|
258
|
+
def reset
|
|
259
|
+
@matched_a = []
|
|
260
|
+
@matched_b = []
|
|
261
|
+
@discards_a = []
|
|
262
|
+
@discards_b = []
|
|
263
|
+
@done_a = []
|
|
264
|
+
@done_b = []
|
|
265
|
+
self
|
|
266
|
+
end
|
|
224
267
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
268
|
+
def match(event)
|
|
269
|
+
@matched_a << event.old_element
|
|
270
|
+
@matched_b << event.new_element
|
|
271
|
+
end
|
|
228
272
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
273
|
+
def discard_b(event)
|
|
274
|
+
@discards_b << event.new_element
|
|
275
|
+
end
|
|
232
276
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
end
|
|
277
|
+
def discard_a(event)
|
|
278
|
+
@discards_a << event.old_element
|
|
279
|
+
end
|
|
237
280
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
281
|
+
def finished_a(event)
|
|
282
|
+
@done_a << [
|
|
283
|
+
event.old_element, event.old_position,
|
|
284
|
+
event.new_element, event.new_position
|
|
285
|
+
]
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
def finished_b(event)
|
|
289
|
+
@done_b << [
|
|
290
|
+
event.old_element, event.old_position,
|
|
291
|
+
event.new_element, event.new_position
|
|
292
|
+
]
|
|
243
293
|
end
|
|
244
|
-
|
|
245
|
-
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
def simple_callback
|
|
297
|
+
SimpleCallback.new
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
class SimpleCallbackNoFinishers < SimpleCallback
|
|
301
|
+
undef :finished_a
|
|
302
|
+
undef :finished_b
|
|
246
303
|
end
|
|
247
304
|
|
|
248
305
|
def simple_callback_no_finishers
|
|
249
|
-
|
|
250
|
-
class << simple
|
|
251
|
-
undef :finished_a
|
|
252
|
-
undef :finished_b
|
|
253
|
-
end
|
|
254
|
-
simple
|
|
306
|
+
SimpleCallbackNoFinishers.new
|
|
255
307
|
end
|
|
256
308
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
309
|
+
class BalancedCallback
|
|
310
|
+
def initialize
|
|
311
|
+
reset
|
|
312
|
+
end
|
|
261
313
|
|
|
262
|
-
|
|
263
|
-
@result = []
|
|
264
|
-
end
|
|
314
|
+
attr_reader :result
|
|
265
315
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
316
|
+
def reset
|
|
317
|
+
@result = []
|
|
318
|
+
end
|
|
269
319
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
320
|
+
def match(event)
|
|
321
|
+
@result << ["=", event.old_position, event.new_position]
|
|
322
|
+
end
|
|
273
323
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
324
|
+
def discard_a(event)
|
|
325
|
+
@result << ["<", event.old_position, event.new_position]
|
|
326
|
+
end
|
|
277
327
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
end
|
|
328
|
+
def discard_b(event)
|
|
329
|
+
@result << [">", event.old_position, event.new_position]
|
|
281
330
|
end
|
|
282
|
-
|
|
283
|
-
|
|
331
|
+
|
|
332
|
+
def change(event)
|
|
333
|
+
@result << ["!", event.old_position, event.new_position]
|
|
334
|
+
end
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
def balanced_callback
|
|
338
|
+
BalancedCallback.new
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
class BalancedCallbackNoChange < BalancedCallback
|
|
342
|
+
undef :change
|
|
284
343
|
end
|
|
285
344
|
|
|
286
345
|
def balanced_callback_no_change
|
|
287
|
-
|
|
288
|
-
class << balanced
|
|
289
|
-
undef :change
|
|
290
|
-
end
|
|
291
|
-
balanced
|
|
346
|
+
BalancedCallbackNoChange.new
|
|
292
347
|
end
|
|
293
348
|
|
|
294
349
|
module Matchers
|
|
@@ -302,9 +357,7 @@ module Diff::LCS::SpecHelper
|
|
|
302
357
|
|
|
303
358
|
matcher :correctly_map_sequence do |s1|
|
|
304
359
|
match do |actual|
|
|
305
|
-
actual.
|
|
306
|
-
expect(ee).to be_nil_or_match_values(ii, s1, @s2)
|
|
307
|
-
}
|
|
360
|
+
actual.each_index { |ii| expect(actual[ii]).to be_nil_or_match_values(ii, s1, @s2) }
|
|
308
361
|
end
|
|
309
362
|
|
|
310
363
|
chain :to_other_sequence do |s2|
|
|
@@ -316,6 +369,8 @@ end
|
|
|
316
369
|
|
|
317
370
|
RSpec.configure do |conf|
|
|
318
371
|
conf.include Diff::LCS::SpecHelper
|
|
319
|
-
conf.alias_it_should_behave_like_to :it_has_behavior,
|
|
372
|
+
conf.alias_it_should_behave_like_to :it_has_behavior, "has behavior:"
|
|
373
|
+
# standard:disable Style/HashSyntax
|
|
320
374
|
conf.filter_run_excluding :broken => true
|
|
375
|
+
# standard:enable Style/HashSyntax
|
|
321
376
|
end
|