striuct 0.0.11.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.
- data/.gemtest +0 -0
- data/History.rdoc +110 -0
- data/Manifest.txt +15 -0
- data/README.ja.rdoc +244 -0
- data/README.rdoc +220 -0
- data/Rakefile +22 -0
- data/example.rb +214 -0
- data/lib/striuct/classutil.rb +26 -0
- data/lib/striuct/core.rb +56 -0
- data/lib/striuct/import.rb +95 -0
- data/lib/striuct/subclass.rb +262 -0
- data/lib/striuct/subclass_eigen.rb +428 -0
- data/lib/striuct/version.rb +4 -0
- data/lib/striuct.rb +4 -0
- data/test/test_helper.rb +3 -0
- data/test/test_helper_import.rb +4 -0
- data/test/test_striuct.rb +580 -0
- data/test/test_striuct_import.rb +42 -0
- metadata +94 -0
@@ -0,0 +1,580 @@
|
|
1
|
+
$VERBOSE = true
|
2
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
3
|
+
|
4
|
+
class User < Striuct.new
|
5
|
+
member :id, Integer
|
6
|
+
member :last_name, /\A\w+\z/
|
7
|
+
member :family_name, /\A\w+\z/
|
8
|
+
member :address, /\A((\w+) ?)+\z/
|
9
|
+
member :age, ->age{(20..140).include? age}
|
10
|
+
end
|
11
|
+
|
12
|
+
class TestStriuctSubclassEigen < Test::Unit::TestCase
|
13
|
+
User2 = Striuct.new :name, :age
|
14
|
+
|
15
|
+
def test_builder
|
16
|
+
klass = Striuct.new
|
17
|
+
assert_kind_of Striuct, klass.new
|
18
|
+
|
19
|
+
klass = Striuct.new :name, :age
|
20
|
+
|
21
|
+
assert_equal klass.members, [:name, :age]
|
22
|
+
|
23
|
+
klass = Striuct.new :foo do
|
24
|
+
member :var
|
25
|
+
end
|
26
|
+
|
27
|
+
assert_equal klass.members, [:foo, :var]
|
28
|
+
assert_equal User.members, [:id, :last_name, :family_name, :address, :age]
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_define
|
32
|
+
user = User2.define{|r|r.age = 1; r.name = ''}
|
33
|
+
assert_same 1, user.age
|
34
|
+
|
35
|
+
assert_raises RuntimeError do
|
36
|
+
user.age = 1
|
37
|
+
end
|
38
|
+
|
39
|
+
user = User2.define(false){|r|r.age = 1; r.name = ''}
|
40
|
+
assert_same 1, user.age
|
41
|
+
|
42
|
+
assert_raises RuntimeError do
|
43
|
+
User2.define{|r|r.age = 1}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_sufficent?
|
48
|
+
assert_equal false, User.sufficent?(:age, 19)
|
49
|
+
assert_equal true, User.sufficent?(:age, 20)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_restrict?
|
53
|
+
klass = Striuct.new :foo do
|
54
|
+
member :var, //
|
55
|
+
member :hoge
|
56
|
+
member :moge, nil
|
57
|
+
end
|
58
|
+
|
59
|
+
assert_equal false, klass.restrict?(:foo)
|
60
|
+
assert_equal true, klass.restrict?(:var)
|
61
|
+
assert_equal false, klass.restrict?(:hoge)
|
62
|
+
assert_equal true, klass.restrict?(:moge)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
class TestStriuctSubclassInstance1 < Test::Unit::TestCase
|
67
|
+
def test_setter
|
68
|
+
user = User.new
|
69
|
+
user[:last_name] = 'foo'
|
70
|
+
assert_equal user.last_name, 'foo'
|
71
|
+
user.last_name = 'bar'
|
72
|
+
assert_equal user[:last_name], 'bar'
|
73
|
+
|
74
|
+
assert_raises Striuct::ConditionError do
|
75
|
+
user[:last_name] = 'foo s'
|
76
|
+
end
|
77
|
+
|
78
|
+
assert_raises Striuct::ConditionError do
|
79
|
+
User.new 'asda'
|
80
|
+
end
|
81
|
+
|
82
|
+
assert_raises Striuct::ConditionError do
|
83
|
+
user.age = 19
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_equal
|
88
|
+
user1 = User.new 11218, 'taro'
|
89
|
+
user2 = User.new 11218, 'taro'
|
90
|
+
assert_equal true, (user1 == user2)
|
91
|
+
user2.last_name = 'ichiro'
|
92
|
+
assert_equal false, (user1 == user2)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
class TestStriuctSubclassInstance2 < Test::Unit::TestCase
|
97
|
+
def setup
|
98
|
+
@user = User.new 9999, 'taro', 'yamada', 'Tokyo Japan', 30
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_reader
|
102
|
+
assert_equal @user[1], 'taro'
|
103
|
+
assert_equal @user[:last_name], 'taro'
|
104
|
+
assert_equal @user.last_name, 'taro'
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_setter_pass
|
108
|
+
assert_equal (@user.id = 2139203509295), 2139203509295
|
109
|
+
assert_equal @user.id, 2139203509295
|
110
|
+
assert_equal (@user.last_name = 'jiro'), 'jiro'
|
111
|
+
assert_equal @user.last_name, 'jiro'
|
112
|
+
assert_equal (@user.age = 40), 40
|
113
|
+
assert_equal @user.age, 40
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_setter_fail
|
117
|
+
assert_raises Striuct::ConditionError do
|
118
|
+
@user.id = 2139203509295.0
|
119
|
+
end
|
120
|
+
|
121
|
+
assert_raises Striuct::ConditionError do
|
122
|
+
@user.last_name = 'ignore name'
|
123
|
+
end
|
124
|
+
|
125
|
+
assert_raises Striuct::ConditionError do
|
126
|
+
@user.age = 19
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_strict?
|
131
|
+
assert_same @user.sufficent?(:last_name), true
|
132
|
+
assert_same @user.strict?, true
|
133
|
+
assert_same @user.sufficent?(:last_name), true
|
134
|
+
@user.last_name.clear
|
135
|
+
assert_same @user.sufficent?(:last_name), false
|
136
|
+
assert_same @user.strict?, false
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
class TestStriuctSubclassInstance3 < Test::Unit::TestCase
|
141
|
+
def setup
|
142
|
+
@user = User.new 9999, 'taro', 'yamada', 'Tokyo Japan', 30
|
143
|
+
@user2 = User.new 9999, 'taro', 'yamada', 'Tokyo Japan', 30
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_to_s
|
147
|
+
/\b(taro)\b/ =~ @user.to_s
|
148
|
+
assert_equal 'taro', $1
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_inspect
|
152
|
+
/\b(taro)\b/ =~ @user.inspect
|
153
|
+
assert_equal 'taro', $1
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_members
|
157
|
+
assert_equal @user.members, [:id, :last_name, :family_name, :address, :age]
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_delegate_class_method
|
161
|
+
assert_equal @user.members, User.members
|
162
|
+
assert_equal @user.size, User.size
|
163
|
+
assert_equal @user.member?(:age), User.member?(:age)
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_each
|
167
|
+
assert_same @user, @user.each{}
|
168
|
+
assert_kind_of Enumerator, enum = @user.each
|
169
|
+
assert_equal enum.next, 9999
|
170
|
+
assert_equal enum.next, 'taro'
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_each_member
|
174
|
+
assert_same @user, @user.each_member{}
|
175
|
+
assert_kind_of Enumerator, enum = @user.each_member
|
176
|
+
assert_equal enum.next, :id
|
177
|
+
assert_equal enum.next, :last_name
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_values
|
181
|
+
assert_equal @user.values, [9999, 'taro', 'yamada', 'Tokyo Japan', 30]
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_values_at
|
185
|
+
assert_equal(@user.values_at(4, 0, (2..4)), [30, 9999, 'yamada', 'Tokyo Japan', 30])
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_hash
|
189
|
+
assert_kind_of Integer, @user.hash
|
190
|
+
assert_equal @user.hash, @user2.hash
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_eql?
|
194
|
+
assert_equal true, @user.eql?(@user2)
|
195
|
+
assert_equal true, @user2.eql?(@user)
|
196
|
+
assert_equal false, @user.eql?(User.new 9999, 'taro', 'yamada', 'Tokyo Japan', 31)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
|
201
|
+
class TestStriuctSubclassInstance4 < Test::Unit::TestCase
|
202
|
+
class Sth < Striuct.new
|
203
|
+
member :bool, true, false
|
204
|
+
member :sth
|
205
|
+
protect_level :struct
|
206
|
+
member :lambda, ->v{v % 3 == 2}, ->v{v.kind_of? Float}
|
207
|
+
end
|
208
|
+
|
209
|
+
def setup
|
210
|
+
@sth = Sth.new
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_accessor
|
214
|
+
@sth.bool = true
|
215
|
+
assert_same true, @sth.bool
|
216
|
+
@sth.bool = false
|
217
|
+
assert_same false, @sth.bool
|
218
|
+
|
219
|
+
assert_raises Striuct::ConditionError do
|
220
|
+
@sth.bool = nil
|
221
|
+
end
|
222
|
+
|
223
|
+
@sth.sth = 1
|
224
|
+
assert_same 1, @sth.sth
|
225
|
+
|
226
|
+
@sth.sth = 'String'
|
227
|
+
assert_equal 'String', @sth.sth
|
228
|
+
|
229
|
+
@sth.sth = Class.class
|
230
|
+
assert_same Class.class, @sth.sth
|
231
|
+
|
232
|
+
assert_raises Striuct::ConditionError do
|
233
|
+
@sth.lambda = 9
|
234
|
+
end
|
235
|
+
|
236
|
+
assert_raises Striuct::ConditionError do
|
237
|
+
@sth.lambda = 7
|
238
|
+
end
|
239
|
+
|
240
|
+
@sth.lambda = 8
|
241
|
+
assert_same 8, @sth.lambda
|
242
|
+
|
243
|
+
@sth.lambda = 9.0
|
244
|
+
assert_equal 9.0, @sth.lambda
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
class TestStriuctCloning < Test::Unit::TestCase
|
249
|
+
class Sth < Striuct.new
|
250
|
+
member :sth
|
251
|
+
end
|
252
|
+
|
253
|
+
def setup
|
254
|
+
@sth = Sth.new
|
255
|
+
end
|
256
|
+
|
257
|
+
def test_clone
|
258
|
+
sth2 = @sth.dup
|
259
|
+
@sth.sth = 1
|
260
|
+
assert_equal false, (@sth.sth == sth2.sth)
|
261
|
+
|
262
|
+
sth2 = @sth.clone
|
263
|
+
@sth.sth = 2
|
264
|
+
assert_equal false, (@sth.sth == sth2.sth)
|
265
|
+
end
|
266
|
+
|
267
|
+
def test_class_clone
|
268
|
+
klass = Sth.dup
|
269
|
+
Sth.__send__ :member, :dummy1
|
270
|
+
assert_equal false, klass.member?(:dummy)
|
271
|
+
|
272
|
+
klass = Sth.clone
|
273
|
+
Sth.__send__ :member, :dummy2
|
274
|
+
assert_equal false, klass.member?(:dummy)
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
class TestStriuctProcedure < Test::Unit::TestCase
|
279
|
+
Sth = Striuct.new do
|
280
|
+
member :age, /\A\d+\z/, Numeric do |arg|
|
281
|
+
Integer arg
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
def setup
|
286
|
+
@sth = Sth.new
|
287
|
+
assert_same nil, @sth.age
|
288
|
+
end
|
289
|
+
|
290
|
+
def test_procedure
|
291
|
+
@sth.age = 10
|
292
|
+
assert_same 10, @sth.age
|
293
|
+
@sth.age = 10.0
|
294
|
+
assert_same 10, @sth.age
|
295
|
+
|
296
|
+
assert_raises Striuct::ConditionError do
|
297
|
+
@sth.age = '10.0'
|
298
|
+
end
|
299
|
+
|
300
|
+
@sth.age = '10'
|
301
|
+
assert_same 10, @sth.age
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
class TestStriuctDefaultValue < Test::Unit::TestCase
|
306
|
+
Sth = Striuct.new do
|
307
|
+
member :lank, Integer
|
308
|
+
default :lank, 1
|
309
|
+
end
|
310
|
+
|
311
|
+
def test_default
|
312
|
+
sth = Sth.new 2
|
313
|
+
assert_equal 2, sth.lank
|
314
|
+
sth = Sth.new
|
315
|
+
assert_equal 1, sth.lank
|
316
|
+
assert_equal true, sth.default?(:lank)
|
317
|
+
sth.lank = 2
|
318
|
+
assert_equal false, sth.default?(:lank)
|
319
|
+
end
|
320
|
+
|
321
|
+
def test_define_default
|
322
|
+
assert_raises NameError do
|
323
|
+
Sth.class_eval do
|
324
|
+
default :anything, 10
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
assert_raises Striuct::ConditionError do
|
329
|
+
Sth.class_eval do
|
330
|
+
member :lank2, Integer
|
331
|
+
default :lank2, '10'
|
332
|
+
end
|
333
|
+
end
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
class TestStriuctFunctionalCondition < Test::Unit::TestCase
|
338
|
+
Sthlambda = Striuct.new do
|
339
|
+
member :lank, ->lank{lanks.include? lank}
|
340
|
+
member :lanks
|
341
|
+
default :lanks, 1..30
|
342
|
+
end
|
343
|
+
|
344
|
+
def test_lambda
|
345
|
+
sth = Sthlambda.new
|
346
|
+
sth.lank = 2
|
347
|
+
assert_equal 2, sth.lank
|
348
|
+
|
349
|
+
assert_raises Striuct::ConditionError do
|
350
|
+
sth.lank = 31
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
max = 9
|
355
|
+
|
356
|
+
SthProc = Striuct.new do
|
357
|
+
member :lank, Proc.new{|n|(3..max) === n}
|
358
|
+
end
|
359
|
+
|
360
|
+
def test_Proc
|
361
|
+
sth = SthProc.new
|
362
|
+
sth.lank = 8
|
363
|
+
assert_equal 8, sth.lank
|
364
|
+
|
365
|
+
assert_raises Striuct::ConditionError do
|
366
|
+
sth.lank = 2
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
SthMethod = Striuct.new do
|
371
|
+
member :lank, 7.method(:<)
|
372
|
+
end
|
373
|
+
|
374
|
+
def test_Method
|
375
|
+
sth = SthMethod.new
|
376
|
+
sth.lank = 8
|
377
|
+
assert_equal 8, sth.lank
|
378
|
+
|
379
|
+
assert_raises Striuct::ConditionError do
|
380
|
+
sth.lank = 6
|
381
|
+
end
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
385
|
+
class TestStriuctAssign < Test::Unit::TestCase
|
386
|
+
Sth = Striuct.new do
|
387
|
+
member :foo
|
388
|
+
end
|
389
|
+
|
390
|
+
def test_unassign
|
391
|
+
sth = Sth.new
|
392
|
+
assert_equal false, sth.assign?(:foo)
|
393
|
+
sth.foo = nil
|
394
|
+
assert_equal true, sth.assign?(:foo)
|
395
|
+
sth.unassign :foo
|
396
|
+
assert_equal false, sth.assign?(:foo)
|
397
|
+
|
398
|
+
assert_raises NameError do
|
399
|
+
sth.unassign :var
|
400
|
+
end
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
class TestStriuctClassLock < Test::Unit::TestCase
|
405
|
+
Sth = Striuct.new do
|
406
|
+
member :foo
|
407
|
+
end
|
408
|
+
|
409
|
+
def test_class_lock
|
410
|
+
sth = Sth.new
|
411
|
+
|
412
|
+
assert_equal true, sth.member?(:foo)
|
413
|
+
|
414
|
+
Sth.class_eval do
|
415
|
+
member :bar
|
416
|
+
end
|
417
|
+
|
418
|
+
assert_equal true, sth.member?(:bar)
|
419
|
+
assert_equal [:foo, :bar], sth.members
|
420
|
+
|
421
|
+
assert_equal false, Sth.closed?
|
422
|
+
|
423
|
+
Sth.__send__ :close
|
424
|
+
|
425
|
+
assert_equal true, Sth.closed?
|
426
|
+
|
427
|
+
assert_raises RuntimeError do
|
428
|
+
Sth.class_eval do
|
429
|
+
member :var2
|
430
|
+
end
|
431
|
+
end
|
432
|
+
|
433
|
+
assert_equal false, sth.member?(:var2)
|
434
|
+
end
|
435
|
+
end
|
436
|
+
|
437
|
+
class TestStriuctDefine < Test::Unit::TestCase
|
438
|
+
def test_define
|
439
|
+
assert_raises RuntimeError do
|
440
|
+
Striuct.define do
|
441
|
+
end
|
442
|
+
end
|
443
|
+
|
444
|
+
klass = Striuct.define do
|
445
|
+
member :foo
|
446
|
+
end
|
447
|
+
|
448
|
+
assert_equal true, klass.closed?
|
449
|
+
end
|
450
|
+
end
|
451
|
+
|
452
|
+
class TestStriuctFreeze < Test::Unit::TestCase
|
453
|
+
Sth = Striuct.new :foo
|
454
|
+
|
455
|
+
def test_freeze
|
456
|
+
sth = Sth.new
|
457
|
+
sth.freeze
|
458
|
+
|
459
|
+
assert_raises RuntimeError do
|
460
|
+
sth.foo = 8
|
461
|
+
end
|
462
|
+
|
463
|
+
assert_equal true, sth.frozen?
|
464
|
+
end
|
465
|
+
end
|
466
|
+
|
467
|
+
|
468
|
+
class TestStriuctSafetyNaming < Test::Unit::TestCase
|
469
|
+
def test_cname?
|
470
|
+
klass = Striuct.new
|
471
|
+
assert_same false, klass.cname?(Object)
|
472
|
+
assert_same false, klass.cname?('m?')
|
473
|
+
assert_same false, klass.cname?('__foo__')
|
474
|
+
assert_same false, klass.cname?('a b')
|
475
|
+
assert_same false, klass.cname?('object_id')
|
476
|
+
assert_same true, klass.cname?('foo')
|
477
|
+
klass.__send__ :protect_level, :warning
|
478
|
+
assert_same false, klass.cname?('m?')
|
479
|
+
assert_same false, klass.cname?('__foo__')
|
480
|
+
assert_same false, klass.cname?('a b')
|
481
|
+
assert_same false, klass.cname?('object_id')
|
482
|
+
assert_same true, klass.cname?('foo')
|
483
|
+
klass.__send__ :protect_level, :struct
|
484
|
+
assert_same true, klass.cname?('m?')
|
485
|
+
assert_same true, klass.cname?('__foo__')
|
486
|
+
assert_same true, klass.cname?('a b')
|
487
|
+
assert_same true, klass.cname?('object_id')
|
488
|
+
assert_same true, klass.cname?('foo')
|
489
|
+
end
|
490
|
+
|
491
|
+
def test_protect
|
492
|
+
klass = Striuct.new
|
493
|
+
assert_raises NameError do
|
494
|
+
klass.class_eval do
|
495
|
+
member ''
|
496
|
+
end
|
497
|
+
end
|
498
|
+
|
499
|
+
assert_raises NameError do
|
500
|
+
klass.class_eval do
|
501
|
+
member :'a b'
|
502
|
+
end
|
503
|
+
end
|
504
|
+
|
505
|
+
assert_raises NameError do
|
506
|
+
klass.class_eval do
|
507
|
+
member :'__send__'
|
508
|
+
end
|
509
|
+
end
|
510
|
+
|
511
|
+
assert_raises NameError do
|
512
|
+
klass.class_eval do
|
513
|
+
member :'__foo__'
|
514
|
+
end
|
515
|
+
end
|
516
|
+
|
517
|
+
assert_raises NameError do
|
518
|
+
klass.class_eval do
|
519
|
+
member :'m?'
|
520
|
+
end
|
521
|
+
end
|
522
|
+
|
523
|
+
assert_same false, klass.member?('m?')
|
524
|
+
|
525
|
+
klass.class_eval do
|
526
|
+
protect_level :struct
|
527
|
+
member :'m?'
|
528
|
+
end
|
529
|
+
|
530
|
+
assert_same true, klass.member?('m?')
|
531
|
+
end
|
532
|
+
end
|
533
|
+
|
534
|
+
class TestStriuctInference < Test::Unit::TestCase
|
535
|
+
def test_inference
|
536
|
+
klass = Striuct.define do
|
537
|
+
member :n, Numeric, inference
|
538
|
+
member :m, inference
|
539
|
+
end
|
540
|
+
|
541
|
+
sth, sth2 = klass.new, klass.new
|
542
|
+
|
543
|
+
assert_raises Striuct::ConditionError do
|
544
|
+
sth.n = '1'
|
545
|
+
end
|
546
|
+
|
547
|
+
sth.n = 1.1
|
548
|
+
|
549
|
+
assert_equal 1.1, sth.n
|
550
|
+
|
551
|
+
assert_raises Striuct::ConditionError do
|
552
|
+
sth.n = 1
|
553
|
+
end
|
554
|
+
|
555
|
+
assert_raises Striuct::ConditionError do
|
556
|
+
sth2.n = 1
|
557
|
+
end
|
558
|
+
|
559
|
+
sth.n = 2.1
|
560
|
+
|
561
|
+
assert_equal 2.1, sth.n
|
562
|
+
|
563
|
+
|
564
|
+
sth2.m = 1
|
565
|
+
|
566
|
+
assert_equal 1, sth2.m
|
567
|
+
|
568
|
+
assert_raises Striuct::ConditionError do
|
569
|
+
sth.m = 1.0
|
570
|
+
end
|
571
|
+
|
572
|
+
assert_raises Striuct::ConditionError do
|
573
|
+
sth2.m = 1.0
|
574
|
+
end
|
575
|
+
|
576
|
+
sth.m = 2
|
577
|
+
|
578
|
+
assert_equal 2, sth.m
|
579
|
+
end
|
580
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
$VERBOSE = true
|
2
|
+
require File.dirname(__FILE__) + '/test_helper_import.rb'
|
3
|
+
|
4
|
+
|
5
|
+
class TestStruct < Test::Unit::TestCase
|
6
|
+
Sth = Struct.new :age
|
7
|
+
Sth2 = Sth.to_strict
|
8
|
+
|
9
|
+
def test_eigen_boolean
|
10
|
+
assert_equal true, Sth.member?(:age)
|
11
|
+
assert_equal false, Sth.conditionable?(BasicObject.new)
|
12
|
+
assert_equal false, Sth.restrict?(:age)
|
13
|
+
assert_equal true, Sth.accept?(:age, 'String')
|
14
|
+
assert_equal false, Sth.has_default?(:age)
|
15
|
+
assert_equal true, Sth.cname?(:age)
|
16
|
+
assert_equal false, Sth.cname?(Object.new)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_eigen_actions
|
20
|
+
r = Sth.define{|o|o.age = 'Something'}
|
21
|
+
assert_kind_of Sth, r
|
22
|
+
assert_equal 'Something', r.age
|
23
|
+
assert_equal StrictStruct, Sth2.superclass
|
24
|
+
assert_equal Sth.members, Sth2.members
|
25
|
+
|
26
|
+
r2 = Sth.load_pairs age: 1
|
27
|
+
assert_equal 1, r2.age
|
28
|
+
|
29
|
+
assert_raises ArgumentError do
|
30
|
+
Sth.load_pairs age: 1, name: 'taro'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_instance_boolean
|
35
|
+
sth = Sth.new
|
36
|
+
assert_equal false, sth.strict?
|
37
|
+
assert_equal false, sth.secure?
|
38
|
+
assert_equal false, sth.assign?(:age)
|
39
|
+
sth.age = 'Something'
|
40
|
+
assert_equal true, sth.assign?(:age)
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: striuct
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.11.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kenichi Kamiya
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-12-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: hoe
|
16
|
+
requirement: &24039228 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.12'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *24039228
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rdoc
|
27
|
+
requirement: &20489640 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3.10'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *20489640
|
36
|
+
description: ! 'Striuct means Strict Struct.
|
37
|
+
|
38
|
+
Handy and safty than Ruby''s Standard Struct.'
|
39
|
+
email:
|
40
|
+
- kachick1+ruby@gmail.com
|
41
|
+
executables: []
|
42
|
+
extensions: []
|
43
|
+
extra_rdoc_files:
|
44
|
+
- Manifest.txt
|
45
|
+
files:
|
46
|
+
- History.rdoc
|
47
|
+
- Manifest.txt
|
48
|
+
- README.rdoc
|
49
|
+
- README.ja.rdoc
|
50
|
+
- Rakefile
|
51
|
+
- example.rb
|
52
|
+
- lib/striuct.rb
|
53
|
+
- lib/striuct/core.rb
|
54
|
+
- lib/striuct/version.rb
|
55
|
+
- lib/striuct/classutil.rb
|
56
|
+
- lib/striuct/subclass.rb
|
57
|
+
- lib/striuct/subclass_eigen.rb
|
58
|
+
- lib/striuct/import.rb
|
59
|
+
- test/test_helper.rb
|
60
|
+
- test/test_striuct.rb
|
61
|
+
- test/test_helper_import.rb
|
62
|
+
- test/test_striuct_import.rb
|
63
|
+
- .gemtest
|
64
|
+
homepage: http://github.com/kachick/striuct
|
65
|
+
licenses: []
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options:
|
68
|
+
- --main
|
69
|
+
- README.rdoc
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project: striuct
|
86
|
+
rubygems_version: 1.8.12
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: Striuct means Strict Struct
|
90
|
+
test_files:
|
91
|
+
- test/test_helper.rb
|
92
|
+
- test/test_helper_import.rb
|
93
|
+
- test/test_striuct.rb
|
94
|
+
- test/test_striuct_import.rb
|