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.
@@ -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
@@ -1,161 +1,185 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
- describe HashDiff do
4
- it "it should be able to patch key addition" do
5
- a = {"a"=>3, "c"=>11, "d"=>45, "e"=>100, "f"=>200}
6
- b = {"a"=>3, "c"=>11, "d"=>45, "e"=>100, "f"=>200, "g"=>300}
7
- diff = HashDiff.diff(a, b)
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
- HashDiff.patch!(a, diff).should == b
11
+ expect(described_class.patch!(a, diff)).to eq(b)
10
12
 
11
- a = {"a"=>3, "c"=>11, "d"=>45, "e"=>100, "f"=>200}
12
- b = {"a"=>3, "c"=>11, "d"=>45, "e"=>100, "f"=>200, "g"=>300}
13
- HashDiff.unpatch!(b, diff).should == a
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 "should be able to patch value type changes" do
17
- a = {"a" => 3}
18
- b = {"a" => {"a1" => 1, "a2" => 2}}
19
- diff = HashDiff.diff(a, b)
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
- HashDiff.patch!(a, diff).should == b
23
+ expect(described_class.patch!(a, diff)).to eq(b)
22
24
 
23
- a = {"a" => 3}
24
- b = {"a" => {"a1" => 1, "a2" => 2}}
25
- HashDiff.unpatch!(b, diff).should == a
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 "should be able to patch value array <=> []" do
29
- a = {"a" => 1, "b" => [1, 2]}
30
- b = {"a" => 1, "b" => []}
31
- diff = HashDiff.diff(a, b)
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
- HashDiff.patch!(a, diff).should == b
35
+ expect(described_class.patch!(a, diff)).to eq(b)
34
36
 
35
- a = {"a" => 1, "b" => [1, 2]}
36
- b = {"a" => 1, "b" => []}
37
- HashDiff.unpatch!(b, diff).should == a
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 "should be able to patch value array <=> nil" do
41
- a = {"a" => 1, "b" => [1, 2]}
42
- b = {"a" => 1, "b" => nil}
43
- diff = HashDiff.diff(a, b)
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
- HashDiff.patch!(a, diff).should == b
47
+ expect(described_class.patch!(a, diff)).to eq(b)
46
48
 
47
- a = {"a" => 1, "b" => [1, 2]}
48
- b = {"a" => 1, "b" => nil}
49
- HashDiff.unpatch!(b, diff).should == a
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 "should be able to patch array value removal" do
53
- a = {"a" => 1, "b" => [1, 2]}
54
- b = {"a" => 1}
55
- diff = HashDiff.diff(a, b)
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
- HashDiff.patch!(a, diff).should == b
59
+ expect(described_class.patch!(a, diff)).to eq(b)
58
60
 
59
- a = {"a" => 1, "b" => [1, 2]}
60
- b = {"a" => 1}
61
- HashDiff.unpatch!(b, diff).should == a
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 "should be able to patch array under hash key with non-word characters" do
65
- a = {"a" => 1, "b-b" => [1, 2]}
66
- b = {"a" => 1, "b-b" => [2, 1]}
67
- diff = HashDiff.diff(a, b)
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
- HashDiff.patch!(a, diff).should == b
71
+ expect(described_class.patch!(a, diff)).to eq(b)
70
72
 
71
- a = {"a" => 1, "b-b" => [1, 2]}
72
- b = {"a" => 1, "b-b" => [2, 1]}
73
- HashDiff.unpatch!(b, diff).should == a
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 "should be able to patch hash value removal" do
77
- a = {"a" => 1, "b" => {"b1" => 1, "b2" =>2}}
78
- b = {"a" => 1}
79
- diff = HashDiff.diff(a, b)
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
- HashDiff.patch!(a, diff).should == b
83
+ expect(described_class.patch!(a, diff)).to eq(b)
82
84
 
83
- a = {"a" => 1, "b" => {"b1" => 1, "b2" =>2}}
84
- b = {"a" => 1}
85
- HashDiff.unpatch!(b, diff).should == a
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 "should be able to patch value hash <=> {}" do
89
- a = {"a" => 1, "b" => {"b1" => 1, "b2" =>2}}
90
- b = {"a" => 1, "b" => {}}
91
- diff = HashDiff.diff(a, b)
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
- HashDiff.patch!(a, diff).should == b
95
+ expect(described_class.patch!(a, diff)).to eq(b)
94
96
 
95
- a = {"a" => 1, "b" => {"b1" => 1, "b2" =>2}}
96
- b = {"a" => 1, "b" => {}}
97
- HashDiff.unpatch!(b, diff).should == a
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 "should be able to patch value hash <=> nil" do
101
- a = {"a" => 1, "b" => {"b1" => 1, "b2" =>2}}
102
- b = {"a" => 1, "b" => nil}
103
- diff = HashDiff.diff(a, b)
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
- HashDiff.patch!(a, diff).should == b
107
+ expect(described_class.patch!(a, diff)).to eq(b)
106
108
 
107
- a = {"a" => 1, "b" => {"b1" => 1, "b2" =>2}}
108
- b = {"a" => 1, "b" => nil}
109
- HashDiff.unpatch!(b, diff).should == a
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 "should be able to patch value nil removal" do
113
- a = {"a" => 1, "b" => nil}
114
- b = {"a" => 1}
115
- diff = HashDiff.diff(a, b)
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
- HashDiff.patch!(a, diff).should == b
119
+ expect(described_class.patch!(a, diff)).to eq(b)
118
120
 
119
- a = {"a" => 1, "b" => nil}
120
- b = {"a" => 1}
121
- HashDiff.unpatch!(b, diff).should == a
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 "should be able to patch similar objects between arrays" do
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 = HashDiff.diff(a, b)
129
- HashDiff.patch!(a, diff).should == b
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
- HashDiff.unpatch!(b, diff).should == a
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 "should be able to patch similar & equal objects between arrays" do
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 = HashDiff.diff(a, b)
141
- HashDiff.patch!(a, diff).should == b
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
- HashDiff.unpatch!(b, diff).should == a
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 "should be able to patch hash value removal with custom delimiter" do
149
- a = {"a" => 1, "b" => {"b1" => 1, "b2" =>2}}
150
- b = {"a" => 1, "b" => {"b1" => 3} }
151
- diff = HashDiff.diff(a, b, :delimiter => "\n")
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
- HashDiff.patch!(a, diff, :delimiter => "\n").should == b
155
+ expect(described_class.patch!(a, diff, delimiter: "\n")).to eq(b)
154
156
 
155
- a = {"a" => 1, "b" => {"b1" => 1, "b2" =>2}}
156
- b = {"a" => 1, "b" => {"b1" => 3} }
157
- HashDiff.unpatch!(b, diff, :delimiter => "\n").should == a
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
@@ -1,78 +1,95 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
- describe HashDiff do
4
- it "should be able to decode property path" do
5
- decoded = HashDiff.send(:decode_property_path, "a.b[0].c.city[5]")
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 "should be able to decode property path with custom delimiter" do
10
- decoded = HashDiff.send(:decode_property_path, "a\tb[0]\tc\tcity[5]", "\t")
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 "should be able to tell similiar hash" do
15
- a = {'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5}
16
- b = {'a' => 1, 'b' => 2, 'c' => 3, 'e' => 5}
17
- HashDiff.similar?(a, b).should be true
18
- HashDiff.similar?(a, b, :similarity => 1).should be false
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 "should be able to tell similiar hash with values within tolerance" do
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
- HashDiff.similar?(a, b, :numeric_tolerance => 0.05).should be true
25
- HashDiff.similar?(a, b).should be false
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 "should be able to tell numbers and strings" do
29
- HashDiff.similar?(1, 2).should be false
30
- HashDiff.similar?("a", "b").should be false
31
- HashDiff.similar?("a", [1, 2, 3]).should be false
32
- HashDiff.similar?(1, {'a' => 1, 'b' => 2, 'c' => 3, 'e' => 5}).should be false
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 "should be able to tell true when similarity == 0.5" do
36
- a = {"value" => "New1", "onclick" => "CreateNewDoc()"}
37
- b = {"value" => "New", "onclick" => "CreateNewDoc()"}
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
- HashDiff.similar?(a, b, :similarity => 0.5).should be true
49
+ described_class.similar?(a, b, similarity: 0.5).should be true
40
50
  end
41
51
 
42
- it "should be able to tell false when similarity == 0.5" do
43
- a = {"value" => "New1", "onclick" => "open()"}
44
- b = {"value" => "New", "onclick" => "CreateNewDoc()"}
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
- HashDiff.similar?(a, b, :similarity => 0.5).should be false
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 "should compare numeric values exactly when no tolerance" do
51
- expect(HashDiff.compare_values(10.004, 10.003)).to be false
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 "should allow tolerance with numeric values" do
55
- expect(HashDiff.compare_values(10.004, 10.003, :numeric_tolerance => 0.01)).to be true
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 "should compare other objects with or without tolerance" do
59
- expect(HashDiff.compare_values('hats', 'ninjas')).to be false
60
- expect(HashDiff.compare_values('hats', 'ninjas', :numeric_tolerance => 0.01)).to be false
61
- expect(HashDiff.compare_values('horse', 'horse')).to be true
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 'should compare strings exactly by default' do
65
- expect(HashDiff.compare_values(' horse', 'horse')).to be false
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 'should strip strings before comparing when requested' do
70
- expect(HashDiff.compare_values(' horse', 'horse', :strip => true)).to be true
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 "should ignore string case when requested" do
74
- expect(HashDiff.compare_values('horse', 'Horse', :case_insensitive => true)).to be true
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
2
4
 
3
5
  require 'rubygems'
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.3.4
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: 2017-05-01 00:00:00.000000000 Z
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: yard
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: bluecloth
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: " HashDiff is a diff lib to compute the smallest difference between two
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
- post_install_message:
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: 1.8.7
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.1
146
+ rubygems_version: 2.5.2.3
107
147
  signing_key:
108
148
  specification_version: 4
109
- summary: HashDiff is a diff lib to compute the smallest difference between two hashes.
149
+ summary: Hashdiff is a diff lib to compute the smallest difference between two hashes.
110
150
  test_files: []
111
- has_rdoc: