hashdiff 0.3.4 → 0.4.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/.rubocop.yml +24 -0
- data/.travis.yml +6 -5
- data/Gemfile +3 -1
- data/README.md +94 -29
- data/Rakefile +9 -4
- data/changelog.md +28 -3
- data/hashdiff.gemspec +27 -12
- data/lib/hashdiff/compare_hashes.rb +56 -0
- data/lib/hashdiff/diff.rb +65 -111
- data/lib/hashdiff/lcs.rb +27 -30
- data/lib/hashdiff/lcs_compare_arrays.rb +32 -0
- data/lib/hashdiff/linear_compare_array.rb +159 -0
- data/lib/hashdiff/patch.rb +16 -12
- data/lib/hashdiff/util.rb +59 -37
- data/lib/hashdiff/version.rb +4 -2
- data/lib/hashdiff.rb +9 -0
- data/spec/hashdiff/best_diff_spec.rb +47 -37
- data/spec/hashdiff/diff_array_spec.rb +19 -19
- data/spec/hashdiff/diff_spec.rb +217 -139
- data/spec/hashdiff/lcs_spec.rb +27 -26
- data/spec/hashdiff/linear_compare_array_spec.rb +50 -0
- data/spec/hashdiff/patch_spec.rb +129 -105
- data/spec/hashdiff/util_spec.rb +60 -43
- data/spec/spec_helper.rb +2 -0
- metadata +50 -11
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Hashdiff::LinearCompareArray do
|
6
|
+
it 'finds no differences between two empty arrays' do
|
7
|
+
difference = described_class.call([], [])
|
8
|
+
difference.should == []
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'finds added items when the old array is empty' do
|
12
|
+
difference = described_class.call([], %i[a b])
|
13
|
+
difference.should == [['+', '[0]', :a], ['+', '[1]', :b]]
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'finds removed items when the new array is empty' do
|
17
|
+
difference = described_class.call(%i[a b], [])
|
18
|
+
difference.should == [['-', '[1]', :b], ['-', '[0]', :a]]
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'finds no differences between identical arrays' do
|
22
|
+
difference = described_class.call(%i[a b], %i[a b])
|
23
|
+
difference.should == []
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'finds added items in an array' do
|
27
|
+
difference = described_class.call(%i[a d], %i[a b c d])
|
28
|
+
difference.should == [['+', '[1]', :b], ['+', '[2]', :c]]
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'finds removed items in an array' do
|
32
|
+
difference = described_class.call(%i[a b c d e f], %i[a d f])
|
33
|
+
difference.should == [['-', '[4]', :e], ['-', '[2]', :c], ['-', '[1]', :b]]
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'shows additions and deletions as changed items' do
|
37
|
+
difference = described_class.call(%i[a b c], %i[c b a])
|
38
|
+
difference.should == [['~', '[0]', :a, :c], ['~', '[2]', :c, :a]]
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'shows changed items in a hash' do
|
42
|
+
difference = described_class.call([{ a: :b }], [{ a: :c }])
|
43
|
+
difference.should == [['~', '[0].a', :b, :c]]
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'shows changed items and added items' do
|
47
|
+
difference = described_class.call([{ a: 1, b: 2 }], [{ a: 2, b: 2 }, :item])
|
48
|
+
difference.should == [['~', '[0].a', 1, 2], ['+', '[1]', :item]]
|
49
|
+
end
|
50
|
+
end
|
data/spec/hashdiff/patch_spec.rb
CHANGED
@@ -1,161 +1,185 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe
|
4
|
-
it
|
5
|
-
a = {
|
6
|
-
b = {
|
7
|
-
diff =
|
5
|
+
describe Hashdiff do
|
6
|
+
it 'is able to patch key addition' do
|
7
|
+
a = { 'a' => 3, 'c' => 11, 'd' => 45, 'e' => 100, 'f' => 200 }
|
8
|
+
b = { 'a' => 3, 'c' => 11, 'd' => 45, 'e' => 100, 'f' => 200, 'g' => 300 }
|
9
|
+
diff = described_class.diff(a, b)
|
8
10
|
|
9
|
-
|
11
|
+
expect(described_class.patch!(a, diff)).to eq(b)
|
10
12
|
|
11
|
-
a = {
|
12
|
-
b = {
|
13
|
-
|
13
|
+
a = { 'a' => 3, 'c' => 11, 'd' => 45, 'e' => 100, 'f' => 200 }
|
14
|
+
b = { 'a' => 3, 'c' => 11, 'd' => 45, 'e' => 100, 'f' => 200, 'g' => 300 }
|
15
|
+
described_class.unpatch!(b, diff).should == a
|
14
16
|
end
|
15
17
|
|
16
|
-
it
|
17
|
-
a = {
|
18
|
-
b = {
|
19
|
-
diff =
|
18
|
+
it 'is able to patch value type changes' do
|
19
|
+
a = { 'a' => 3 }
|
20
|
+
b = { 'a' => { 'a1' => 1, 'a2' => 2 } }
|
21
|
+
diff = described_class.diff(a, b)
|
20
22
|
|
21
|
-
|
23
|
+
expect(described_class.patch!(a, diff)).to eq(b)
|
22
24
|
|
23
|
-
a = {
|
24
|
-
b = {
|
25
|
-
|
25
|
+
a = { 'a' => 3 }
|
26
|
+
b = { 'a' => { 'a1' => 1, 'a2' => 2 } }
|
27
|
+
described_class.unpatch!(b, diff).should == a
|
26
28
|
end
|
27
29
|
|
28
|
-
it
|
29
|
-
a = {
|
30
|
-
b = {
|
31
|
-
diff =
|
30
|
+
it 'is able to patch value array <=> []' do
|
31
|
+
a = { 'a' => 1, 'b' => [1, 2] }
|
32
|
+
b = { 'a' => 1, 'b' => [] }
|
33
|
+
diff = described_class.diff(a, b)
|
32
34
|
|
33
|
-
|
35
|
+
expect(described_class.patch!(a, diff)).to eq(b)
|
34
36
|
|
35
|
-
a = {
|
36
|
-
b = {
|
37
|
-
|
37
|
+
a = { 'a' => 1, 'b' => [1, 2] }
|
38
|
+
b = { 'a' => 1, 'b' => [] }
|
39
|
+
described_class.unpatch!(b, diff).should == a
|
38
40
|
end
|
39
41
|
|
40
|
-
it
|
41
|
-
a = {
|
42
|
-
b = {
|
43
|
-
diff =
|
42
|
+
it 'is able to patch value array <=> nil' do
|
43
|
+
a = { 'a' => 1, 'b' => [1, 2] }
|
44
|
+
b = { 'a' => 1, 'b' => nil }
|
45
|
+
diff = described_class.diff(a, b)
|
44
46
|
|
45
|
-
|
47
|
+
expect(described_class.patch!(a, diff)).to eq(b)
|
46
48
|
|
47
|
-
a = {
|
48
|
-
b = {
|
49
|
-
|
49
|
+
a = { 'a' => 1, 'b' => [1, 2] }
|
50
|
+
b = { 'a' => 1, 'b' => nil }
|
51
|
+
described_class.unpatch!(b, diff).should == a
|
50
52
|
end
|
51
53
|
|
52
|
-
it
|
53
|
-
a = {
|
54
|
-
b = {
|
55
|
-
diff =
|
54
|
+
it 'is able to patch array value removal' do
|
55
|
+
a = { 'a' => 1, 'b' => [1, 2] }
|
56
|
+
b = { 'a' => 1 }
|
57
|
+
diff = described_class.diff(a, b)
|
56
58
|
|
57
|
-
|
59
|
+
expect(described_class.patch!(a, diff)).to eq(b)
|
58
60
|
|
59
|
-
a = {
|
60
|
-
b = {
|
61
|
-
|
61
|
+
a = { 'a' => 1, 'b' => [1, 2] }
|
62
|
+
b = { 'a' => 1 }
|
63
|
+
described_class.unpatch!(b, diff).should == a
|
62
64
|
end
|
63
65
|
|
64
|
-
it
|
65
|
-
a = {
|
66
|
-
b = {
|
67
|
-
diff =
|
66
|
+
it 'is able to patch array under hash key with non-word characters' do
|
67
|
+
a = { 'a' => 1, 'b-b' => [1, 2] }
|
68
|
+
b = { 'a' => 1, 'b-b' => [2, 1] }
|
69
|
+
diff = described_class.diff(a, b)
|
68
70
|
|
69
|
-
|
71
|
+
expect(described_class.patch!(a, diff)).to eq(b)
|
70
72
|
|
71
|
-
a = {
|
72
|
-
b = {
|
73
|
-
|
73
|
+
a = { 'a' => 1, 'b-b' => [1, 2] }
|
74
|
+
b = { 'a' => 1, 'b-b' => [2, 1] }
|
75
|
+
described_class.unpatch!(b, diff).should == a
|
74
76
|
end
|
75
77
|
|
76
|
-
it
|
77
|
-
a = {
|
78
|
-
b = {
|
79
|
-
diff =
|
78
|
+
it 'is able to patch hash value removal' do
|
79
|
+
a = { 'a' => 1, 'b' => { 'b1' => 1, 'b2' => 2 } }
|
80
|
+
b = { 'a' => 1 }
|
81
|
+
diff = described_class.diff(a, b)
|
80
82
|
|
81
|
-
|
83
|
+
expect(described_class.patch!(a, diff)).to eq(b)
|
82
84
|
|
83
|
-
a = {
|
84
|
-
b = {
|
85
|
-
|
85
|
+
a = { 'a' => 1, 'b' => { 'b1' => 1, 'b2' => 2 } }
|
86
|
+
b = { 'a' => 1 }
|
87
|
+
described_class.unpatch!(b, diff).should == a
|
86
88
|
end
|
87
89
|
|
88
|
-
it
|
89
|
-
a = {
|
90
|
-
b = {
|
91
|
-
diff =
|
90
|
+
it 'is able to patch value hash <=> {}' do
|
91
|
+
a = { 'a' => 1, 'b' => { 'b1' => 1, 'b2' => 2 } }
|
92
|
+
b = { 'a' => 1, 'b' => {} }
|
93
|
+
diff = described_class.diff(a, b)
|
92
94
|
|
93
|
-
|
95
|
+
expect(described_class.patch!(a, diff)).to eq(b)
|
94
96
|
|
95
|
-
a = {
|
96
|
-
b = {
|
97
|
-
|
97
|
+
a = { 'a' => 1, 'b' => { 'b1' => 1, 'b2' => 2 } }
|
98
|
+
b = { 'a' => 1, 'b' => {} }
|
99
|
+
described_class.unpatch!(b, diff).should == a
|
98
100
|
end
|
99
101
|
|
100
|
-
it
|
101
|
-
a = {
|
102
|
-
b = {
|
103
|
-
diff =
|
102
|
+
it 'is able to patch value hash <=> nil' do
|
103
|
+
a = { 'a' => 1, 'b' => { 'b1' => 1, 'b2' => 2 } }
|
104
|
+
b = { 'a' => 1, 'b' => nil }
|
105
|
+
diff = described_class.diff(a, b)
|
104
106
|
|
105
|
-
|
107
|
+
expect(described_class.patch!(a, diff)).to eq(b)
|
106
108
|
|
107
|
-
a = {
|
108
|
-
b = {
|
109
|
-
|
109
|
+
a = { 'a' => 1, 'b' => { 'b1' => 1, 'b2' => 2 } }
|
110
|
+
b = { 'a' => 1, 'b' => nil }
|
111
|
+
described_class.unpatch!(b, diff).should == a
|
110
112
|
end
|
111
113
|
|
112
|
-
it
|
113
|
-
a = {
|
114
|
-
b = {
|
115
|
-
diff =
|
114
|
+
it 'is able to patch value nil removal' do
|
115
|
+
a = { 'a' => 1, 'b' => nil }
|
116
|
+
b = { 'a' => 1 }
|
117
|
+
diff = described_class.diff(a, b)
|
116
118
|
|
117
|
-
|
119
|
+
expect(described_class.patch!(a, diff)).to eq(b)
|
118
120
|
|
119
|
-
a = {
|
120
|
-
b = {
|
121
|
-
|
121
|
+
a = { 'a' => 1, 'b' => nil }
|
122
|
+
b = { 'a' => 1 }
|
123
|
+
described_class.unpatch!(b, diff).should == a
|
122
124
|
end
|
123
125
|
|
124
|
-
it
|
125
|
-
a = [{'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5}, 3]
|
126
|
-
b = [1, {'a' => 1, 'b' => 2, 'c' => 3, 'e' => 5}]
|
126
|
+
it 'is able to patch similar objects between arrays' do
|
127
|
+
a = [{ 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5 }, 3]
|
128
|
+
b = [1, { 'a' => 1, 'b' => 2, 'c' => 3, 'e' => 5 }]
|
127
129
|
|
128
|
-
diff =
|
129
|
-
|
130
|
+
diff = described_class.diff(a, b)
|
131
|
+
expect(described_class.patch!(a, diff)).to eq(b)
|
130
132
|
|
131
|
-
a = [{'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5}, 3]
|
132
|
-
b = [1, {'a' => 1, 'b' => 2, 'c' => 3, 'e' => 5}]
|
133
|
-
|
133
|
+
a = [{ 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5 }, 3]
|
134
|
+
b = [1, { 'a' => 1, 'b' => 2, 'c' => 3, 'e' => 5 }]
|
135
|
+
described_class.unpatch!(b, diff).should == a
|
134
136
|
end
|
135
137
|
|
136
|
-
it
|
137
|
-
a = [{'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5}, {'x' => 5, 'y' => 6, 'z' => 3}, 1]
|
138
|
-
b = [1, {'a' => 1, 'b' => 2, 'c' => 3, 'e' => 5}]
|
138
|
+
it 'is able to patch similar & equal objects between arrays' do
|
139
|
+
a = [{ 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5 }, { 'x' => 5, 'y' => 6, 'z' => 3 }, 1]
|
140
|
+
b = [1, { 'a' => 1, 'b' => 2, 'c' => 3, 'e' => 5 }]
|
139
141
|
|
140
|
-
diff =
|
141
|
-
|
142
|
+
diff = described_class.diff(a, b)
|
143
|
+
expect(described_class.patch!(a, diff)).to eq(b)
|
142
144
|
|
143
|
-
a = [{'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5}, {'x' => 5, 'y' => 6, 'z' => 3}, 1]
|
144
|
-
b = [1, {'a' => 1, 'b' => 2, 'c' => 3, 'e' => 5}]
|
145
|
-
|
145
|
+
a = [{ 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5 }, { 'x' => 5, 'y' => 6, 'z' => 3 }, 1]
|
146
|
+
b = [1, { 'a' => 1, 'b' => 2, 'c' => 3, 'e' => 5 }]
|
147
|
+
described_class.unpatch!(b, diff).should == a
|
146
148
|
end
|
147
149
|
|
148
|
-
it
|
149
|
-
a = {
|
150
|
-
b = {
|
151
|
-
diff =
|
150
|
+
it 'is able to patch hash value removal with custom delimiter' do
|
151
|
+
a = { 'a' => 1, 'b' => { 'b1' => 1, 'b2' => 2 } }
|
152
|
+
b = { 'a' => 1, 'b' => { 'b1' => 3 } }
|
153
|
+
diff = described_class.diff(a, b, delimiter: "\n")
|
152
154
|
|
153
|
-
|
155
|
+
expect(described_class.patch!(a, diff, delimiter: "\n")).to eq(b)
|
154
156
|
|
155
|
-
a = {
|
156
|
-
b = {
|
157
|
-
|
157
|
+
a = { 'a' => 1, 'b' => { 'b1' => 1, 'b2' => 2 } }
|
158
|
+
b = { 'a' => 1, 'b' => { 'b1' => 3 } }
|
159
|
+
described_class.unpatch!(b, diff, delimiter: "\n").should == a
|
158
160
|
end
|
159
161
|
|
162
|
+
it 'is able to patch when the diff is generated with an array_path' do
|
163
|
+
a = { 'a' => 1, 'b' => 1 }
|
164
|
+
b = { 'a' => 1, 'b' => 2 }
|
165
|
+
diff = described_class.diff(a, b, array_path: true)
|
166
|
+
|
167
|
+
expect(described_class.patch!(a, diff)).to eq(b)
|
168
|
+
|
169
|
+
a = { 'a' => 1, 'b' => 1 }
|
170
|
+
b = { 'a' => 1, 'b' => 2 }
|
171
|
+
described_class.unpatch!(b, diff).should == a
|
172
|
+
end
|
160
173
|
|
174
|
+
it 'is able to use non string keys when diff is generated with an array_path' do
|
175
|
+
a = { 'a' => 1, :a => 2, 0 => 3 }
|
176
|
+
b = { 'a' => 5, :a => 6, 0 => 7 }
|
177
|
+
diff = described_class.diff(a, b, array_path: true)
|
178
|
+
|
179
|
+
expect(described_class.patch!(a, diff)).to eq(b)
|
180
|
+
|
181
|
+
a = { 'a' => 1, :a => 2, 0 => 3 }
|
182
|
+
b = { 'a' => 5, :a => 6, 0 => 7 }
|
183
|
+
described_class.unpatch!(b, diff).should == a
|
184
|
+
end
|
161
185
|
end
|
data/spec/hashdiff/util_spec.rb
CHANGED
@@ -1,78 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe
|
4
|
-
it
|
5
|
-
decoded =
|
5
|
+
describe Hashdiff do
|
6
|
+
it 'is able to decode property path' do
|
7
|
+
decoded = described_class.send(:decode_property_path, 'a.b[0].c.city[5]')
|
6
8
|
decoded.should == ['a', 'b', 0, 'c', 'city', 5]
|
7
9
|
end
|
8
10
|
|
9
|
-
it
|
10
|
-
decoded =
|
11
|
+
it 'is able to decode property path with custom delimiter' do
|
12
|
+
decoded = described_class.send(:decode_property_path, "a\tb[0]\tc\tcity[5]", "\t")
|
11
13
|
decoded.should == ['a', 'b', 0, 'c', 'city', 5]
|
12
14
|
end
|
13
15
|
|
14
|
-
it
|
15
|
-
a = {'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5}
|
16
|
-
b = {'a' => 1, 'b' => 2, 'c' => 3, 'e' => 5}
|
17
|
-
|
18
|
-
|
16
|
+
it 'is able to tell similiar hash' do
|
17
|
+
a = { 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5 }
|
18
|
+
b = { 'a' => 1, 'b' => 2, 'c' => 3, 'e' => 5 }
|
19
|
+
described_class.similar?(a, b).should be true
|
20
|
+
described_class.similar?(a, b, similarity: 1).should be false
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'is able to tell similiar empty hash' do
|
24
|
+
described_class.similar?({}, {}, similarity: 1).should be true
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'is able to tell similiar empty array' do
|
28
|
+
described_class.similar?([], [], similarity: 1).should be true
|
19
29
|
end
|
20
30
|
|
21
|
-
it
|
22
|
-
a = {'a' => 1.5, 'b' => 2.25, 'c' => 3, 'd' => 4, 'e' => 5}
|
23
|
-
b = {'a' => 1.503, 'b' => 2.22, 'c' => 3, 'e' => 5}
|
24
|
-
|
25
|
-
|
31
|
+
it 'is able to tell similiar hash with values within tolerance' do
|
32
|
+
a = { 'a' => 1.5, 'b' => 2.25, 'c' => 3, 'd' => 4, 'e' => 5 }
|
33
|
+
b = { 'a' => 1.503, 'b' => 2.22, 'c' => 3, 'e' => 5 }
|
34
|
+
described_class.similar?(a, b, numeric_tolerance: 0.05).should be true
|
35
|
+
described_class.similar?(a, b).should be false
|
26
36
|
end
|
27
37
|
|
28
|
-
it
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
38
|
+
it 'is able to tell numbers and strings' do
|
39
|
+
described_class.similar?(1, 2).should be false
|
40
|
+
described_class.similar?('a', 'b').should be false
|
41
|
+
described_class.similar?('a', [1, 2, 3]).should be false
|
42
|
+
described_class.similar?(1, 'a' => 1, 'b' => 2, 'c' => 3, 'e' => 5).should be false
|
33
43
|
end
|
34
44
|
|
35
|
-
it
|
36
|
-
a = {
|
37
|
-
b = {
|
45
|
+
it 'is able to tell true when similarity == 0.5' do
|
46
|
+
a = { 'value' => 'New1', 'onclick' => 'CreateNewDoc()' }
|
47
|
+
b = { 'value' => 'New', 'onclick' => 'CreateNewDoc()' }
|
38
48
|
|
39
|
-
|
49
|
+
described_class.similar?(a, b, similarity: 0.5).should be true
|
40
50
|
end
|
41
51
|
|
42
|
-
it
|
43
|
-
a = {
|
44
|
-
b = {
|
52
|
+
it 'is able to tell false when similarity == 0.5' do
|
53
|
+
a = { 'value' => 'New1', 'onclick' => 'open()' }
|
54
|
+
b = { 'value' => 'New', 'onclick' => 'CreateNewDoc()' }
|
45
55
|
|
46
|
-
|
56
|
+
described_class.similar?(a, b, similarity: 0.5).should be false
|
47
57
|
end
|
48
58
|
|
49
59
|
describe '.compare_values' do
|
50
|
-
it
|
51
|
-
expect(
|
60
|
+
it 'compares numeric values exactly when no tolerance' do
|
61
|
+
expect(described_class.compare_values(10.004, 10.003)).to be false
|
52
62
|
end
|
53
63
|
|
54
|
-
it
|
55
|
-
expect(
|
64
|
+
it 'allows tolerance with numeric values' do
|
65
|
+
expect(described_class.compare_values(10.004, 10.003, numeric_tolerance: 0.01)).to be true
|
56
66
|
end
|
57
67
|
|
58
|
-
it
|
59
|
-
expect(
|
60
|
-
|
61
|
-
|
68
|
+
it 'compares different objects without tolerance' do
|
69
|
+
expect(described_class.compare_values('hats', 'ninjas')).to be false
|
70
|
+
end
|
71
|
+
it 'compares other objects with tolerance' do
|
72
|
+
expect(described_class.compare_values('hats', 'ninjas', numeric_tolerance: 0.01)).to be false
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'compares same objects without tolerance' do
|
76
|
+
expect(described_class.compare_values('horse', 'horse')).to be true
|
62
77
|
end
|
63
78
|
|
64
|
-
it '
|
65
|
-
expect(
|
66
|
-
expect(HashDiff.compare_values('horse', 'Horse')).to be false
|
79
|
+
it 'compares strings for spaces exactly by default' do
|
80
|
+
expect(described_class.compare_values(' horse', 'horse')).to be false
|
67
81
|
end
|
68
82
|
|
69
|
-
it '
|
70
|
-
expect(
|
83
|
+
it 'compares strings for capitalization exactly by default' do
|
84
|
+
expect(described_class.compare_values('horse', 'Horse')).to be false
|
71
85
|
end
|
72
86
|
|
73
|
-
it
|
74
|
-
expect(
|
87
|
+
it 'strips strings before comparing when requested' do
|
88
|
+
expect(described_class.compare_values(' horse', 'horse', strip: true)).to be true
|
75
89
|
end
|
76
90
|
|
91
|
+
it 'ignores string case when requested' do
|
92
|
+
expect(described_class.compare_values('horse', 'Horse', case_insensitive: true)).to be true
|
93
|
+
end
|
77
94
|
end
|
78
95
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashdiff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Liu Fengyun
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bluecloth
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rspec
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -25,7 +39,7 @@ dependencies:
|
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: '2.0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
42
|
+
name: rubocop
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - ">="
|
@@ -39,7 +53,21 @@ dependencies:
|
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
56
|
+
name: rubocop-rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: yard
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
44
72
|
requirements:
|
45
73
|
- - ">="
|
@@ -52,7 +80,7 @@ dependencies:
|
|
52
80
|
- - ">="
|
53
81
|
- !ruby/object:Gem::Version
|
54
82
|
version: '0'
|
55
|
-
description: "
|
83
|
+
description: " Hashdiff is a diff lib to compute the smallest difference between two
|
56
84
|
hashes. "
|
57
85
|
email:
|
58
86
|
- liufengyunchina@gmail.com
|
@@ -62,6 +90,7 @@ extra_rdoc_files: []
|
|
62
90
|
files:
|
63
91
|
- ".gitignore"
|
64
92
|
- ".rspec"
|
93
|
+
- ".rubocop.yml"
|
65
94
|
- ".travis.yml"
|
66
95
|
- ".yardopts"
|
67
96
|
- Gemfile
|
@@ -71,8 +100,11 @@ files:
|
|
71
100
|
- changelog.md
|
72
101
|
- hashdiff.gemspec
|
73
102
|
- lib/hashdiff.rb
|
103
|
+
- lib/hashdiff/compare_hashes.rb
|
74
104
|
- lib/hashdiff/diff.rb
|
75
105
|
- lib/hashdiff/lcs.rb
|
106
|
+
- lib/hashdiff/lcs_compare_arrays.rb
|
107
|
+
- lib/hashdiff/linear_compare_array.rb
|
76
108
|
- lib/hashdiff/patch.rb
|
77
109
|
- lib/hashdiff/util.rb
|
78
110
|
- lib/hashdiff/version.rb
|
@@ -80,14 +112,22 @@ files:
|
|
80
112
|
- spec/hashdiff/diff_array_spec.rb
|
81
113
|
- spec/hashdiff/diff_spec.rb
|
82
114
|
- spec/hashdiff/lcs_spec.rb
|
115
|
+
- spec/hashdiff/linear_compare_array_spec.rb
|
83
116
|
- spec/hashdiff/patch_spec.rb
|
84
117
|
- spec/hashdiff/util_spec.rb
|
85
118
|
- spec/spec_helper.rb
|
86
119
|
homepage: https://github.com/liufengyun/hashdiff
|
87
120
|
licenses:
|
88
121
|
- MIT
|
89
|
-
metadata:
|
90
|
-
|
122
|
+
metadata:
|
123
|
+
bug_tracker_uri: https://github.com/liufengyun/hashdiff/issues
|
124
|
+
changelog_uri: https://github.com/liufengyun/hashdiff/blob/master/changelog.md
|
125
|
+
documentation_uri: https://www.rubydoc.info/gems/hashdiff
|
126
|
+
homepage_uri: https://github.com/liufengyun/hashdiff
|
127
|
+
source_code_uri: https://github.com/liufengyun/hashdiff
|
128
|
+
post_install_message: The HashDiff constant used by this gem conflicts with another
|
129
|
+
gem of a similar name. As of version 1.0 the HashDiff constant will be completely
|
130
|
+
removed and replaced by Hashdiff. For more information see https://github.com/liufengyun/hashdiff/issues/45.
|
91
131
|
rdoc_options: []
|
92
132
|
require_paths:
|
93
133
|
- lib
|
@@ -95,7 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
135
|
requirements:
|
96
136
|
- - ">="
|
97
137
|
- !ruby/object:Gem::Version
|
98
|
-
version:
|
138
|
+
version: 2.0.0
|
99
139
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
140
|
requirements:
|
101
141
|
- - ">="
|
@@ -103,9 +143,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
143
|
version: '0'
|
104
144
|
requirements: []
|
105
145
|
rubyforge_project:
|
106
|
-
rubygems_version: 2.5.
|
146
|
+
rubygems_version: 2.5.2.3
|
107
147
|
signing_key:
|
108
148
|
specification_version: 4
|
109
|
-
summary:
|
149
|
+
summary: Hashdiff is a diff lib to compute the smallest difference between two hashes.
|
110
150
|
test_files: []
|
111
|
-
has_rdoc:
|