hashdiff 0.3.7 → 1.0.1

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,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'README.md' do
6
+ it 'has correct examples' do
7
+ File.read('README.md').scan(/```ruby(.*?)```/m).flatten(1).each do |block|
8
+ begin
9
+ eval block # rubocop:disable Security/Eval
10
+ rescue Exception => e # rubocop:disable Lint/RescueException
11
+ raise "README.md code block:\n#{block}\n\nhas error:\n#{e}"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,78 +1,116 @@
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
62
70
  end
63
71
 
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
72
+ it 'compares other objects with tolerance' do
73
+ expect(described_class.compare_values('hats', 'ninjas', numeric_tolerance: 0.01)).to be false
67
74
  end
68
75
 
69
- it 'should strip strings before comparing when requested' do
70
- expect(HashDiff.compare_values(' horse', 'horse', :strip => true)).to be true
76
+ it 'compares same objects without tolerance' do
77
+ expect(described_class.compare_values('horse', 'horse')).to be true
71
78
  end
72
79
 
73
- it "should ignore string case when requested" do
74
- expect(HashDiff.compare_values('horse', 'Horse', :case_insensitive => true)).to be true
80
+ it 'compares strings for spaces exactly by default' do
81
+ expect(described_class.compare_values(' horse', 'horse')).to be false
75
82
  end
76
83
 
84
+ it 'compares strings for capitalization exactly by default' do
85
+ expect(described_class.compare_values('horse', 'Horse')).to be false
86
+ end
87
+
88
+ it 'strips strings before comparing when requested' do
89
+ expect(described_class.compare_values(' horse', 'horse', strip: true)).to be true
90
+ end
91
+
92
+ it 'ignores string case when requested' do
93
+ expect(described_class.compare_values('horse', 'Horse', case_insensitive: true)).to be true
94
+ end
95
+ end
96
+
97
+ describe '.comparable?' do
98
+ it 'identifies hashes as comparable' do
99
+ expect(described_class.comparable?({}, {})).to be true
100
+ end
101
+
102
+ it 'identifies a subclass of Hash to be comparable with a Hash' do
103
+ other = Class.new(Hash)
104
+ expect(described_class.comparable?(other.new, {})).to be true
105
+ end
106
+
107
+ it 'identifies a Hash to be comparable with a subclass of Hash' do
108
+ other = Class.new(Hash)
109
+ expect(described_class.comparable?({}, other.new)).to be true
110
+ end
111
+
112
+ it 'does not identify a Numeric as comparable with a Hash' do
113
+ expect(described_class.comparable?(1, {})).to be false
114
+ end
77
115
  end
78
116
  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,69 +1,98 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashdiff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 1.0.1
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-10-08 00:00:00.000000000 Z
11
+ date: 2020-02-27 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
16
30
  requirements:
17
- - - ~>
31
+ - - "~>"
18
32
  - !ruby/object:Gem::Version
19
33
  version: '2.0'
20
34
  type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
- - - ~>
38
+ - - "~>"
25
39
  - !ruby/object:Gem::Version
26
40
  version: '2.0'
27
41
  - !ruby/object:Gem::Dependency
28
- name: yard
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.49.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.49.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop-rspec
29
57
  requirement: !ruby/object:Gem::Requirement
30
58
  requirements:
31
- - - '>='
59
+ - - ">="
32
60
  - !ruby/object:Gem::Version
33
61
  version: '0'
34
62
  type: :development
35
63
  prerelease: false
36
64
  version_requirements: !ruby/object:Gem::Requirement
37
65
  requirements:
38
- - - '>='
66
+ - - ">="
39
67
  - !ruby/object:Gem::Version
40
68
  version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
- name: bluecloth
70
+ name: yard
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
- - - '>='
73
+ - - ">="
46
74
  - !ruby/object:Gem::Version
47
75
  version: '0'
48
76
  type: :development
49
77
  prerelease: false
50
78
  version_requirements: !ruby/object:Gem::Requirement
51
79
  requirements:
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
56
- hashes. '
83
+ description: " Hashdiff is a diff lib to compute the smallest difference between two
84
+ hashes. "
57
85
  email:
58
86
  - liufengyunchina@gmail.com
59
87
  executables: []
60
88
  extensions: []
61
89
  extra_rdoc_files: []
62
90
  files:
63
- - .gitignore
64
- - .rspec
65
- - .travis.yml
66
- - .yardopts
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".rubocop.yml"
94
+ - ".travis.yml"
95
+ - ".yardopts"
67
96
  - Gemfile
68
97
  - LICENSE
69
98
  - README.md
@@ -71,8 +100,10 @@ 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
76
107
  - lib/hashdiff/linear_compare_array.rb
77
108
  - lib/hashdiff/patch.rb
78
109
  - lib/hashdiff/util.rb
@@ -83,30 +114,35 @@ files:
83
114
  - spec/hashdiff/lcs_spec.rb
84
115
  - spec/hashdiff/linear_compare_array_spec.rb
85
116
  - spec/hashdiff/patch_spec.rb
117
+ - spec/hashdiff/readme_spec.rb
86
118
  - spec/hashdiff/util_spec.rb
87
119
  - spec/spec_helper.rb
88
120
  homepage: https://github.com/liufengyun/hashdiff
89
121
  licenses:
90
122
  - MIT
91
- metadata: {}
123
+ metadata:
124
+ bug_tracker_uri: https://github.com/liufengyun/hashdiff/issues
125
+ changelog_uri: https://github.com/liufengyun/hashdiff/blob/master/changelog.md
126
+ documentation_uri: https://www.rubydoc.info/gems/hashdiff
127
+ homepage_uri: https://github.com/liufengyun/hashdiff
128
+ source_code_uri: https://github.com/liufengyun/hashdiff
92
129
  post_install_message:
93
130
  rdoc_options: []
94
131
  require_paths:
95
132
  - lib
96
133
  required_ruby_version: !ruby/object:Gem::Requirement
97
134
  requirements:
98
- - - '>='
135
+ - - ">="
99
136
  - !ruby/object:Gem::Version
100
- version: 1.9.3
137
+ version: 2.0.0
101
138
  required_rubygems_version: !ruby/object:Gem::Requirement
102
139
  requirements:
103
- - - '>='
140
+ - - ">="
104
141
  - !ruby/object:Gem::Version
105
142
  version: '0'
106
143
  requirements: []
107
- rubyforge_project:
108
- rubygems_version: 2.0.14.1
144
+ rubygems_version: 3.0.6
109
145
  signing_key:
110
146
  specification_version: 4
111
- summary: HashDiff is a diff lib to compute the smallest difference between two hashes.
147
+ summary: Hashdiff is a diff lib to compute the smallest difference between two hashes.
112
148
  test_files: []