diff-lcs 2.0.0.beta.1 → 2.0.0.beta.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 +4 -4
- data/CHANGELOG.md +30 -5
- data/CONTRIBUTING.md +8 -3
- data/CONTRIBUTORS.md +19 -9
- data/Manifest.txt +88 -70
- data/README.md +13 -9
- data/Rakefile +90 -22
- data/SECURITY.md +1 -10
- 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 +130 -96
- 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_issues.rb
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
require "diff/lcs/hunk"
|
|
5
|
+
|
|
6
|
+
class TestIssues < Minitest::Test
|
|
7
|
+
def test_issue_1_string_forward_diff
|
|
8
|
+
s1 = "aX"
|
|
9
|
+
s2 = "bXaX"
|
|
10
|
+
forward_diff = [
|
|
11
|
+
[
|
|
12
|
+
["+", 0, "b"],
|
|
13
|
+
["+", 1, "X"]
|
|
14
|
+
]
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
diff_s1_s2 = diff(s1, s2)
|
|
18
|
+
|
|
19
|
+
assert_equal change_diff(forward_diff), diff_s1_s2
|
|
20
|
+
assert_equal s2, patch(s1, diff_s1_s2)
|
|
21
|
+
assert_equal s1, patch(s2, diff_s1_s2)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_issue_1_string_reverse_diff
|
|
25
|
+
s1 = "bXaX"
|
|
26
|
+
s2 = "aX"
|
|
27
|
+
forward_diff = [
|
|
28
|
+
[
|
|
29
|
+
["-", 0, "b"],
|
|
30
|
+
["-", 1, "X"]
|
|
31
|
+
]
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
diff_s1_s2 = diff(s1, s2)
|
|
35
|
+
|
|
36
|
+
assert_equal change_diff(forward_diff), diff_s1_s2
|
|
37
|
+
assert_equal s2, patch(s1, diff_s1_s2)
|
|
38
|
+
assert_equal s1, patch(s2, diff_s1_s2)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def test_issue_1_array_forward_diff
|
|
42
|
+
s1 = %w[a X]
|
|
43
|
+
s2 = %w[b X a X]
|
|
44
|
+
forward_diff = [
|
|
45
|
+
[
|
|
46
|
+
["+", 0, "b"],
|
|
47
|
+
["+", 1, "X"]
|
|
48
|
+
]
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
diff_s1_s2 = diff(s1, s2)
|
|
52
|
+
|
|
53
|
+
assert_equal change_diff(forward_diff), diff_s1_s2
|
|
54
|
+
assert_equal s2, patch(s1, diff_s1_s2)
|
|
55
|
+
assert_equal s1, patch(s2, diff_s1_s2)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def test_issue_1_array_reverse_diff
|
|
59
|
+
s1 = %w[b X a X]
|
|
60
|
+
s2 = %w[a X]
|
|
61
|
+
forward_diff = [
|
|
62
|
+
[
|
|
63
|
+
["-", 0, "b"],
|
|
64
|
+
["-", 1, "X"]
|
|
65
|
+
]
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
diff_s1_s2 = diff(s1, s2)
|
|
69
|
+
|
|
70
|
+
assert_equal change_diff(forward_diff), diff_s1_s2
|
|
71
|
+
assert_equal s2, patch(s1, diff_s1_s2)
|
|
72
|
+
assert_equal s1, patch(s2, diff_s1_s2)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def test_issue_57_should_fail_with_correct_error
|
|
76
|
+
assert_raises(Minitest::Assertion) do
|
|
77
|
+
actual = {category: "app.rack.request"}
|
|
78
|
+
expected = {category: "rack.middleware", title: "Anonymous Middleware"}
|
|
79
|
+
assert_equal expected, actual
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def diff_lines(old_lines, new_lines)
|
|
84
|
+
file_length_difference = 0
|
|
85
|
+
previous_hunk = nil
|
|
86
|
+
output = []
|
|
87
|
+
|
|
88
|
+
diff(old_lines, new_lines).each do |piece|
|
|
89
|
+
hunk = hunk(old_lines, new_lines, piece, 3, file_length_difference)
|
|
90
|
+
file_length_difference = hunk.file_length_difference
|
|
91
|
+
maybe_contiguous_hunks = previous_hunk.nil? || hunk.merge(previous_hunk)
|
|
92
|
+
|
|
93
|
+
output << "#{previous_hunk.diff(:unified)}\n" unless maybe_contiguous_hunks
|
|
94
|
+
|
|
95
|
+
previous_hunk = hunk
|
|
96
|
+
end
|
|
97
|
+
output << "#{previous_hunk.diff(:unified, true)}\n" unless previous_hunk.nil?
|
|
98
|
+
output.join
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def test_issue_65_should_not_misplace_new_chunk
|
|
102
|
+
old_data = [
|
|
103
|
+
"recipe[a::default]", "recipe[b::default]", "recipe[c::default]",
|
|
104
|
+
"recipe[d::default]", "recipe[e::default]", "recipe[f::default]",
|
|
105
|
+
"recipe[g::default]", "recipe[h::default]", "recipe[i::default]",
|
|
106
|
+
"recipe[j::default]", "recipe[k::default]", "recipe[l::default]",
|
|
107
|
+
"recipe[m::default]", "recipe[n::default]"
|
|
108
|
+
]
|
|
109
|
+
|
|
110
|
+
new_data = [
|
|
111
|
+
"recipe[a::default]", "recipe[c::default]", "recipe[d::default]",
|
|
112
|
+
"recipe[e::default]", "recipe[f::default]", "recipe[g::default]",
|
|
113
|
+
"recipe[h::default]", "recipe[i::default]", "recipe[j::default]",
|
|
114
|
+
"recipe[k::default]", "recipe[l::default]", "recipe[m::default]",
|
|
115
|
+
"recipe[n::default]", "recipe[o::new]", "recipe[p::new]",
|
|
116
|
+
"recipe[q::new]", "recipe[r::new]"
|
|
117
|
+
]
|
|
118
|
+
|
|
119
|
+
expected = <<~EODIFF
|
|
120
|
+
@@ -1,5 +1,4 @@
|
|
121
|
+
recipe[a::default]
|
|
122
|
+
-recipe[b::default]
|
|
123
|
+
recipe[c::default]
|
|
124
|
+
recipe[d::default]
|
|
125
|
+
recipe[e::default]
|
|
126
|
+
@@ -12,3 +11,7 @@
|
|
127
|
+
recipe[l::default]
|
|
128
|
+
recipe[m::default]
|
|
129
|
+
recipe[n::default]
|
|
130
|
+
+recipe[o::new]
|
|
131
|
+
+recipe[p::new]
|
|
132
|
+
+recipe[q::new]
|
|
133
|
+
+recipe[r::new]
|
|
134
|
+
EODIFF
|
|
135
|
+
|
|
136
|
+
assert_equal expected, diff_lines(old_data, new_data)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def test_issue_107_should_produce_unified_output_with_correct_context
|
|
140
|
+
old_data = <<~DATA_OLD.strip.split("\n").map(&:chomp)
|
|
141
|
+
{
|
|
142
|
+
"name": "x",
|
|
143
|
+
"description": "hi"
|
|
144
|
+
}
|
|
145
|
+
DATA_OLD
|
|
146
|
+
|
|
147
|
+
new_data = <<~DATA_NEW.strip.split("\n").map(&:chomp)
|
|
148
|
+
{
|
|
149
|
+
"name": "x",
|
|
150
|
+
"description": "lo"
|
|
151
|
+
}
|
|
152
|
+
DATA_NEW
|
|
153
|
+
|
|
154
|
+
diff = diff(old_data, new_data)
|
|
155
|
+
hunk = hunk(old_data, new_data, diff.first, 3, 0)
|
|
156
|
+
|
|
157
|
+
expected = <<~EXPECTED.chomp
|
|
158
|
+
@@ -1,4 +1,4 @@
|
|
159
|
+
{
|
|
160
|
+
"name": "x",
|
|
161
|
+
- "description": "hi"
|
|
162
|
+
+ "description": "lo"
|
|
163
|
+
}
|
|
164
|
+
EXPECTED
|
|
165
|
+
|
|
166
|
+
assert_equal expected, hunk.diff(:unified)
|
|
167
|
+
end
|
|
168
|
+
end
|
data/test/test_lcs.rb
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "test_helper"
|
|
4
|
+
|
|
5
|
+
class TestLCSInternals < Minitest::Test
|
|
6
|
+
def test_returns_meaningful_lcs_array_with_seq1_seq2
|
|
7
|
+
res = internal_lcs(seq1, seq2)
|
|
8
|
+
assert_equal correct_lcs.size, res.compact.size
|
|
9
|
+
assert_correctly_maps_sequence(res, seq1, seq2)
|
|
10
|
+
|
|
11
|
+
x_seq1 = (0...res.size).map { |ix| res[ix] ? seq1[ix] : nil }.compact
|
|
12
|
+
x_seq2 = (0...res.size).map { |ix| res[ix] ? seq2[res[ix]] : nil }.compact
|
|
13
|
+
|
|
14
|
+
assert_equal correct_lcs, x_seq1
|
|
15
|
+
assert_equal correct_lcs, x_seq2
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_returns_all_indexes_with_hello_hello
|
|
19
|
+
assert_equal (0...hello.size).to_a, internal_lcs(hello, hello)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_returns_all_indexes_with_hello_ary_hello_ary
|
|
23
|
+
assert_equal (0...hello_ary.size).to_a, internal_lcs(hello_ary, hello_ary)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
class TestLCS < Minitest::Test
|
|
28
|
+
def test_returns_correct_compacted_values
|
|
29
|
+
res = lcs(seq1, seq2)
|
|
30
|
+
assert_equal correct_lcs, res
|
|
31
|
+
assert_equal res, res.compact
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_is_transitive
|
|
35
|
+
res = lcs(seq2, seq1)
|
|
36
|
+
assert_equal correct_lcs, res
|
|
37
|
+
assert_equal res, res.compact
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_returns_hello_chars_with_hello_hello
|
|
41
|
+
assert_equal hello.chars, lcs(hello, hello)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_returns_hello_ary_with_hello_ary_hello_ary
|
|
45
|
+
assert_equal hello_ary, lcs(hello_ary, hello_ary)
|
|
46
|
+
end
|
|
47
|
+
end
|
data/test/test_ldiff.rb
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class TestLdiff < Minitest::Test
|
|
6
|
+
FIXTURES = [
|
|
7
|
+
{name: "diff", left: "aX", right: "bXaX", diff: 1},
|
|
8
|
+
{name: "diff.missing_new_line1", left: "four_lines", right: "four_lines_with_missing_new_line", diff: 1},
|
|
9
|
+
{name: "diff.missing_new_line2", left: "four_lines_with_missing_new_line", right: "four_lines", diff: 1},
|
|
10
|
+
{name: "diff.issue95_trailing_context", left: "123_x", right: "456_x", diff: 1},
|
|
11
|
+
{name: "diff.four_lines.vs.empty", left: "four_lines", right: "empty", diff: 1},
|
|
12
|
+
{name: "diff.empty.vs.four_lines", left: "empty", right: "four_lines", diff: 1},
|
|
13
|
+
{name: "diff.bin1", left: "file1.bin", right: "file1.bin", diff: 0},
|
|
14
|
+
{name: "diff.bin2", left: "file1.bin", right: "file2.bin", diff: 1},
|
|
15
|
+
{name: "diff.chef", left: "old-chef", right: "new-chef", diff: 1},
|
|
16
|
+
{name: "diff.chef2", left: "old-chef2", right: "new-chef2", diff: 1}
|
|
17
|
+
].product([nil, "-c", "-u"]).map { |(fixture, flag)|
|
|
18
|
+
fixture = fixture.dup
|
|
19
|
+
fixture[:flag] = flag
|
|
20
|
+
fixture
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
FIXTURES.each do |fixture|
|
|
24
|
+
test_name = "test_ldiff_#{fixture[:name]}_#{fixture[:flag] || "default"}"
|
|
25
|
+
.tr(".", "_")
|
|
26
|
+
.tr("-", "_")
|
|
27
|
+
|
|
28
|
+
define_method(test_name) do
|
|
29
|
+
stdout, stderr, status = run_ldiff(fixture)
|
|
30
|
+
assert_equal fixture[:diff], status
|
|
31
|
+
assert_equal read_fixture(fixture, mode: "error", allow_missing: true), stderr
|
|
32
|
+
assert_equal read_fixture(fixture, mode: "output", allow_missing: false), stdout
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
def read_fixture(options, mode: "output", allow_missing: false)
|
|
39
|
+
fixture = options.fetch(:name)
|
|
40
|
+
flag = options.fetch(:flag)
|
|
41
|
+
name = "test/fixtures/ldiff/#{mode}.#{fixture}#{flag}"
|
|
42
|
+
|
|
43
|
+
return "" if !::File.exist?(name) && allow_missing
|
|
44
|
+
|
|
45
|
+
data = IO.__send__(IO.respond_to?(:binread) ? :binread : :read, name)
|
|
46
|
+
clean_data(data, flag)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def clean_data(data, flag)
|
|
50
|
+
data =
|
|
51
|
+
case flag
|
|
52
|
+
when "-c", "-u"
|
|
53
|
+
clean_output_timestamp(data)
|
|
54
|
+
else
|
|
55
|
+
data
|
|
56
|
+
end
|
|
57
|
+
data.gsub(/\r\n?/, "\n")
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def clean_output_timestamp(data)
|
|
61
|
+
data.gsub(
|
|
62
|
+
%r{
|
|
63
|
+
^
|
|
64
|
+
[-+*]{3}
|
|
65
|
+
\s*
|
|
66
|
+
test/fixtures/(\S+)
|
|
67
|
+
\s*
|
|
68
|
+
\d{4}-\d\d-\d\d
|
|
69
|
+
\s*
|
|
70
|
+
\d\d:\d\d:\d\d(?:\.\d+)
|
|
71
|
+
\s*
|
|
72
|
+
(?:[-+]\d{4}|Z)
|
|
73
|
+
}x,
|
|
74
|
+
'*** test/fixtures/\1 0000-00-00 :00 =>:00 =>00.000000000 -0000'
|
|
75
|
+
)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def run_ldiff(options)
|
|
79
|
+
flag = options.fetch(:flag)
|
|
80
|
+
left = options.fetch(:left)
|
|
81
|
+
right = options.fetch(:right)
|
|
82
|
+
|
|
83
|
+
stdout, stderr = capture_subprocess_io do
|
|
84
|
+
system("ruby -Ilib bin/ldiff #{flag} test/fixtures/#{left} test/fixtures/#{right}")
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
[clean_data(stdout, flag), stderr, $?.exitstatus]
|
|
88
|
+
end
|
|
89
|
+
end
|
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
|