blockenspiel 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Blockenspiel.rdoc +5 -1
- data/History.rdoc +7 -0
- data/README.rdoc +6 -2
- data/Version +1 -1
- data/ext/unmixer_mri/extconf.rb +10 -10
- data/ext/unmixer_mri/unmixer_mri.c +10 -10
- data/lib/blockenspiel.rb +7 -7
- data/lib/blockenspiel/builder.rb +52 -52
- data/lib/blockenspiel/dsl_setup.rb +86 -86
- data/lib/blockenspiel/errors.rb +18 -18
- data/lib/blockenspiel/impl.rb +116 -116
- data/lib/blockenspiel/unmixer_rubinius.rb +22 -22
- data/lib/blockenspiel/unmixer_unimplemented.rb +17 -17
- data/lib/blockenspiel/version.rb +9 -9
- data/lib/blockenspiel/versionomy.rb +11 -13
- data/test/tc_basic.rb +38 -38
- data/test/tc_behaviors.rb +36 -36
- data/test/tc_dsl_attrs.rb +37 -37
- data/test/tc_dsl_methods.rb +86 -86
- data/test/tc_dynamic.rb +39 -39
- data/test/tc_embedded_block.rb +29 -28
- data/test/tc_mixins.rb +103 -68
- data/test/tc_modules.rb +49 -49
- data/test/tc_version.rb +59 -0
- metadata +27 -29
- data/lib/blockenspiel_unmixer_jruby.jar +0 -0
data/test/tc_dsl_attrs.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# Blockenspiel dsl attribute tests
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# This file contains tests for the dsl attribute directives.
|
6
|
-
#
|
6
|
+
#
|
7
7
|
# -----------------------------------------------------------------------------
|
8
8
|
# Copyright 2008-2011 Daniel Azuma
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# All rights reserved.
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# Redistribution and use in source and binary forms, with or without
|
13
13
|
# modification, are permitted provided that the following conditions are met:
|
14
|
-
#
|
14
|
+
#
|
15
15
|
# * Redistributions of source code must retain the above copyright notice,
|
16
16
|
# this list of conditions and the following disclaimer.
|
17
17
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
@@ -20,7 +20,7 @@
|
|
20
20
|
# * Neither the name of the copyright holder, nor the names of any other
|
21
21
|
# contributors to this software, may be used to endorse or promote products
|
22
22
|
# derived from this software without specific prior written permission.
|
23
|
-
#
|
23
|
+
#
|
24
24
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
25
25
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
26
26
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
@@ -42,29 +42,29 @@ require 'blockenspiel'
|
|
42
42
|
|
43
43
|
module Blockenspiel
|
44
44
|
module Tests # :nodoc:
|
45
|
-
|
45
|
+
|
46
46
|
class TestDSLAttrs < ::Test::Unit::TestCase # :nodoc:
|
47
|
-
|
48
|
-
|
47
|
+
|
48
|
+
|
49
49
|
class WriterTarget < ::Blockenspiel::Base
|
50
|
-
|
50
|
+
|
51
51
|
dsl_attr_writer(:attr1, :attr2)
|
52
|
-
|
52
|
+
|
53
53
|
end
|
54
|
-
|
55
|
-
|
54
|
+
|
55
|
+
|
56
56
|
class AccessorTarget < ::Blockenspiel::Base
|
57
|
-
|
57
|
+
|
58
58
|
dsl_attr_accessor(:attr1, :attr2)
|
59
|
-
|
59
|
+
|
60
60
|
end
|
61
|
-
|
62
|
-
|
61
|
+
|
62
|
+
|
63
63
|
# Test dsl attr writer in a parametered block
|
64
|
-
#
|
64
|
+
#
|
65
65
|
# * Asserts that the standard setter syntax works
|
66
66
|
# * Asserts that the alternate setter syntax works
|
67
|
-
|
67
|
+
|
68
68
|
def test_writer_parametered
|
69
69
|
block_ = ::Proc.new do |param_|
|
70
70
|
param_.attr1 = 1
|
@@ -75,29 +75,29 @@ module Blockenspiel
|
|
75
75
|
assert_equal(1, target_.instance_variable_get(:@attr1))
|
76
76
|
assert_equal(2, target_.instance_variable_get(:@attr2))
|
77
77
|
end
|
78
|
-
|
79
|
-
|
78
|
+
|
79
|
+
|
80
80
|
# Test dsl attr writer in a parameterless block
|
81
|
-
#
|
81
|
+
#
|
82
82
|
# * Asserts that the alternate setter syntax works
|
83
|
-
|
83
|
+
|
84
84
|
def test_writer_parameterless
|
85
85
|
block_ = ::Proc.new do
|
86
86
|
assert_equal(2, attr2(2))
|
87
87
|
end
|
88
88
|
target_ = WriterTarget.new
|
89
89
|
::Blockenspiel.invoke(block_, target_)
|
90
|
-
|
90
|
+
assert_equal(false, target_.instance_variable_defined?(:@attr1))
|
91
91
|
assert_equal(2, target_.instance_variable_get(:@attr2))
|
92
92
|
end
|
93
|
-
|
94
|
-
|
93
|
+
|
94
|
+
|
95
95
|
# Test dsl attr accessor in a parametered block
|
96
|
-
#
|
96
|
+
#
|
97
97
|
# * Asserts that the standard setter syntax works
|
98
98
|
# * Asserts that the alternate setter syntax works
|
99
99
|
# * Asserts that the getter syntax works
|
100
|
-
|
100
|
+
|
101
101
|
def _test_accessor_parametered
|
102
102
|
block_ = ::Proc.new do |param_|
|
103
103
|
param_.attr1 = 1
|
@@ -109,13 +109,13 @@ module Blockenspiel
|
|
109
109
|
assert_equal(1, target_.instance_variable_get(:@attr1))
|
110
110
|
assert_equal(2, target_.instance_variable_get(:@attr2))
|
111
111
|
end
|
112
|
-
|
113
|
-
|
112
|
+
|
113
|
+
|
114
114
|
# Test dsl attr accessor in a parameterless block
|
115
|
-
#
|
115
|
+
#
|
116
116
|
# * Asserts that the alternate setter syntax works
|
117
117
|
# * Asserts that the getter syntax works
|
118
|
-
|
118
|
+
|
119
119
|
def test_accessor_parameterless
|
120
120
|
block_ = ::Proc.new do
|
121
121
|
assert_equal(2, attr2(2))
|
@@ -123,12 +123,12 @@ module Blockenspiel
|
|
123
123
|
end
|
124
124
|
target_ = AccessorTarget.new
|
125
125
|
::Blockenspiel.invoke(block_, target_)
|
126
|
-
|
126
|
+
assert_equal(false, target_.instance_variable_defined?(:@attr1))
|
127
127
|
assert_equal(2, target_.instance_variable_get(:@attr2))
|
128
128
|
end
|
129
|
-
|
130
|
-
|
129
|
+
|
130
|
+
|
131
131
|
end
|
132
|
-
|
132
|
+
|
133
133
|
end
|
134
134
|
end
|
data/test/tc_dsl_methods.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# Blockenspiel dsl method tests
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# This file contains tests for the dsl method directives.
|
6
|
-
#
|
6
|
+
#
|
7
7
|
# -----------------------------------------------------------------------------
|
8
8
|
# Copyright 2008-2011 Daniel Azuma
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# All rights reserved.
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# Redistribution and use in source and binary forms, with or without
|
13
13
|
# modification, are permitted provided that the following conditions are met:
|
14
|
-
#
|
14
|
+
#
|
15
15
|
# * Redistributions of source code must retain the above copyright notice,
|
16
16
|
# this list of conditions and the following disclaimer.
|
17
17
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
@@ -20,7 +20,7 @@
|
|
20
20
|
# * Neither the name of the copyright holder, nor the names of any other
|
21
21
|
# contributors to this software, may be used to endorse or promote products
|
22
22
|
# derived from this software without specific prior written permission.
|
23
|
-
#
|
23
|
+
#
|
24
24
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
25
25
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
26
26
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
@@ -42,165 +42,165 @@ require 'blockenspiel'
|
|
42
42
|
|
43
43
|
module Blockenspiel
|
44
44
|
module Tests # :nodoc:
|
45
|
-
|
45
|
+
|
46
46
|
class TestDSLMethods < ::Test::Unit::TestCase # :nodoc:
|
47
|
-
|
48
|
-
|
47
|
+
|
48
|
+
|
49
49
|
class Target1 < ::Blockenspiel::Base
|
50
|
-
|
50
|
+
|
51
51
|
def initialize(hash_)
|
52
52
|
@hash = hash_
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
def set_value1(key_, value_)
|
56
56
|
@hash["#{key_}1"] = value_
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
def set_value2(key_)
|
60
60
|
@hash["#{key_}2"] = yield
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
def _set_value3(key_, value_)
|
64
64
|
@hash["#{key_}3"] = value_
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
end
|
68
|
-
|
69
|
-
|
68
|
+
|
69
|
+
|
70
70
|
class Target2 < ::Blockenspiel::Base
|
71
|
-
|
71
|
+
|
72
72
|
def initialize(hash_)
|
73
73
|
@hash = hash_
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
dsl_methods false
|
77
|
-
|
77
|
+
|
78
78
|
def set_value1(key_, value_)
|
79
79
|
@hash["#{key_}1"] = value_
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
dsl_methods true
|
83
|
-
|
83
|
+
|
84
84
|
def set_value2(key_)
|
85
85
|
@hash["#{key_}2"] = yield
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
def _set_value3(key_, value_)
|
89
89
|
@hash["#{key_}3"] = value_
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
end
|
93
|
-
|
94
|
-
|
93
|
+
|
94
|
+
|
95
95
|
class Target3 < ::Blockenspiel::Base
|
96
|
-
|
96
|
+
|
97
97
|
def initialize(hash_)
|
98
98
|
@hash = hash_
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
101
|
dsl_methods false
|
102
|
-
|
102
|
+
|
103
103
|
def set_value1(key_, value_)
|
104
104
|
@hash["#{key_}1"] = value_
|
105
105
|
end
|
106
106
|
dsl_method :set_value1
|
107
|
-
|
107
|
+
|
108
108
|
def set_value2(key_)
|
109
109
|
@hash["#{key_}2"] = yield
|
110
110
|
end
|
111
111
|
dsl_method :renamed_set_value2, :set_value2
|
112
112
|
dsl_method :another_set_value2, :set_value2
|
113
|
-
|
113
|
+
|
114
114
|
end
|
115
|
-
|
116
|
-
|
115
|
+
|
116
|
+
|
117
117
|
class Target4 < ::Blockenspiel::Base
|
118
|
-
|
118
|
+
|
119
119
|
def initialize(hash_)
|
120
120
|
@hash = hash_
|
121
121
|
end
|
122
|
-
|
122
|
+
|
123
123
|
def set_value1(key_, value_)
|
124
124
|
@hash["#{key_}1"] = value_
|
125
125
|
end
|
126
126
|
dsl_method :set_value1, false
|
127
|
-
|
127
|
+
|
128
128
|
def set_value2(key_)
|
129
129
|
@hash["#{key_}2"] = yield
|
130
130
|
end
|
131
131
|
dsl_method :set_value2, false
|
132
132
|
dsl_method :renamed_set_value2, :set_value2
|
133
|
-
|
133
|
+
|
134
134
|
end
|
135
|
-
|
136
|
-
|
135
|
+
|
136
|
+
|
137
137
|
class Target5a < ::Blockenspiel::Base
|
138
|
-
|
138
|
+
|
139
139
|
def initialize(hash_)
|
140
140
|
@hash = hash_
|
141
141
|
end
|
142
|
-
|
142
|
+
|
143
143
|
def set_value1(key_, value_)
|
144
144
|
@hash["#{key_}1"] = value_
|
145
145
|
end
|
146
|
-
|
146
|
+
|
147
147
|
def set_value2(key_)
|
148
148
|
@hash["#{key_}2"] = yield
|
149
149
|
end
|
150
|
-
|
150
|
+
|
151
151
|
def set_value3(key_, value_)
|
152
152
|
@hash["#{key_}3"] = value_
|
153
153
|
end
|
154
|
-
|
154
|
+
|
155
155
|
def set_value4(key_, value_)
|
156
156
|
@hash["#{key_}4"] = value_
|
157
157
|
end
|
158
158
|
dsl_method :set_value4, false
|
159
159
|
dsl_method :renamed_set_value4, :set_value4
|
160
|
-
|
160
|
+
|
161
161
|
end
|
162
|
-
|
163
|
-
|
162
|
+
|
163
|
+
|
164
164
|
class Target5b < Target5a
|
165
|
-
|
165
|
+
|
166
166
|
def set_value1(key_, value_)
|
167
167
|
@hash["#{key_}1sub"] = value_
|
168
168
|
end
|
169
|
-
|
169
|
+
|
170
170
|
dsl_method :set_value3, false
|
171
|
-
|
171
|
+
|
172
172
|
def set_value5(key_, value_)
|
173
173
|
@hash["#{key_}5"] = value_
|
174
174
|
end
|
175
|
-
|
175
|
+
|
176
176
|
end
|
177
|
-
|
178
|
-
|
177
|
+
|
178
|
+
|
179
179
|
class Target6 < ::Blockenspiel::Base
|
180
|
-
|
180
|
+
|
181
181
|
def initialize(hash_)
|
182
182
|
@hash = hash_
|
183
183
|
end
|
184
|
-
|
184
|
+
|
185
185
|
dsl_methods false
|
186
|
-
|
186
|
+
|
187
187
|
def set_value1(key_, value_)
|
188
188
|
@hash["#{key_}1"] = value_
|
189
189
|
end
|
190
|
-
|
190
|
+
|
191
191
|
def set_value2(key_)
|
192
192
|
@hash["#{key_}2"] = yield
|
193
193
|
end
|
194
|
-
|
194
|
+
|
195
195
|
dsl_methods :set_value1, :renamed_set_value2 => :set_value2
|
196
|
-
|
196
|
+
|
197
197
|
end
|
198
|
-
|
199
|
-
|
198
|
+
|
199
|
+
|
200
200
|
# Test default dsl method setting.
|
201
|
-
#
|
201
|
+
#
|
202
202
|
# * Asserts the right dsl methods are added for the default setting.
|
203
|
-
|
203
|
+
|
204
204
|
def test_default_setting
|
205
205
|
hash_ = ::Hash.new
|
206
206
|
block_ = ::Proc.new do
|
@@ -213,14 +213,14 @@ module Blockenspiel
|
|
213
213
|
assert_equal(2, hash_['b2'])
|
214
214
|
assert_nil(hash_['c3'])
|
215
215
|
end
|
216
|
-
|
217
|
-
|
216
|
+
|
217
|
+
|
218
218
|
# Test dsl_methods true and false switching.
|
219
|
-
#
|
219
|
+
#
|
220
220
|
# * Asserts that dsl_methods false turns off automatic method creation.
|
221
221
|
# * Asserts that dsl_methods true turns on automatic method creation.
|
222
222
|
# * Asserts that underscore methods are added in dsl_methods true mode.
|
223
|
-
|
223
|
+
|
224
224
|
def test_onoff_switching
|
225
225
|
hash_ = ::Hash.new
|
226
226
|
block_ = ::Proc.new do
|
@@ -233,13 +233,13 @@ module Blockenspiel
|
|
233
233
|
assert_equal(2, hash_['b2'])
|
234
234
|
assert_equal(3, hash_['c3'])
|
235
235
|
end
|
236
|
-
|
237
|
-
|
236
|
+
|
237
|
+
|
238
238
|
# Test dsl_methods explicit adding.
|
239
|
-
#
|
239
|
+
#
|
240
240
|
# * Asserts that adding an explicit dsl method works.
|
241
241
|
# * Asserts that adding an explicit dsl method with a different name works.
|
242
|
-
|
242
|
+
|
243
243
|
def test_explicit_add
|
244
244
|
hash_ = ::Hash.new
|
245
245
|
block_ = ::Proc.new do
|
@@ -254,13 +254,13 @@ module Blockenspiel
|
|
254
254
|
assert_equal(3, hash_['c2'])
|
255
255
|
assert_equal(4, hash_['d2'])
|
256
256
|
end
|
257
|
-
|
258
|
-
|
257
|
+
|
258
|
+
|
259
259
|
# Test dsl_methods explicit removing.
|
260
|
-
#
|
260
|
+
#
|
261
261
|
# * Asserts that removing a dsl method works.
|
262
262
|
# * Asserts that re-adding a removed method with a different name works.
|
263
|
-
|
263
|
+
|
264
264
|
def test_explicit_removing
|
265
265
|
hash_ = ::Hash.new
|
266
266
|
block_ = ::Proc.new do
|
@@ -273,13 +273,13 @@ module Blockenspiel
|
|
273
273
|
assert_nil(hash_['b2'])
|
274
274
|
assert_equal(3, hash_['c2'])
|
275
275
|
end
|
276
|
-
|
277
|
-
|
276
|
+
|
277
|
+
|
278
278
|
# Test dsl method setting with subclasses
|
279
|
-
#
|
279
|
+
#
|
280
280
|
# * Asserts that modules are properly inherited.
|
281
281
|
# * Asserts that method overriding is done correctly.
|
282
|
-
|
282
|
+
|
283
283
|
def test_subclassing
|
284
284
|
hash_ = ::Hash.new
|
285
285
|
block_ = ::Proc.new do
|
@@ -298,13 +298,13 @@ module Blockenspiel
|
|
298
298
|
assert_equal(5, hash_['e4'])
|
299
299
|
assert_equal(6, hash_['f5'])
|
300
300
|
end
|
301
|
-
|
302
|
-
|
301
|
+
|
302
|
+
|
303
303
|
# Test dsl_methods with multiple parameters.
|
304
|
-
#
|
304
|
+
#
|
305
305
|
# * Asserts that hash syntax for dsl_methods works.
|
306
306
|
# * Asserts that combined array and hash parameters works.
|
307
|
-
|
307
|
+
|
308
308
|
def test_multiple_dsl_methods
|
309
309
|
hash_ = ::Hash.new
|
310
310
|
block_ = ::Proc.new do
|
@@ -316,9 +316,9 @@ module Blockenspiel
|
|
316
316
|
assert_equal(1, hash_['a1'])
|
317
317
|
assert_equal(2, hash_['b2'])
|
318
318
|
end
|
319
|
-
|
320
|
-
|
319
|
+
|
320
|
+
|
321
321
|
end
|
322
|
-
|
322
|
+
|
323
323
|
end
|
324
324
|
end
|