diff-lcs 2.0.0.beta.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +32 -5
- data/CODE_OF_CONDUCT.md +152 -114
- data/CONTRIBUTING.md +8 -3
- data/CONTRIBUTORS.md +19 -9
- data/Manifest.txt +88 -70
- data/README.md +30 -17
- data/Rakefile +90 -22
- data/SECURITY.md +3 -12
- data/integration/compare/array_diff_spec.rb +10 -0
- data/integration/compare/hash_diff_spec.rb +25 -0
- data/integration/compare/string_diff_spec.rb +10 -0
- data/integration/rspec_differ_spec.rb +26 -0
- data/integration/rspec_expectations_spec.rb +32 -0
- data/integration/runner +20 -0
- data/lib/diff/lcs/change.rb +21 -16
- data/lib/diff/lcs/ldiff.rb +9 -4
- data/lib/diff/lcs/version.rb +1 -1
- data/spec/hunk_spec.rb +32 -34
- data/spec/ldiff_spec.rb +7 -7
- data/spec/spec_helper.rb +4 -12
- data/test/fixtures/ldiff/output.diff-c +7 -0
- data/test/fixtures/ldiff/output.diff-u +5 -0
- data/test/fixtures/ldiff/output.diff.bin2 +1 -0
- data/test/fixtures/ldiff/output.diff.bin2-c +1 -0
- data/test/fixtures/ldiff/output.diff.bin2-e +1 -0
- data/test/fixtures/ldiff/output.diff.bin2-f +1 -0
- data/test/fixtures/ldiff/output.diff.bin2-u +1 -0
- data/{spec → test}/fixtures/ldiff/output.diff.chef-c +2 -2
- data/test/fixtures/ldiff/output.diff.chef-u +9 -0
- data/{spec → test}/fixtures/ldiff/output.diff.chef2-c +2 -2
- data/{spec → test}/fixtures/ldiff/output.diff.chef2-u +2 -2
- data/test/fixtures/ldiff/output.diff.empty.vs.four_lines-c +9 -0
- data/test/fixtures/ldiff/output.diff.empty.vs.four_lines-u +7 -0
- data/test/fixtures/ldiff/output.diff.four_lines.vs.empty-c +9 -0
- data/test/fixtures/ldiff/output.diff.four_lines.vs.empty-u +7 -0
- data/test/fixtures/ldiff/output.diff.issue95_trailing_context-c +9 -0
- data/test/fixtures/ldiff/output.diff.issue95_trailing_context-u +6 -0
- data/{spec → test}/fixtures/ldiff/output.diff.missing_new_line1-c +2 -2
- data/test/fixtures/ldiff/output.diff.missing_new_line1-u +9 -0
- data/{spec → test}/fixtures/ldiff/output.diff.missing_new_line2-c +2 -2
- data/test/fixtures/ldiff/output.diff.missing_new_line2-u +9 -0
- data/test/test_block.rb +34 -0
- data/test/test_change.rb +234 -0
- data/test/test_diff.rb +53 -0
- data/test/test_helper.rb +225 -0
- data/test/test_hunk.rb +72 -0
- data/test/test_issues.rb +168 -0
- data/test/test_lcs.rb +47 -0
- data/test/test_ldiff.rb +89 -0
- data/test/test_patch.rb +362 -0
- data/test/test_sdiff.rb +167 -0
- data/test/test_traverse_balanced.rb +322 -0
- data/test/test_traverse_sequences.rb +187 -0
- metadata +136 -105
- data/spec/fixtures/ldiff/output.diff-c +0 -7
- data/spec/fixtures/ldiff/output.diff-u +0 -5
- data/spec/fixtures/ldiff/output.diff.bin2 +0 -1
- data/spec/fixtures/ldiff/output.diff.bin2-c +0 -1
- data/spec/fixtures/ldiff/output.diff.bin2-e +0 -1
- data/spec/fixtures/ldiff/output.diff.bin2-f +0 -1
- data/spec/fixtures/ldiff/output.diff.bin2-u +0 -1
- data/spec/fixtures/ldiff/output.diff.chef-u +0 -9
- data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-c +0 -9
- data/spec/fixtures/ldiff/output.diff.empty.vs.four_lines-u +0 -7
- data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-c +0 -9
- data/spec/fixtures/ldiff/output.diff.four_lines.vs.empty-u +0 -7
- data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-c +0 -9
- data/spec/fixtures/ldiff/output.diff.issue95_trailing_context-u +0 -6
- data/spec/fixtures/ldiff/output.diff.missing_new_line1-u +0 -9
- data/spec/fixtures/ldiff/output.diff.missing_new_line2-u +0 -9
- /data/{spec → test}/fixtures/123_x +0 -0
- /data/{spec → test}/fixtures/456_x +0 -0
- /data/{spec → test}/fixtures/aX +0 -0
- /data/{spec → test}/fixtures/bXaX +0 -0
- /data/{spec → test}/fixtures/ds1.csv +0 -0
- /data/{spec → test}/fixtures/ds2.csv +0 -0
- /data/{spec → test}/fixtures/empty +0 -0
- /data/{spec → test}/fixtures/file1.bin +0 -0
- /data/{spec → test}/fixtures/file2.bin +0 -0
- /data/{spec → test}/fixtures/four_lines +0 -0
- /data/{spec → test}/fixtures/four_lines_with_missing_new_line +0 -0
- /data/{spec → test}/fixtures/ldiff/diff.missing_new_line1-e +0 -0
- /data/{spec → test}/fixtures/ldiff/diff.missing_new_line1-f +0 -0
- /data/{spec → test}/fixtures/ldiff/diff.missing_new_line2-e +0 -0
- /data/{spec → test}/fixtures/ldiff/diff.missing_new_line2-f +0 -0
- /data/{spec → test}/fixtures/ldiff/error.diff.chef-e +0 -0
- /data/{spec → test}/fixtures/ldiff/error.diff.chef-f +0 -0
- /data/{spec → test}/fixtures/ldiff/error.diff.missing_new_line1-e +0 -0
- /data/{spec → test}/fixtures/ldiff/error.diff.missing_new_line1-f +0 -0
- /data/{spec → test}/fixtures/ldiff/error.diff.missing_new_line2-e +0 -0
- /data/{spec → test}/fixtures/ldiff/error.diff.missing_new_line2-f +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff.bin1 +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff.bin1-c +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff.bin1-e +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff.bin1-f +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff.bin1-u +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff.chef +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff.chef2 +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff.chef2-d +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff.empty.vs.four_lines +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff.empty.vs.four_lines-e +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff.empty.vs.four_lines-f +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff.four_lines.vs.empty +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff.four_lines.vs.empty-e +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff.four_lines.vs.empty-f +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff.issue95_trailing_context +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff.issue95_trailing_context-e +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff.issue95_trailing_context-f +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff.missing_new_line1 +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff.missing_new_line1-e +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff.missing_new_line1-f +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff.missing_new_line2 +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff.missing_new_line2-e +0 -0
- /data/{spec → test}/fixtures/ldiff/output.diff.missing_new_line2-f +0 -0
- /data/{spec → test}/fixtures/new-chef +0 -0
- /data/{spec → test}/fixtures/new-chef2 +0 -0
- /data/{spec → test}/fixtures/old-chef +0 -0
- /data/{spec → test}/fixtures/old-chef2 +0 -0
data/test/test_patch.rb
ADDED
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "test_helper"
|
|
4
|
+
|
|
5
|
+
class TestPatch < Minitest::Test
|
|
6
|
+
def patch_sequences_correctly(s1, s2, patch_set)
|
|
7
|
+
assert_equal s2, patch(s1, patch_set)
|
|
8
|
+
assert_equal s2, patch(s1, patch_set, :patch)
|
|
9
|
+
assert_equal s2, patch!(s1, patch_set)
|
|
10
|
+
assert_equal s1, patch(s2, patch_set)
|
|
11
|
+
assert_equal s1, patch(s2, patch_set, :unpatch)
|
|
12
|
+
assert_equal s1, unpatch!(s2, patch_set)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_diff_patchset_empty_returns_source_string
|
|
16
|
+
diff = diff(hello, hello)
|
|
17
|
+
assert_equal hello, patch(hello, diff)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_diff_patchset_empty_returns_source_array
|
|
21
|
+
diff = diff(hello_ary, hello_ary)
|
|
22
|
+
assert_equal hello_ary, patch(hello_ary, diff)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_diff_patchset_default_callbacks_forward
|
|
26
|
+
patch_set = diff(seq1, seq2)
|
|
27
|
+
patch_sequences_correctly(seq1, seq2, patch_set)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_diff_patchset_default_callbacks_reverse
|
|
31
|
+
patch_set = diff(seq2, seq1)
|
|
32
|
+
patch_sequences_correctly(seq2, seq1, patch_set)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_diff_patchset_context_callbacks_forward
|
|
36
|
+
patch_set = diff(seq1, seq2, Diff::LCS::ContextDiffCallbacks)
|
|
37
|
+
patch_sequences_correctly(seq1, seq2, patch_set)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_diff_patchset_context_callbacks_reverse
|
|
41
|
+
patch_set = diff(seq2, seq1, Diff::LCS::ContextDiffCallbacks)
|
|
42
|
+
patch_sequences_correctly(seq2, seq1, patch_set)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_diff_patchset_sdiff_callbacks_forward
|
|
46
|
+
patch_set = diff(seq1, seq2, Diff::LCS::SDiffCallbacks)
|
|
47
|
+
patch_sequences_correctly(seq1, seq2, patch_set)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_diff_patchset_sdiff_callbacks_reverse
|
|
51
|
+
patch_set = diff(seq2, seq1, Diff::LCS::SDiffCallbacks)
|
|
52
|
+
patch_sequences_correctly(seq2, seq1, patch_set)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_sdiff_patchset_empty_returns_source_string
|
|
56
|
+
assert_equal hello, patch(hello, sdiff(hello, hello))
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_sdiff_patchset_empty_returns_source_array
|
|
60
|
+
assert_equal hello_ary, patch(hello_ary, sdiff(hello_ary, hello_ary))
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_sdiff_patchset_diff_callbacks_forward
|
|
64
|
+
patch_set = sdiff(seq1, seq2, Diff::LCS::DiffCallbacks)
|
|
65
|
+
patch_sequences_correctly(seq1, seq2, patch_set)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def test_sdiff_patchset_diff_callbacks_reverse
|
|
69
|
+
patch_set = sdiff(seq2, seq1, Diff::LCS::DiffCallbacks)
|
|
70
|
+
patch_sequences_correctly(seq2, seq1, patch_set)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_sdiff_patchset_context_callbacks_forward
|
|
74
|
+
patch_set = sdiff(seq1, seq2, Diff::LCS::ContextDiffCallbacks)
|
|
75
|
+
patch_sequences_correctly(seq1, seq2, patch_set)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def test_sdiff_patchset_context_callbacks_reverse
|
|
79
|
+
patch_set = sdiff(seq2, seq1, Diff::LCS::ContextDiffCallbacks)
|
|
80
|
+
patch_sequences_correctly(seq2, seq1, patch_set)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def test_sdiff_patchset_sdiff_callbacks_forward
|
|
84
|
+
patch_set = sdiff(seq1, seq2)
|
|
85
|
+
patch_sequences_correctly(seq1, seq2, patch_set)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def test_sdiff_patchset_sdiff_callbacks_reverse
|
|
89
|
+
patch_set = sdiff(seq2, seq1)
|
|
90
|
+
patch_sequences_correctly(seq2, seq1, patch_set)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def test_bug_891_diff_default_callbacks_autodiscover_s1_to_s2
|
|
94
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
95
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
96
|
+
patch_set = diff(s1, s2)
|
|
97
|
+
assert_equal s2, patch(s1, patch_set)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def test_bug_891_diff_default_callbacks_autodiscover_s2_to_s1
|
|
101
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
102
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
103
|
+
patch_set = diff(s2, s1)
|
|
104
|
+
assert_equal s2, patch(s1, patch_set)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def test_bug_891_diff_default_callbacks_left_to_right
|
|
108
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
109
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
110
|
+
patch_set_s1_s2 = diff(s1, s2)
|
|
111
|
+
patch_set_s2_s1 = diff(s2, s1)
|
|
112
|
+
assert_equal s1, patch(s2, patch_set_s2_s1)
|
|
113
|
+
assert_equal s1, patch(s2, patch_set_s1_s2)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def test_bug_891_diff_default_callbacks_explicit_patch
|
|
117
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
118
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
119
|
+
patch_set_s1_s2 = diff(s1, s2)
|
|
120
|
+
patch_set_s2_s1 = diff(s2, s1)
|
|
121
|
+
assert_equal s2, patch(s1, patch_set_s1_s2, :patch)
|
|
122
|
+
assert_equal s1, patch(s2, patch_set_s2_s1, :patch)
|
|
123
|
+
assert_equal s2, patch!(s1, patch_set_s1_s2)
|
|
124
|
+
assert_equal s1, patch!(s2, patch_set_s2_s1)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def test_bug_891_diff_default_callbacks_explicit_unpatch
|
|
128
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
129
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
130
|
+
patch_set_s1_s2 = diff(s1, s2)
|
|
131
|
+
patch_set_s2_s1 = diff(s2, s1)
|
|
132
|
+
assert_equal s1, patch(s2, patch_set_s1_s2, :unpatch)
|
|
133
|
+
assert_equal s2, patch(s1, patch_set_s2_s1, :unpatch)
|
|
134
|
+
assert_equal s1, unpatch!(s2, patch_set_s1_s2)
|
|
135
|
+
assert_equal s2, unpatch!(s1, patch_set_s2_s1)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def test_bug_891_diff_context_callbacks_autodiscover_s1_to_s2
|
|
139
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
140
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
141
|
+
patch_set = diff(s1, s2, Diff::LCS::ContextDiffCallbacks)
|
|
142
|
+
assert_equal s2, patch(s1, patch_set)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def test_bug_891_diff_context_callbacks_autodiscover_s2_to_s1
|
|
146
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
147
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
148
|
+
patch_set = diff(s2, s1, Diff::LCS::ContextDiffCallbacks)
|
|
149
|
+
assert_equal s2, patch(s1, patch_set)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def test_bug_891_diff_context_callbacks_left_to_right
|
|
153
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
154
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
155
|
+
patch_set_s1_s2 = diff(s1, s2, Diff::LCS::ContextDiffCallbacks)
|
|
156
|
+
patch_set_s2_s1 = diff(s2, s1, Diff::LCS::ContextDiffCallbacks)
|
|
157
|
+
assert_equal s1, patch(s2, patch_set_s2_s1)
|
|
158
|
+
assert_equal s1, patch(s2, patch_set_s1_s2)
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def test_bug_891_diff_context_callbacks_explicit_patch
|
|
162
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
163
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
164
|
+
patch_set_s1_s2 = diff(s1, s2, Diff::LCS::ContextDiffCallbacks)
|
|
165
|
+
patch_set_s2_s1 = diff(s2, s1, Diff::LCS::ContextDiffCallbacks)
|
|
166
|
+
assert_equal s2, patch(s1, patch_set_s1_s2, :patch)
|
|
167
|
+
assert_equal s1, patch(s2, patch_set_s2_s1, :patch)
|
|
168
|
+
assert_equal s2, patch!(s1, patch_set_s1_s2)
|
|
169
|
+
assert_equal s1, patch!(s2, patch_set_s2_s1)
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def test_bug_891_diff_context_callbacks_explicit_unpatch
|
|
173
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
174
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
175
|
+
patch_set_s1_s2 = diff(s1, s2, Diff::LCS::ContextDiffCallbacks)
|
|
176
|
+
patch_set_s2_s1 = diff(s2, s1, Diff::LCS::ContextDiffCallbacks)
|
|
177
|
+
assert_equal s1, patch(s2, patch_set_s1_s2, :unpatch)
|
|
178
|
+
assert_equal s2, patch(s1, patch_set_s2_s1, :unpatch)
|
|
179
|
+
assert_equal s1, unpatch!(s2, patch_set_s1_s2)
|
|
180
|
+
assert_equal s2, unpatch!(s1, patch_set_s2_s1)
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def test_bug_891_diff_sdiff_callbacks_autodiscover_s1_to_s2
|
|
184
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
185
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
186
|
+
patch_set = diff(s1, s2, Diff::LCS::SDiffCallbacks)
|
|
187
|
+
assert_equal s2, patch(s1, patch_set)
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def test_bug_891_diff_sdiff_callbacks_autodiscover_s2_to_s1
|
|
191
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
192
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
193
|
+
patch_set = diff(s2, s1, Diff::LCS::SDiffCallbacks)
|
|
194
|
+
assert_equal s2, patch(s1, patch_set)
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def test_bug_891_diff_sdiff_callbacks_left_to_right
|
|
198
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
199
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
200
|
+
patch_set_s1_s2 = diff(s1, s2, Diff::LCS::SDiffCallbacks)
|
|
201
|
+
patch_set_s2_s1 = diff(s2, s1, Diff::LCS::SDiffCallbacks)
|
|
202
|
+
assert_equal s1, patch(s2, patch_set_s2_s1)
|
|
203
|
+
assert_equal s1, patch(s2, patch_set_s1_s2)
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def test_bug_891_diff_sdiff_callbacks_explicit_patch
|
|
207
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
208
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
209
|
+
patch_set_s1_s2 = diff(s1, s2, Diff::LCS::SDiffCallbacks)
|
|
210
|
+
patch_set_s2_s1 = diff(s2, s1, Diff::LCS::SDiffCallbacks)
|
|
211
|
+
assert_equal s2, patch(s1, patch_set_s1_s2, :patch)
|
|
212
|
+
assert_equal s1, patch(s2, patch_set_s2_s1, :patch)
|
|
213
|
+
assert_equal s2, patch!(s1, patch_set_s1_s2)
|
|
214
|
+
assert_equal s1, patch!(s2, patch_set_s2_s1)
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def test_bug_891_diff_sdiff_callbacks_explicit_unpatch
|
|
218
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
219
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
220
|
+
patch_set_s1_s2 = diff(s1, s2, Diff::LCS::SDiffCallbacks)
|
|
221
|
+
patch_set_s2_s1 = diff(s2, s1, Diff::LCS::SDiffCallbacks)
|
|
222
|
+
assert_equal s1, patch(s2, patch_set_s1_s2, :unpatch)
|
|
223
|
+
assert_equal s2, patch(s1, patch_set_s2_s1, :unpatch)
|
|
224
|
+
assert_equal s1, unpatch!(s2, patch_set_s1_s2)
|
|
225
|
+
assert_equal s2, unpatch!(s1, patch_set_s2_s1)
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
def test_bug_891_sdiff_default_callbacks_autodiscover_s1_to_s2
|
|
229
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
230
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
231
|
+
patch_set = sdiff(s1, s2)
|
|
232
|
+
assert_equal s2, patch(s1, patch_set)
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
def test_bug_891_sdiff_default_callbacks_autodiscover_s2_to_s1
|
|
236
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
237
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
238
|
+
patch_set = sdiff(s2, s1)
|
|
239
|
+
assert_equal s2, patch(s1, patch_set)
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
def test_bug_891_sdiff_default_callbacks_left_to_right
|
|
243
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
244
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
245
|
+
patch_set_s1_s2 = sdiff(s1, s2)
|
|
246
|
+
patch_set_s2_s1 = sdiff(s2, s1)
|
|
247
|
+
assert_equal s1, patch(s2, patch_set_s2_s1)
|
|
248
|
+
assert_equal s1, patch(s2, patch_set_s1_s2)
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
def test_bug_891_sdiff_default_callbacks_explicit_patch
|
|
252
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
253
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
254
|
+
patch_set_s1_s2 = sdiff(s1, s2)
|
|
255
|
+
patch_set_s2_s1 = sdiff(s2, s1)
|
|
256
|
+
assert_equal s2, patch(s1, patch_set_s1_s2, :patch)
|
|
257
|
+
assert_equal s1, patch(s2, patch_set_s2_s1, :patch)
|
|
258
|
+
assert_equal s2, patch!(s1, patch_set_s1_s2)
|
|
259
|
+
assert_equal s1, patch!(s2, patch_set_s2_s1)
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
def test_bug_891_sdiff_default_callbacks_explicit_unpatch
|
|
263
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
264
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
265
|
+
patch_set_s1_s2 = sdiff(s1, s2)
|
|
266
|
+
patch_set_s2_s1 = sdiff(s2, s1)
|
|
267
|
+
assert_equal s1, patch(s2, patch_set_s1_s2, :unpatch)
|
|
268
|
+
assert_equal s2, patch(s1, patch_set_s2_s1, :unpatch)
|
|
269
|
+
assert_equal s1, unpatch!(s2, patch_set_s1_s2)
|
|
270
|
+
assert_equal s2, unpatch!(s1, patch_set_s2_s1)
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
def test_bug_891_sdiff_context_callbacks_autodiscover_s1_to_s2
|
|
274
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
275
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
276
|
+
patch_set = sdiff(s1, s2, Diff::LCS::ContextDiffCallbacks)
|
|
277
|
+
assert_equal s2, patch(s1, patch_set)
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
def test_bug_891_sdiff_context_callbacks_autodiscover_s2_to_s1
|
|
281
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
282
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
283
|
+
patch_set = sdiff(s2, s1, Diff::LCS::ContextDiffCallbacks)
|
|
284
|
+
assert_equal s2, patch(s1, patch_set)
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
def test_bug_891_sdiff_context_callbacks_left_to_right
|
|
288
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
289
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
290
|
+
patch_set_s1_s2 = sdiff(s1, s2, Diff::LCS::ContextDiffCallbacks)
|
|
291
|
+
patch_set_s2_s1 = sdiff(s2, s1, Diff::LCS::ContextDiffCallbacks)
|
|
292
|
+
assert_equal s1, patch(s2, patch_set_s2_s1)
|
|
293
|
+
assert_equal s1, patch(s2, patch_set_s1_s2)
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
def test_bug_891_sdiff_context_callbacks_explicit_patch
|
|
297
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
298
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
299
|
+
patch_set_s1_s2 = sdiff(s1, s2, Diff::LCS::ContextDiffCallbacks)
|
|
300
|
+
patch_set_s2_s1 = sdiff(s2, s1, Diff::LCS::ContextDiffCallbacks)
|
|
301
|
+
assert_equal s2, patch(s1, patch_set_s1_s2, :patch)
|
|
302
|
+
assert_equal s1, patch(s2, patch_set_s2_s1, :patch)
|
|
303
|
+
assert_equal s2, patch!(s1, patch_set_s1_s2)
|
|
304
|
+
assert_equal s1, patch!(s2, patch_set_s2_s1)
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
def test_bug_891_sdiff_context_callbacks_explicit_unpatch
|
|
308
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
309
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
310
|
+
patch_set_s1_s2 = sdiff(s1, s2, Diff::LCS::ContextDiffCallbacks)
|
|
311
|
+
patch_set_s2_s1 = sdiff(s2, s1, Diff::LCS::ContextDiffCallbacks)
|
|
312
|
+
assert_equal s1, patch(s2, patch_set_s1_s2, :unpatch)
|
|
313
|
+
assert_equal s2, patch(s1, patch_set_s2_s1, :unpatch)
|
|
314
|
+
assert_equal s1, unpatch!(s2, patch_set_s1_s2)
|
|
315
|
+
assert_equal s2, unpatch!(s1, patch_set_s2_s1)
|
|
316
|
+
end
|
|
317
|
+
|
|
318
|
+
def test_bug_891_sdiff_diff_callbacks_autodiscover_s1_to_s2
|
|
319
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
320
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
321
|
+
patch_set = sdiff(s1, s2, Diff::LCS::DiffCallbacks)
|
|
322
|
+
assert_equal s2, patch(s1, patch_set)
|
|
323
|
+
end
|
|
324
|
+
|
|
325
|
+
def test_bug_891_sdiff_diff_callbacks_autodiscover_s2_to_s1
|
|
326
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
327
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
328
|
+
patch_set = sdiff(s2, s1, Diff::LCS::DiffCallbacks)
|
|
329
|
+
assert_equal s2, patch(s1, patch_set)
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
def test_bug_891_sdiff_diff_callbacks_left_to_right
|
|
333
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
334
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
335
|
+
patch_set_s1_s2 = sdiff(s1, s2, Diff::LCS::DiffCallbacks)
|
|
336
|
+
patch_set_s2_s1 = sdiff(s2, s1, Diff::LCS::DiffCallbacks)
|
|
337
|
+
assert_equal s1, patch(s2, patch_set_s2_s1)
|
|
338
|
+
assert_equal s1, patch(s2, patch_set_s1_s2)
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
def test_bug_891_sdiff_diff_callbacks_explicit_patch
|
|
342
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
343
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
344
|
+
patch_set_s1_s2 = sdiff(s1, s2, Diff::LCS::DiffCallbacks)
|
|
345
|
+
patch_set_s2_s1 = sdiff(s2, s1, Diff::LCS::DiffCallbacks)
|
|
346
|
+
assert_equal s2, patch(s1, patch_set_s1_s2, :patch)
|
|
347
|
+
assert_equal s1, patch(s2, patch_set_s2_s1, :patch)
|
|
348
|
+
assert_equal s2, patch!(s1, patch_set_s1_s2)
|
|
349
|
+
assert_equal s1, patch!(s2, patch_set_s2_s1)
|
|
350
|
+
end
|
|
351
|
+
|
|
352
|
+
def test_bug_891_sdiff_diff_callbacks_explicit_unpatch
|
|
353
|
+
s1 = %w[a b c d e f g h i j k] # standard:disable Layout/SpaceInsideArrayPercentLiteral
|
|
354
|
+
s2 = %w[a b c d D e f g h i j k]
|
|
355
|
+
patch_set_s1_s2 = sdiff(s1, s2, Diff::LCS::DiffCallbacks)
|
|
356
|
+
patch_set_s2_s1 = sdiff(s2, s1, Diff::LCS::DiffCallbacks)
|
|
357
|
+
assert_equal s1, patch(s2, patch_set_s1_s2, :unpatch)
|
|
358
|
+
assert_equal s2, patch(s1, patch_set_s2_s1, :unpatch)
|
|
359
|
+
assert_equal s1, unpatch!(s2, patch_set_s1_s2)
|
|
360
|
+
assert_equal s2, unpatch!(s1, patch_set_s2_s1)
|
|
361
|
+
end
|
|
362
|
+
end
|
data/test/test_sdiff.rb
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "test_helper"
|
|
4
|
+
|
|
5
|
+
class TestSDiff < Minitest::Test
|
|
6
|
+
def compare_sequences_correctly(s1, s2, result)
|
|
7
|
+
assert_equal context_diff(result), sdiff(s1, s2)
|
|
8
|
+
assert_equal context_diff(reverse_sdiff(result)), sdiff(s2, s1)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_seq1_seq2
|
|
12
|
+
compare_sequences_correctly(seq1, seq2, correct_forward_sdiff)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_abc_def_yyy_xxx_ghi_jkl
|
|
16
|
+
s1 = %w[abc def yyy xxx ghi jkl]
|
|
17
|
+
s2 = %w[abc dxf xxx ghi jkl]
|
|
18
|
+
result = [
|
|
19
|
+
["=", [0, "abc"], [0, "abc"]],
|
|
20
|
+
["!", [1, "def"], [1, "dxf"]],
|
|
21
|
+
["-", [2, "yyy"], [2, nil]],
|
|
22
|
+
["=", [3, "xxx"], [2, "xxx"]],
|
|
23
|
+
["=", [4, "ghi"], [3, "ghi"]],
|
|
24
|
+
["=", [5, "jkl"], [4, "jkl"]]
|
|
25
|
+
]
|
|
26
|
+
compare_sequences_correctly(s1, s2, result)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_a_b_c_d_e_vs_a_e
|
|
30
|
+
s1 = %w[a b c d e]
|
|
31
|
+
s2 = %w[a e]
|
|
32
|
+
result = [
|
|
33
|
+
["=", [0, "a"], [0, "a"]],
|
|
34
|
+
["-", [1, "b"], [1, nil]],
|
|
35
|
+
["-", [2, "c"], [1, nil]],
|
|
36
|
+
["-", [3, "d"], [1, nil]],
|
|
37
|
+
["=", [4, "e"], [1, "e"]]
|
|
38
|
+
]
|
|
39
|
+
compare_sequences_correctly(s1, s2, result)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_a_e_vs_a_b_c_d_e
|
|
43
|
+
s1 = %w[a e]
|
|
44
|
+
s2 = %w[a b c d e]
|
|
45
|
+
result = [
|
|
46
|
+
["=", [0, "a"], [0, "a"]],
|
|
47
|
+
["+", [1, nil], [1, "b"]],
|
|
48
|
+
["+", [1, nil], [2, "c"]],
|
|
49
|
+
["+", [1, nil], [3, "d"]],
|
|
50
|
+
["=", [1, "e"], [4, "e"]]
|
|
51
|
+
]
|
|
52
|
+
compare_sequences_correctly(s1, s2, result)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_v_x_a_e_vs_w_y_a_b_c_d_e
|
|
56
|
+
s1 = %w[v x a e]
|
|
57
|
+
s2 = %w[w y a b c d e]
|
|
58
|
+
result = [
|
|
59
|
+
["!", [0, "v"], [0, "w"]],
|
|
60
|
+
["!", [1, "x"], [1, "y"]],
|
|
61
|
+
["=", [2, "a"], [2, "a"]],
|
|
62
|
+
["+", [3, nil], [3, "b"]],
|
|
63
|
+
["+", [3, nil], [4, "c"]],
|
|
64
|
+
["+", [3, nil], [5, "d"]],
|
|
65
|
+
["=", [3, "e"], [6, "e"]]
|
|
66
|
+
]
|
|
67
|
+
compare_sequences_correctly(s1, s2, result)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def test_x_a_e_vs_a_b_c_d_e
|
|
71
|
+
s1 = %w[x a e]
|
|
72
|
+
s2 = %w[a b c d e]
|
|
73
|
+
result = [
|
|
74
|
+
["-", [0, "x"], [0, nil]],
|
|
75
|
+
["=", [1, "a"], [0, "a"]],
|
|
76
|
+
["+", [2, nil], [1, "b"]],
|
|
77
|
+
["+", [2, nil], [2, "c"]],
|
|
78
|
+
["+", [2, nil], [3, "d"]],
|
|
79
|
+
["=", [2, "e"], [4, "e"]]
|
|
80
|
+
]
|
|
81
|
+
compare_sequences_correctly(s1, s2, result)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def test_a_e_vs_x_a_b_c_d_e
|
|
85
|
+
s1 = %w[a e]
|
|
86
|
+
s2 = %w[x a b c d e]
|
|
87
|
+
result = [
|
|
88
|
+
["+", [0, nil], [0, "x"]],
|
|
89
|
+
["=", [0, "a"], [1, "a"]],
|
|
90
|
+
["+", [1, nil], [2, "b"]],
|
|
91
|
+
["+", [1, nil], [3, "c"]],
|
|
92
|
+
["+", [1, nil], [4, "d"]],
|
|
93
|
+
["=", [1, "e"], [5, "e"]]
|
|
94
|
+
]
|
|
95
|
+
compare_sequences_correctly(s1, s2, result)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def test_a_e_v_vs_x_a_b_c_d_e_w_x
|
|
99
|
+
s1 = %w[a e v]
|
|
100
|
+
s2 = %w[x a b c d e w x]
|
|
101
|
+
result = [
|
|
102
|
+
["+", [0, nil], [0, "x"]],
|
|
103
|
+
["=", [0, "a"], [1, "a"]],
|
|
104
|
+
["+", [1, nil], [2, "b"]],
|
|
105
|
+
["+", [1, nil], [3, "c"]],
|
|
106
|
+
["+", [1, nil], [4, "d"]],
|
|
107
|
+
["=", [1, "e"], [5, "e"]],
|
|
108
|
+
["!", [2, "v"], [6, "w"]],
|
|
109
|
+
["+", [3, nil], [7, "x"]]
|
|
110
|
+
]
|
|
111
|
+
compare_sequences_correctly(s1, s2, result)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def test_empty_vs_a_b_c
|
|
115
|
+
s1 = %w[]
|
|
116
|
+
s2 = %w[a b c]
|
|
117
|
+
result = [
|
|
118
|
+
["+", [0, nil], [0, "a"]],
|
|
119
|
+
["+", [0, nil], [1, "b"]],
|
|
120
|
+
["+", [0, nil], [2, "c"]]
|
|
121
|
+
]
|
|
122
|
+
compare_sequences_correctly(s1, s2, result)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def test_a_b_c_vs_1
|
|
126
|
+
s1 = %w[a b c]
|
|
127
|
+
s2 = %w[1]
|
|
128
|
+
result = [
|
|
129
|
+
["!", [0, "a"], [0, "1"]],
|
|
130
|
+
["-", [1, "b"], [1, nil]],
|
|
131
|
+
["-", [2, "c"], [1, nil]]
|
|
132
|
+
]
|
|
133
|
+
compare_sequences_correctly(s1, s2, result)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def test_a_b_c_vs_c
|
|
137
|
+
s1 = %w[a b c]
|
|
138
|
+
s2 = %w[c]
|
|
139
|
+
result = [
|
|
140
|
+
["-", [0, "a"], [0, nil]],
|
|
141
|
+
["-", [1, "b"], [0, nil]],
|
|
142
|
+
["=", [2, "c"], [0, "c"]]
|
|
143
|
+
]
|
|
144
|
+
compare_sequences_correctly(s1, s2, result)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def test_abcd_efgh_ijkl_mnop_vs_empty
|
|
148
|
+
s1 = %w[abcd efgh ijkl mnop]
|
|
149
|
+
s2 = []
|
|
150
|
+
result = [
|
|
151
|
+
["-", [0, "abcd"], [0, nil]],
|
|
152
|
+
["-", [1, "efgh"], [0, nil]],
|
|
153
|
+
["-", [2, "ijkl"], [0, nil]],
|
|
154
|
+
["-", [3, "mnop"], [0, nil]]
|
|
155
|
+
]
|
|
156
|
+
compare_sequences_correctly(s1, s2, result)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def test_nested_array_vs_empty
|
|
160
|
+
s1 = [[1, 2]]
|
|
161
|
+
s2 = []
|
|
162
|
+
result = [
|
|
163
|
+
["-", [0, [1, 2]], [0, nil]]
|
|
164
|
+
]
|
|
165
|
+
compare_sequences_correctly(s1, s2, result)
|
|
166
|
+
end
|
|
167
|
+
end
|