hashery 1.5.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.ruby +30 -17
- data/.yardopts +1 -0
- data/Config.rb +28 -0
- data/{QED.rdoc → DEMO.rdoc} +0 -0
- data/HISTORY.rdoc +37 -0
- data/LICENSE.txt +26 -0
- data/NOTICE.txt +46 -0
- data/README.rdoc +10 -7
- data/lib/hashery.rb +6 -6
- data/lib/hashery.yml +30 -17
- data/lib/hashery/association.rb +169 -109
- data/lib/hashery/casting_hash.rb +128 -135
- data/lib/hashery/core_ext.rb +89 -61
- data/lib/hashery/crud_hash.rb +365 -0
- data/lib/hashery/dictionary.rb +545 -345
- data/lib/hashery/fuzzy_hash.rb +177 -125
- data/lib/hashery/ini_hash.rb +321 -0
- data/lib/hashery/key_hash.rb +54 -179
- data/lib/hashery/linked_list.rb +245 -191
- data/lib/hashery/lru_hash.rb +292 -202
- data/lib/hashery/open_cascade.rb +133 -78
- data/lib/hashery/open_hash.rb +127 -61
- data/lib/hashery/ordered_hash.rb +128 -122
- data/lib/hashery/path_hash.rb +238 -0
- data/lib/hashery/property_hash.rb +144 -80
- data/lib/hashery/query_hash.rb +85 -29
- data/lib/hashery/stash.rb +7 -3
- data/lib/hashery/static_hash.rb +46 -41
- data/test/case_association.rb +65 -4
- data/test/case_dictionary.rb +149 -5
- data/test/{case_keyhash.rb → case_key_hash.rb} +20 -14
- data/test/case_lru_hash.rb +162 -0
- data/test/{case_opencascade.rb → case_open_cascade.rb} +4 -8
- data/test/case_open_hash.rb +87 -0
- data/test/case_query_hash.rb +226 -0
- data/test/helper.rb +8 -0
- metadata +33 -63
- data/COPYING.rdoc +0 -45
- data/lib/hashery/basic_object.rb +0 -74
- data/lib/hashery/basic_struct.rb +0 -288
- data/lib/hashery/basicobject.rb +0 -1
- data/lib/hashery/basicstruct.rb +0 -1
- data/lib/hashery/castinghash.rb +0 -1
- data/lib/hashery/fuzzyhash.rb +0 -1
- data/lib/hashery/ini.rb +0 -268
- data/lib/hashery/keyhash.rb +0 -1
- data/lib/hashery/linkedlist.rb +0 -1
- data/lib/hashery/lruhash.rb +0 -1
- data/lib/hashery/memoizer.rb +0 -64
- data/lib/hashery/open_object.rb +0 -1
- data/lib/hashery/opencascade.rb +0 -1
- data/lib/hashery/openhash.rb +0 -1
- data/lib/hashery/openobject.rb +0 -1
- data/lib/hashery/orderedhash.rb +0 -1
- data/lib/hashery/ostructable.rb +0 -186
- data/lib/hashery/propertyhash.rb +0 -1
- data/lib/hashery/queryhash.rb +0 -1
- data/lib/hashery/statichash.rb +0 -1
- data/qed/01_openhash.rdoc +0 -57
- data/qed/02_queryhash.rdoc +0 -21
- data/qed/03_castinghash.rdoc +0 -13
- data/qed/04_statichash.rdoc +0 -22
- data/qed/05_association.rdoc +0 -59
- data/qed/06_opencascade.rdoc +0 -58
- data/qed/07_fuzzyhash.rdoc +0 -141
- data/qed/08_properyhash.rdoc +0 -38
- data/qed/09_ostructable.rdoc +0 -56
- data/qed/applique/ae.rb +0 -1
- data/test/case_basicstruct.rb +0 -192
- data/test/case_openhash.rb +0 -22
@@ -1,15 +1,17 @@
|
|
1
|
-
require '
|
2
|
-
require 'ae'
|
3
|
-
require 'ae/pry'
|
4
|
-
|
5
|
-
require 'hashery/key_hash'
|
1
|
+
require 'helper'
|
6
2
|
|
7
3
|
testcase KeyHash do
|
8
4
|
|
9
5
|
class_method :[] do
|
10
|
-
test '
|
6
|
+
test 'creates new KeyHash' do
|
7
|
+
s = KeyHash[]
|
8
|
+
KeyHash.assert === s
|
9
|
+
end
|
10
|
+
|
11
|
+
test 'pre-assigns values' do
|
11
12
|
s = KeyHash[:a=>1, :b=>2]
|
12
|
-
assert
|
13
|
+
s[:a].assert == 1
|
14
|
+
s[:b].assert == 2
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
@@ -18,6 +20,10 @@ testcase KeyHash do
|
|
18
20
|
s = KeyHash[:a=>1, :b=>2]
|
19
21
|
s[:a].assert == 1
|
20
22
|
s[:b].assert == 2
|
23
|
+
end
|
24
|
+
|
25
|
+
test 'by default keys are converted to strings' do
|
26
|
+
s = KeyHash[:a=>1, :b=>2]
|
21
27
|
s['a'].assert == 1
|
22
28
|
s['b'].assert == 2
|
23
29
|
end
|
@@ -97,7 +103,7 @@ testcase KeyHash do
|
|
97
103
|
s1.to_h.assert == {'a'=>1,'b'=>2,'c'=>3,'d'=>4}
|
98
104
|
end
|
99
105
|
end
|
100
|
-
|
106
|
+
|
101
107
|
method :rekey do
|
102
108
|
test do
|
103
109
|
s = KeyHash[:a=>1,:b=>2,:c=>3]
|
@@ -164,12 +170,12 @@ require 'ae'
|
|
164
170
|
end
|
165
171
|
end
|
166
172
|
|
167
|
-
method :
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
end
|
173
|
+
#method :cast_key do
|
174
|
+
# test do
|
175
|
+
# s = KeyHash.new
|
176
|
+
# s.send(:cast_key, :a).assert == 'a'
|
177
|
+
# end
|
178
|
+
#end
|
173
179
|
|
174
180
|
end
|
175
181
|
|
@@ -0,0 +1,162 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
test_case LRUHash do
|
4
|
+
|
5
|
+
class_method :new do
|
6
|
+
h = LRUHash.new(10)
|
7
|
+
LRUHash.assert === h
|
8
|
+
end
|
9
|
+
|
10
|
+
method :max_size= do
|
11
|
+
test do
|
12
|
+
h = LRUHash.new(10)
|
13
|
+
h.max_size = 100
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
method :store do
|
18
|
+
test do
|
19
|
+
h = LRUHash.new(10)
|
20
|
+
h.store(:a, 1)
|
21
|
+
h[:a].assert == 1
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
method :[] do
|
26
|
+
test do
|
27
|
+
h = LRUHash.new(10)
|
28
|
+
h.store(:a, 1)
|
29
|
+
h[:a].assert == 1
|
30
|
+
end
|
31
|
+
|
32
|
+
test do
|
33
|
+
h = LRUHash.new(10){ |h,k| h[k] = 0 }
|
34
|
+
h[:a].assert == 0
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
method :empty? do
|
39
|
+
test do
|
40
|
+
h = LRUHash.new(10)
|
41
|
+
h.assert.empty?
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
method :key do
|
46
|
+
test do
|
47
|
+
h = LRUHash.new(10)
|
48
|
+
h[:a] = 1
|
49
|
+
h.key(1).assert == :a
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
method :keys do
|
54
|
+
test do
|
55
|
+
h = LRUHash.new(10)
|
56
|
+
h[:a] = 1
|
57
|
+
h.keys.assert == [:a]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
method :values do
|
62
|
+
test do
|
63
|
+
h = LRUHash.new(10)
|
64
|
+
h[:a] = 1
|
65
|
+
h.values.assert == [1]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
method :values_at do
|
70
|
+
test do
|
71
|
+
h = LRUHash.new(10)
|
72
|
+
h[:a] = 1
|
73
|
+
h[:b] = 2
|
74
|
+
h.values_at(:a).assert == [1]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
method :has_key? do
|
79
|
+
test do
|
80
|
+
h = LRUHash.new(10)
|
81
|
+
h[:a] = 1
|
82
|
+
h.assert.has_key?(:a)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
method :has_value? do
|
87
|
+
test do
|
88
|
+
h = LRUHash.new(10)
|
89
|
+
h[:a] = 1
|
90
|
+
h.assert.has_value?(1)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
method :assoc do
|
95
|
+
test do
|
96
|
+
h = LRUHash.new(10)
|
97
|
+
h[:a] = 1
|
98
|
+
h[:b] = 2
|
99
|
+
h.assoc(:a).assert == [:a,1]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
method :rassoc do
|
104
|
+
test do
|
105
|
+
h = LRUHash.new(10)
|
106
|
+
h[:a] = 1
|
107
|
+
h[:b] = 2
|
108
|
+
h.rassoc(1).assert == [:a,1]
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
method :each_key do
|
113
|
+
test do
|
114
|
+
h = LRUHash.new(10)
|
115
|
+
h[:a] = 1
|
116
|
+
h[:b] = 2
|
117
|
+
h.each_key do |k|
|
118
|
+
[:a,:b].assert.include?(k)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
method :each_value do
|
124
|
+
test do
|
125
|
+
h = LRUHash.new(10)
|
126
|
+
h[:a] = 1
|
127
|
+
h[:b] = 2
|
128
|
+
h.each_value do |v|
|
129
|
+
[1,2].assert.include?(v)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
method :clear do
|
135
|
+
test do
|
136
|
+
h = LRUHash.new(10)
|
137
|
+
h[:a] = 1
|
138
|
+
h[:b] = 2
|
139
|
+
h.clear
|
140
|
+
h.assert.empty?
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
method :delete do
|
145
|
+
test do
|
146
|
+
h = LRUHash.new(10)
|
147
|
+
h[:a] = 1
|
148
|
+
h.delete(:a)
|
149
|
+
h.assert.empty?
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
method :delete_if do
|
154
|
+
test do
|
155
|
+
h = LRUHash.new(10)
|
156
|
+
h[:a] = 1
|
157
|
+
h.delete_if{ |k,v| k == :a }
|
158
|
+
h.assert.empty?
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
@@ -1,14 +1,10 @@
|
|
1
|
-
require '
|
2
|
-
require 'ae'
|
3
|
-
require 'ae/legacy' # bacause imitation BasicObject sucks
|
4
|
-
|
5
|
-
require 'hashery/open_cascade'
|
1
|
+
require 'helper'
|
6
2
|
|
7
3
|
testcase OpenCascade do
|
8
4
|
include AE::Legacy::Assertions
|
9
5
|
|
10
6
|
class_method :new do
|
11
|
-
OpenCascade
|
7
|
+
OpenCascade[:a=>1]
|
12
8
|
end
|
13
9
|
|
14
10
|
class_method :[] do
|
@@ -32,7 +28,7 @@ testcase OpenCascade do
|
|
32
28
|
test "basic assignment" do
|
33
29
|
o = OpenCascade.new
|
34
30
|
o[:a] = 1
|
35
|
-
assert_equal(1, o
|
31
|
+
assert_equal(1, o[:a])
|
36
32
|
end
|
37
33
|
end
|
38
34
|
|
@@ -64,8 +60,8 @@ testcase OpenCascade do
|
|
64
60
|
method :merge! do
|
65
61
|
test do
|
66
62
|
o = OpenCascade[:f0=>"f0"]
|
67
|
-
h = { :h0=>"h0" }
|
68
63
|
r = OpenCascade[:f0=>"f0", :h0=>"h0"]
|
64
|
+
h = { :h0=>"h0" }
|
69
65
|
assert_equal(r, o.merge!(h))
|
70
66
|
assert_equal({:f0=>"f0", :h0=>"h0"}, h.merge(o))
|
71
67
|
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
testcase OpenHash do
|
4
|
+
|
5
|
+
class_method :[] do
|
6
|
+
test do
|
7
|
+
o = OpenHash[:a=>1, :b=>2]
|
8
|
+
o.a.assert == 1
|
9
|
+
o.b.assert == 2
|
10
|
+
end
|
11
|
+
|
12
|
+
test do
|
13
|
+
o = OpenHash[:a=>1, :b=>2]
|
14
|
+
o.a.assert == 1
|
15
|
+
o.b.assert == 2
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
method :open? do
|
20
|
+
test do
|
21
|
+
o = OpenHash[:a=>1, :b=>2]
|
22
|
+
o.assert.open?(:foo)
|
23
|
+
o.refute.open?(:each)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
method :open! do
|
28
|
+
test do
|
29
|
+
o = OpenHash[:a=>1, :b=>2]
|
30
|
+
o.open!(:each)
|
31
|
+
o.assert.open?(:each)
|
32
|
+
o.each = 10
|
33
|
+
o.each.assert == 10
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
method :close! do
|
38
|
+
test do
|
39
|
+
o = OpenHash[:a=>1, :b=>2]
|
40
|
+
o.open!(:each)
|
41
|
+
o.assert.open?(:each)
|
42
|
+
o.each = 10
|
43
|
+
o.each.assert == 10
|
44
|
+
o.close!(:each)
|
45
|
+
o.each.refute == 10
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
method :method_missing do
|
50
|
+
test 'bang method' do
|
51
|
+
o = OpenHash[]
|
52
|
+
o.open!(:each)
|
53
|
+
o.each = 10
|
54
|
+
o.each.assert == 10
|
55
|
+
|
56
|
+
a = []
|
57
|
+
o.each! do |k,v|
|
58
|
+
a << [k,v]
|
59
|
+
end
|
60
|
+
a.assert == [[:each,10]]
|
61
|
+
end
|
62
|
+
|
63
|
+
test 'query method' do
|
64
|
+
o = OpenHash[]
|
65
|
+
o.a = 1
|
66
|
+
o.assert.a?
|
67
|
+
o.refute.b?
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
method :send do
|
72
|
+
test do
|
73
|
+
o = OpenHash[]
|
74
|
+
o.open!(:each)
|
75
|
+
o.each = 10
|
76
|
+
o.each.assert == 10
|
77
|
+
|
78
|
+
a = []
|
79
|
+
o.send(:each) do |k,v|
|
80
|
+
a << [k,v]
|
81
|
+
end
|
82
|
+
a.assert == [[:each,10]]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
@@ -0,0 +1,226 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
testcase QueryHash do
|
4
|
+
|
5
|
+
class_method :new do
|
6
|
+
test 'new QueryHash with default proc' do
|
7
|
+
q = QueryHash.new{ |h,k| h[k] = 1 }
|
8
|
+
q[:a].assert == 1
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class_method :[] do
|
13
|
+
test 'creates new QueryHash' do
|
14
|
+
s = QueryHash[]
|
15
|
+
QueryHash.assert === s
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'pre-assigns values' do
|
19
|
+
s = QueryHash[:a=>1, :b=>2]
|
20
|
+
s[:a].assert == 1
|
21
|
+
s[:b].assert == 2
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
method :[] do
|
26
|
+
test 'instance level fetch' do
|
27
|
+
s = QueryHash[:a=>1, :b=>2]
|
28
|
+
s[:a].assert == 1
|
29
|
+
s[:b].assert == 2
|
30
|
+
#s['a'].assert == 1
|
31
|
+
#s['b'].assert == 2
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
method :[]= do
|
36
|
+
test do
|
37
|
+
s = QueryHash.new
|
38
|
+
s[:a] = 1
|
39
|
+
s[:b] = 2
|
40
|
+
s[:a].assert == 1
|
41
|
+
s[:b].assert == 2
|
42
|
+
#s['a'].assert == 1
|
43
|
+
#s['b'].assert == 2
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
method :respond_to? do
|
48
|
+
test 'responds to all query methods' do
|
49
|
+
q = QueryHash.new
|
50
|
+
q.assert.respond_to?(:anything?)
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'responds to all bang methods' do
|
54
|
+
q = QueryHash.new
|
55
|
+
q.assert.respond_to?(:anything!)
|
56
|
+
end
|
57
|
+
|
58
|
+
test 'responds to all setter methods' do
|
59
|
+
q = QueryHash.new
|
60
|
+
q.assert.respond_to?(:anything=)
|
61
|
+
end
|
62
|
+
|
63
|
+
test 'responds to usual methods' do
|
64
|
+
q = QueryHash.new
|
65
|
+
q.assert.respond_to?(:each)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
method :to_hash do
|
70
|
+
test do
|
71
|
+
s = QueryHash[:a=>1, :b=>2]
|
72
|
+
s.to_hash.assert == {'a'=>1, 'b'=>2}
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
method :to_h do
|
77
|
+
test do
|
78
|
+
s = QueryHash[:a=>1, :b=>2]
|
79
|
+
s.to_h.assert == {'a'=>1, 'b'=>2}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
method :replace do
|
84
|
+
test do
|
85
|
+
s = QueryHash.new
|
86
|
+
s.replace(:a=>1, :b=>2)
|
87
|
+
s.to_h.assert == {'a'=>1, 'b'=>2}
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
method :delete do
|
92
|
+
test do
|
93
|
+
s = QueryHash[:a=>1, :b=>2]
|
94
|
+
s.delete(:a)
|
95
|
+
s.to_h.assert == {'b'=>2}
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
method :each do
|
100
|
+
test do
|
101
|
+
s = QueryHash[:a=>1, :b=>2]
|
102
|
+
s.each do |k,v|
|
103
|
+
String.assert === k
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
method :store do
|
109
|
+
test do
|
110
|
+
s = QueryHash.new
|
111
|
+
s.store(:a, 1)
|
112
|
+
s.to_h.assert == {'a'=>1}
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
method :update do
|
117
|
+
test do
|
118
|
+
s1 = QueryHash[:a=>1,:b=>2]
|
119
|
+
s2 = QueryHash[:c=>3,:d=>4]
|
120
|
+
s1.update(s2)
|
121
|
+
s1.to_h.assert == {'a'=>1,'b'=>2,'c'=>3,'d'=>4}
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
method :rekey do
|
126
|
+
test do
|
127
|
+
s = QueryHash[:a=>1,:b=>2,:c=>3]
|
128
|
+
x = s.rekey{ |k| k.upcase }
|
129
|
+
x.to_h.assert == {'A'=>1,'B'=>2,'C'=>3}
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
method :rekey! do
|
134
|
+
test do
|
135
|
+
s = QueryHash[:a=>1,:b=>2,:c=>3]
|
136
|
+
s.rekey!{ |k| k.upcase }
|
137
|
+
s.to_h.assert == {'A'=>1,'B'=>2,'C'=>3}
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
method :key? do
|
142
|
+
test do
|
143
|
+
s = QueryHash[:a=>1]
|
144
|
+
s.assert.key?(:a)
|
145
|
+
s.assert.key?('a')
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
method :has_key? do
|
150
|
+
test do
|
151
|
+
s = QueryHash[:a=>1]
|
152
|
+
s.assert.has_key?(:a)
|
153
|
+
s.assert.has_key?('a')
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
method :<< do
|
158
|
+
test do
|
159
|
+
s = QueryHash.new
|
160
|
+
s << [:a, 1]
|
161
|
+
s << [:b, 2]
|
162
|
+
s.to_h.assert == {'a'=>1, 'b'=>2}
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
method :merge! do
|
167
|
+
test do
|
168
|
+
s1 = QueryHash[:a=>1,:b=>2]
|
169
|
+
s2 = QueryHash[:c=>3,:d=>4]
|
170
|
+
s1.merge!(s2)
|
171
|
+
s1.to_h.assert == {'a'=>1,'b'=>2,'c'=>3,'d'=>4}
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
method :values_at do
|
176
|
+
test do
|
177
|
+
s = QueryHash[:a=>1,:b=>2,:c=>3]
|
178
|
+
s.values_at(:a, :b).assert == [1,2]
|
179
|
+
s.values_at('a','b').assert == [1,2]
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
method :fetch do
|
184
|
+
test do
|
185
|
+
s = QueryHash[:a=>1,:b=>2,:c=>3]
|
186
|
+
s.fetch(:a).assert == 1
|
187
|
+
s.fetch('a').assert == 1
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
method :cast_key do
|
192
|
+
test do
|
193
|
+
s = QueryHash.new
|
194
|
+
s.pry.cast_key(:a).assert == 'a'
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
method :method_missing do
|
199
|
+
test 'dynamic query methods can look-up values' do
|
200
|
+
q = QueryHash[:a=>1,:b=>2,:c=>3]
|
201
|
+
q.a?.assert == 1
|
202
|
+
q.b?.assert == 2
|
203
|
+
q.c?.assert == 3
|
204
|
+
end
|
205
|
+
|
206
|
+
test 'dynamic bang methods can looks up values too' do
|
207
|
+
q = QueryHash[:a=>1,:b=>2,:c=>3]
|
208
|
+
q.a!.assert == 1
|
209
|
+
q.b!.assert == 2
|
210
|
+
q.c!.assert == 3
|
211
|
+
end
|
212
|
+
|
213
|
+
test 'dynamic bang methods will auto-instantiate' do
|
214
|
+
q = QueryHash.new
|
215
|
+
q.default_proc{ |h,k| h[k] = 'default' }
|
216
|
+
q.foo!.assert == 'default'
|
217
|
+
end
|
218
|
+
|
219
|
+
test 'dynamic query methods will NOT auto-instantiate' do
|
220
|
+
q = QueryHash.new
|
221
|
+
q.default_proc{ |h,k| h[k] = 'default' }
|
222
|
+
q.foo?.assert == nil
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
end
|