striuct 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +35 -34
- data/.travis.yml +6 -6
- data/Gemfile +12 -12
- data/History.rdoc +279 -273
- data/LICENSE +21 -21
- data/Manifest.txt +91 -90
- data/README.ja.old.rdoc +297 -297
- data/README.md +128 -128
- data/Rakefile +11 -11
- data/benchmark/basics.rb +56 -56
- data/example/README.rb +44 -44
- data/example/example.old.rdoc +187 -187
- data/example/example1.rb +233 -233
- data/example/example2.rb +22 -22
- data/example/see_trace.rb +32 -32
- data/lib/striuct/classmethods/README.md +5 -5
- data/lib/striuct/classmethods/adjustment.rb +32 -32
- data/lib/striuct/classmethods/constructor.rb +63 -63
- data/lib/striuct/classmethods/default.rb +27 -27
- data/lib/striuct/classmethods/enum.rb +48 -48
- data/lib/striuct/classmethods/inner.rb +91 -91
- data/lib/striuct/classmethods/length.rb +14 -14
- data/lib/striuct/classmethods/macro.rb +144 -144
- data/lib/striuct/classmethods/named.rb +113 -113
- data/lib/striuct/classmethods/object.rb +54 -54
- data/lib/striuct/classmethods/prevent_conflicts.rb +89 -89
- data/lib/striuct/classmethods/requiremnets.rb +11 -11
- data/lib/striuct/classmethods/to_struct.rb +23 -25
- data/lib/striuct/classmethods/validation.rb +55 -55
- data/lib/striuct/classmethods.rb +1 -1
- data/lib/striuct/instancemethods/README.md +5 -5
- data/lib/striuct/instancemethods/assign.rb +30 -30
- data/lib/striuct/instancemethods/cast.rb +34 -34
- data/lib/striuct/instancemethods/compare.rb +30 -30
- data/lib/striuct/instancemethods/default.rb +13 -13
- data/lib/striuct/instancemethods/delegate_class_methods.rb +28 -28
- data/lib/striuct/instancemethods/enum.rb +103 -103
- data/lib/striuct/instancemethods/hashy.rb +121 -121
- data/lib/striuct/instancemethods/inner.rb +60 -60
- data/lib/striuct/instancemethods/keyvalidatable.rb +14 -14
- data/lib/striuct/instancemethods/lock.rb +61 -61
- data/lib/striuct/instancemethods/object.rb +52 -52
- data/lib/striuct/instancemethods/requirements.rb +14 -14
- data/lib/striuct/instancemethods/safety.rb +11 -11
- data/lib/striuct/instancemethods/subscript.rb +55 -55
- data/lib/striuct/instancemethods/validation.rb +29 -25
- data/lib/striuct/instancemethods/values.rb +57 -57
- data/lib/striuct/instancemethods.rb +1 -1
- data/lib/striuct/requirements.rb +5 -5
- data/lib/striuct/singleton_class.rb +66 -66
- data/lib/striuct/specificcontainer.rb +19 -19
- data/lib/striuct/structs.rb +7 -7
- data/lib/striuct/version.rb +5 -5
- data/lib/striuct.rb +13 -13
- data/striuct.gemspec +24 -24
- data/test/helper.rb +5 -5
- data/test/test_striuct-singleton_class-define.rb +19 -19
- data/test/test_striuct-subclass-class-cloning.rb +20 -20
- data/test/test_striuct-subclass-class-close.rb +36 -36
- data/test/test_striuct-subclass-class-constructor.rb +82 -82
- data/test/test_striuct-subclass-class-freeze.rb +36 -36
- data/test/test_striuct-subclass-class-inheritable.rb +57 -57
- data/test/test_striuct-subclass-class-macro.rb +13 -13
- data/test/test_striuct-subclass-class-safety_naming.rb +72 -72
- data/test/test_striuct-subclass-class-validation.rb +26 -26
- data/test/test_striuct-subclass-feature-alias_member.rb +53 -53
- data/test/test_striuct-subclass-feature-to_struct.rb +61 -25
- data/test/test_striuct-subclass-feature-validation_util.rb +57 -0
- data/test/test_striuct-subclass-instance-accessor.rb +137 -137
- data/test/test_striuct-subclass-instance-adjuster.rb +94 -94
- data/test/test_striuct-subclass-instance-assign.rb +30 -30
- data/test/test_striuct-subclass-instance-basic.rb +32 -32
- data/test/test_striuct-subclass-instance-cloning.rb +22 -22
- data/test/test_striuct-subclass-instance-compare.rb +51 -51
- data/test/test_striuct-subclass-instance-default_value.rb +128 -128
- data/test/test_striuct-subclass-instance-enum.rb +92 -92
- data/test/test_striuct-subclass-instance-freeze.rb +19 -19
- data/test/test_striuct-subclass-instance-hashlike.rb +153 -153
- data/test/test_striuct-subclass-instance-keyvalidatable.rb +24 -24
- data/test/test_striuct-subclass-instance-lock.rb +39 -39
- data/test/test_striuct-subclass-instance-to_s_family.rb +25 -25
- data/test/test_striuct-subclass-instance-validation_functional_condition.rb +50 -50
- data/test/test_striuct-subclass-instance-validation_inference.rb +50 -50
- data/test/test_striuct-subclass-instance-validation_specific_conditions.rb +247 -247
- data/test/test_striuct-subclass-instance-validation_with_getter.rb +33 -33
- data/test/test_striuct-subclass-instance_names.rb +18 -18
- data/test/test_striuct-version.rb +10 -10
- metadata +4 -2
@@ -1,153 +1,153 @@
|
|
1
|
-
require_relative 'helper'
|
2
|
-
|
3
|
-
class Test_Striuct_Subclass_Instance_HashLike < Test::Unit::TestCase
|
4
|
-
|
5
|
-
Sth = Striuct.new :foo, :bar, :hoge
|
6
|
-
|
7
|
-
def test_empty?
|
8
|
-
sth = Sth[hoge: 7, foo: 8]
|
9
|
-
assert_equal false, sth.empty?
|
10
|
-
sth.each_member{|name|sth[name] = nil}
|
11
|
-
assert_equal false, sth.empty?
|
12
|
-
sth.each_member{|name|sth.unassign name}
|
13
|
-
assert_equal true, sth.empty?
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_has_value?
|
17
|
-
sth = Sth[hoge: 7, foo: 8]
|
18
|
-
assert_equal true, sth.value?(7)
|
19
|
-
assert_equal true, sth.value?(8)
|
20
|
-
assert_equal false, sth.value?(9)
|
21
|
-
assert_equal false, sth.value?(nil)
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_select!
|
25
|
-
sth = Sth[hoge: 7, foo: 8]
|
26
|
-
sth2, sth3 = sth.dup, sth.dup
|
27
|
-
|
28
|
-
assert_kind_of Enumerator, enum = sth.select!
|
29
|
-
assert_equal [:foo, 8], enum.next
|
30
|
-
assert_equal [:bar, nil], enum.next
|
31
|
-
assert_equal [:hoge, 7], enum.next
|
32
|
-
assert_raises StopIteration do
|
33
|
-
enum.next
|
34
|
-
end
|
35
|
-
|
36
|
-
assert_equal nil, sth2.select!{|k, v|true}
|
37
|
-
assert_equal sth3, sth3.select!{|k, v|k == :hoge && v == 7}
|
38
|
-
assert_equal nil, sth3.foo
|
39
|
-
assert_equal true, sth3.assign?(:hoge)
|
40
|
-
assert_equal false, sth3.assign?(:foo)
|
41
|
-
assert_equal 7, sth3.hoge
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_keep_if
|
45
|
-
sth = Sth[hoge: 7, foo: 8]
|
46
|
-
sth2, sth3 = sth.dup, sth.dup
|
47
|
-
|
48
|
-
assert_kind_of Enumerator, enum = sth.keep_if
|
49
|
-
assert_equal [:foo, 8], enum.next
|
50
|
-
assert_equal [:bar, nil], enum.next
|
51
|
-
assert_equal [:hoge, 7], enum.next
|
52
|
-
assert_raises StopIteration do
|
53
|
-
enum.next
|
54
|
-
end
|
55
|
-
|
56
|
-
assert_equal sth2, sth2.keep_if{|k, v|true}
|
57
|
-
assert_equal sth3, sth3.keep_if{|k, v|k == :hoge && v == 7}
|
58
|
-
assert_equal nil, sth3.foo
|
59
|
-
assert_equal true, sth3.assign?(:hoge)
|
60
|
-
assert_equal false, sth3.assign?(:foo)
|
61
|
-
assert_equal 7, sth3.hoge
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_reject!
|
65
|
-
sth = Sth[hoge: 7, foo: 8]
|
66
|
-
sth2, sth3 = sth.dup, sth.dup
|
67
|
-
|
68
|
-
assert_kind_of Enumerator, enum = sth.reject!
|
69
|
-
assert_equal [:foo, 8], enum.next
|
70
|
-
assert_equal [:bar, nil], enum.next
|
71
|
-
assert_equal [:hoge, 7], enum.next
|
72
|
-
assert_raises StopIteration do
|
73
|
-
enum.next
|
74
|
-
end
|
75
|
-
|
76
|
-
enum.rewind
|
77
|
-
assert_equal [:foo, 8], enum.next
|
78
|
-
|
79
|
-
assert_equal nil, sth2.reject!{|k, v|false}
|
80
|
-
assert_equal sth3, sth3.reject!{|k, v|k == :hoge && v == 7}
|
81
|
-
assert_equal nil, sth3.hoge
|
82
|
-
assert_equal false, sth3.assign?(:hoge)
|
83
|
-
assert_equal true, sth3.assign?(:foo)
|
84
|
-
assert_equal 8, sth3.foo
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_delete_if
|
88
|
-
sth = Sth[hoge: 7, foo: 8]
|
89
|
-
sth2, sth3 = sth.dup, sth.dup
|
90
|
-
|
91
|
-
assert_kind_of Enumerator, enum = sth.delete_if
|
92
|
-
|
93
|
-
assert_equal [:foo, 8], enum.next
|
94
|
-
assert_equal [:bar, nil], enum.next
|
95
|
-
assert_equal [:hoge, 7], enum.next
|
96
|
-
assert_raises StopIteration do
|
97
|
-
enum.next
|
98
|
-
end
|
99
|
-
|
100
|
-
assert_equal sth2, sth2.delete_if{|k, v|false}
|
101
|
-
assert_equal sth3, sth3.delete_if{|k, v|k == :hoge && v == 7}
|
102
|
-
assert_equal nil, sth3.hoge
|
103
|
-
assert_equal false, sth3.assign?(:hoge)
|
104
|
-
assert_equal true, sth3.assign?(:foo)
|
105
|
-
assert_equal 8, sth3.foo
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_assoc
|
109
|
-
sth = Sth[hoge: 7, foo: 8]
|
110
|
-
|
111
|
-
assert_equal [:foo, 8], sth.assoc(:foo)
|
112
|
-
assert_equal [:bar, nil], sth.assoc(:bar)
|
113
|
-
assert_equal [:hoge, 7], sth.assoc(:hoge)
|
114
|
-
|
115
|
-
assert_raises NameError do
|
116
|
-
sth.assoc(:dummy)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_rassoc
|
121
|
-
sth = Sth[hoge: 7, foo: 7]
|
122
|
-
|
123
|
-
assert_equal [:foo, 7], sth.rassoc(7)
|
124
|
-
assert_equal [:bar, nil], sth.rassoc(nil)
|
125
|
-
assert_equal nil, sth.rassoc(9)
|
126
|
-
end
|
127
|
-
|
128
|
-
def test_flatten
|
129
|
-
sth = Sth[hoge: 7, foo: 8, bar: [1, 2]]
|
130
|
-
assert_equal [:foo, 8, :bar, [1, 2], :hoge, 7], sth.flatten
|
131
|
-
assert_equal [:foo, 8, :bar, [1, 2], :hoge, 7], sth.flatten(1)
|
132
|
-
assert_equal [:foo, 8, :bar, 1, 2, :hoge, 7], sth.flatten(2)
|
133
|
-
assert_equal [:foo, 8, :bar, 1, 2, :hoge, 7], sth.flatten(3)
|
134
|
-
assert_equal [:foo, 8, :bar, 1, 2, :hoge, 7], sth.flatten(-1)
|
135
|
-
end
|
136
|
-
|
137
|
-
def test_select
|
138
|
-
sth = Sth[hoge: 7, foo: 8]
|
139
|
-
|
140
|
-
assert_kind_of Enumerator, sth.select
|
141
|
-
|
142
|
-
assert_equal Sth[hoge: 7], sth.select{|k, v|k == :hoge}
|
143
|
-
end
|
144
|
-
|
145
|
-
def test_reject
|
146
|
-
sth = Sth[hoge: 7, foo: 8]
|
147
|
-
|
148
|
-
assert_kind_of Enumerator, sth.reject
|
149
|
-
|
150
|
-
assert_equal Sth[foo: 8], sth.reject{|k, v|k == :hoge}
|
151
|
-
end
|
152
|
-
|
153
|
-
end
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
class Test_Striuct_Subclass_Instance_HashLike < Test::Unit::TestCase
|
4
|
+
|
5
|
+
Sth = Striuct.new :foo, :bar, :hoge
|
6
|
+
|
7
|
+
def test_empty?
|
8
|
+
sth = Sth[hoge: 7, foo: 8]
|
9
|
+
assert_equal false, sth.empty?
|
10
|
+
sth.each_member{|name|sth[name] = nil}
|
11
|
+
assert_equal false, sth.empty?
|
12
|
+
sth.each_member{|name|sth.unassign name}
|
13
|
+
assert_equal true, sth.empty?
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_has_value?
|
17
|
+
sth = Sth[hoge: 7, foo: 8]
|
18
|
+
assert_equal true, sth.value?(7)
|
19
|
+
assert_equal true, sth.value?(8)
|
20
|
+
assert_equal false, sth.value?(9)
|
21
|
+
assert_equal false, sth.value?(nil)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_select!
|
25
|
+
sth = Sth[hoge: 7, foo: 8]
|
26
|
+
sth2, sth3 = sth.dup, sth.dup
|
27
|
+
|
28
|
+
assert_kind_of Enumerator, enum = sth.select!
|
29
|
+
assert_equal [:foo, 8], enum.next
|
30
|
+
assert_equal [:bar, nil], enum.next
|
31
|
+
assert_equal [:hoge, 7], enum.next
|
32
|
+
assert_raises StopIteration do
|
33
|
+
enum.next
|
34
|
+
end
|
35
|
+
|
36
|
+
assert_equal nil, sth2.select!{|k, v|true}
|
37
|
+
assert_equal sth3, sth3.select!{|k, v|k == :hoge && v == 7}
|
38
|
+
assert_equal nil, sth3.foo
|
39
|
+
assert_equal true, sth3.assign?(:hoge)
|
40
|
+
assert_equal false, sth3.assign?(:foo)
|
41
|
+
assert_equal 7, sth3.hoge
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_keep_if
|
45
|
+
sth = Sth[hoge: 7, foo: 8]
|
46
|
+
sth2, sth3 = sth.dup, sth.dup
|
47
|
+
|
48
|
+
assert_kind_of Enumerator, enum = sth.keep_if
|
49
|
+
assert_equal [:foo, 8], enum.next
|
50
|
+
assert_equal [:bar, nil], enum.next
|
51
|
+
assert_equal [:hoge, 7], enum.next
|
52
|
+
assert_raises StopIteration do
|
53
|
+
enum.next
|
54
|
+
end
|
55
|
+
|
56
|
+
assert_equal sth2, sth2.keep_if{|k, v|true}
|
57
|
+
assert_equal sth3, sth3.keep_if{|k, v|k == :hoge && v == 7}
|
58
|
+
assert_equal nil, sth3.foo
|
59
|
+
assert_equal true, sth3.assign?(:hoge)
|
60
|
+
assert_equal false, sth3.assign?(:foo)
|
61
|
+
assert_equal 7, sth3.hoge
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_reject!
|
65
|
+
sth = Sth[hoge: 7, foo: 8]
|
66
|
+
sth2, sth3 = sth.dup, sth.dup
|
67
|
+
|
68
|
+
assert_kind_of Enumerator, enum = sth.reject!
|
69
|
+
assert_equal [:foo, 8], enum.next
|
70
|
+
assert_equal [:bar, nil], enum.next
|
71
|
+
assert_equal [:hoge, 7], enum.next
|
72
|
+
assert_raises StopIteration do
|
73
|
+
enum.next
|
74
|
+
end
|
75
|
+
|
76
|
+
enum.rewind
|
77
|
+
assert_equal [:foo, 8], enum.next
|
78
|
+
|
79
|
+
assert_equal nil, sth2.reject!{|k, v|false}
|
80
|
+
assert_equal sth3, sth3.reject!{|k, v|k == :hoge && v == 7}
|
81
|
+
assert_equal nil, sth3.hoge
|
82
|
+
assert_equal false, sth3.assign?(:hoge)
|
83
|
+
assert_equal true, sth3.assign?(:foo)
|
84
|
+
assert_equal 8, sth3.foo
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_delete_if
|
88
|
+
sth = Sth[hoge: 7, foo: 8]
|
89
|
+
sth2, sth3 = sth.dup, sth.dup
|
90
|
+
|
91
|
+
assert_kind_of Enumerator, enum = sth.delete_if
|
92
|
+
|
93
|
+
assert_equal [:foo, 8], enum.next
|
94
|
+
assert_equal [:bar, nil], enum.next
|
95
|
+
assert_equal [:hoge, 7], enum.next
|
96
|
+
assert_raises StopIteration do
|
97
|
+
enum.next
|
98
|
+
end
|
99
|
+
|
100
|
+
assert_equal sth2, sth2.delete_if{|k, v|false}
|
101
|
+
assert_equal sth3, sth3.delete_if{|k, v|k == :hoge && v == 7}
|
102
|
+
assert_equal nil, sth3.hoge
|
103
|
+
assert_equal false, sth3.assign?(:hoge)
|
104
|
+
assert_equal true, sth3.assign?(:foo)
|
105
|
+
assert_equal 8, sth3.foo
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_assoc
|
109
|
+
sth = Sth[hoge: 7, foo: 8]
|
110
|
+
|
111
|
+
assert_equal [:foo, 8], sth.assoc(:foo)
|
112
|
+
assert_equal [:bar, nil], sth.assoc(:bar)
|
113
|
+
assert_equal [:hoge, 7], sth.assoc(:hoge)
|
114
|
+
|
115
|
+
assert_raises NameError do
|
116
|
+
sth.assoc(:dummy)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_rassoc
|
121
|
+
sth = Sth[hoge: 7, foo: 7]
|
122
|
+
|
123
|
+
assert_equal [:foo, 7], sth.rassoc(7)
|
124
|
+
assert_equal [:bar, nil], sth.rassoc(nil)
|
125
|
+
assert_equal nil, sth.rassoc(9)
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_flatten
|
129
|
+
sth = Sth[hoge: 7, foo: 8, bar: [1, 2]]
|
130
|
+
assert_equal [:foo, 8, :bar, [1, 2], :hoge, 7], sth.flatten
|
131
|
+
assert_equal [:foo, 8, :bar, [1, 2], :hoge, 7], sth.flatten(1)
|
132
|
+
assert_equal [:foo, 8, :bar, 1, 2, :hoge, 7], sth.flatten(2)
|
133
|
+
assert_equal [:foo, 8, :bar, 1, 2, :hoge, 7], sth.flatten(3)
|
134
|
+
assert_equal [:foo, 8, :bar, 1, 2, :hoge, 7], sth.flatten(-1)
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_select
|
138
|
+
sth = Sth[hoge: 7, foo: 8]
|
139
|
+
|
140
|
+
assert_kind_of Enumerator, sth.select
|
141
|
+
|
142
|
+
assert_equal Sth[hoge: 7], sth.select{|k, v|k == :hoge}
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_reject
|
146
|
+
sth = Sth[hoge: 7, foo: 8]
|
147
|
+
|
148
|
+
assert_kind_of Enumerator, sth.reject
|
149
|
+
|
150
|
+
assert_equal Sth[foo: 8], sth.reject{|k, v|k == :hoge}
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
@@ -1,25 +1,25 @@
|
|
1
|
-
require_relative 'helper'
|
2
|
-
|
3
|
-
class Test_Striuct_Subclass_Instance_KeyVallidatable < Test::Unit::TestCase
|
4
|
-
|
5
|
-
Sth = Striuct.new :foo, :bar
|
6
|
-
|
7
|
-
def test_valid_keys?
|
8
|
-
sth = Sth.new
|
9
|
-
assert(sth.valid_keys?(must: [:foo, :bar]))
|
10
|
-
assert(sth.valid_keys?(let: [:foo, :bar]))
|
11
|
-
assert(sth.valid_keys?(must: [:foo], let: [:bar]))
|
12
|
-
assert(sth.valid_keys?(let: [:foo, :bar, :hoge]))
|
13
|
-
assert_same(false, sth.valid_keys?(must: [:foo, :bar, :hoge]))
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_valid_autonyms?
|
17
|
-
sth = Sth.new
|
18
|
-
assert(sth.valid_autonyms?(must: [:foo, :bar]))
|
19
|
-
assert(sth.valid_autonyms?(let: [:foo, :bar]))
|
20
|
-
assert(sth.valid_autonyms?(must: [:foo], let: [:bar]))
|
21
|
-
assert(sth.valid_autonyms?(let: [:foo, :bar, :hoge]))
|
22
|
-
assert_same(false, sth.valid_autonyms?(must: [:foo, :bar, :hoge]))
|
23
|
-
end
|
24
|
-
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
class Test_Striuct_Subclass_Instance_KeyVallidatable < Test::Unit::TestCase
|
4
|
+
|
5
|
+
Sth = Striuct.new :foo, :bar
|
6
|
+
|
7
|
+
def test_valid_keys?
|
8
|
+
sth = Sth.new
|
9
|
+
assert(sth.valid_keys?(must: [:foo, :bar]))
|
10
|
+
assert(sth.valid_keys?(let: [:foo, :bar]))
|
11
|
+
assert(sth.valid_keys?(must: [:foo], let: [:bar]))
|
12
|
+
assert(sth.valid_keys?(let: [:foo, :bar, :hoge]))
|
13
|
+
assert_same(false, sth.valid_keys?(must: [:foo, :bar, :hoge]))
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_valid_autonyms?
|
17
|
+
sth = Sth.new
|
18
|
+
assert(sth.valid_autonyms?(must: [:foo, :bar]))
|
19
|
+
assert(sth.valid_autonyms?(let: [:foo, :bar]))
|
20
|
+
assert(sth.valid_autonyms?(must: [:foo], let: [:bar]))
|
21
|
+
assert(sth.valid_autonyms?(let: [:foo, :bar, :hoge]))
|
22
|
+
assert_same(false, sth.valid_autonyms?(must: [:foo, :bar, :hoge]))
|
23
|
+
end
|
24
|
+
|
25
25
|
end
|
@@ -1,40 +1,40 @@
|
|
1
|
-
require_relative 'helper'
|
2
|
-
|
3
|
-
class Test_Striuct_Subclass_Instance_Lock < Test::Unit::TestCase
|
4
|
-
|
5
|
-
Sth = Striuct.new :foo, :bar
|
6
|
-
Sth.__send__ :close
|
7
|
-
|
8
|
-
def test_lock
|
9
|
-
sth = Sth.new
|
10
|
-
assert_equal false, sth.lock?(:foo)
|
11
|
-
assert_equal false, sth.lock?(:bar)
|
12
|
-
assert_equal false, sth.secure?
|
13
|
-
sth.lock :bar
|
14
|
-
assert_equal true, sth.lock?(:bar)
|
15
|
-
assert_equal false, sth.secure?
|
16
|
-
|
17
|
-
assert_raises RuntimeError do
|
18
|
-
sth.bar = 1
|
19
|
-
end
|
20
|
-
|
21
|
-
sth.__send__ :unlock, :bar
|
22
|
-
|
23
|
-
assert_equal false, sth.lock?(:bar)
|
24
|
-
|
25
|
-
sth.bar = 1
|
26
|
-
assert_equal 1, sth.bar
|
27
|
-
|
28
|
-
sth.lock
|
29
|
-
assert_equal true, sth.lock?(:foo)
|
30
|
-
assert_equal true, sth.lock?(:bar)
|
31
|
-
assert_equal true, sth.lock?
|
32
|
-
|
33
|
-
assert_raises RuntimeError do
|
34
|
-
sth.foo = 1
|
35
|
-
end
|
36
|
-
|
37
|
-
assert_equal true, sth.secure?
|
38
|
-
end
|
39
|
-
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
class Test_Striuct_Subclass_Instance_Lock < Test::Unit::TestCase
|
4
|
+
|
5
|
+
Sth = Striuct.new :foo, :bar
|
6
|
+
Sth.__send__ :close
|
7
|
+
|
8
|
+
def test_lock
|
9
|
+
sth = Sth.new
|
10
|
+
assert_equal false, sth.lock?(:foo)
|
11
|
+
assert_equal false, sth.lock?(:bar)
|
12
|
+
assert_equal false, sth.secure?
|
13
|
+
sth.lock :bar
|
14
|
+
assert_equal true, sth.lock?(:bar)
|
15
|
+
assert_equal false, sth.secure?
|
16
|
+
|
17
|
+
assert_raises RuntimeError do
|
18
|
+
sth.bar = 1
|
19
|
+
end
|
20
|
+
|
21
|
+
sth.__send__ :unlock, :bar
|
22
|
+
|
23
|
+
assert_equal false, sth.lock?(:bar)
|
24
|
+
|
25
|
+
sth.bar = 1
|
26
|
+
assert_equal 1, sth.bar
|
27
|
+
|
28
|
+
sth.lock
|
29
|
+
assert_equal true, sth.lock?(:foo)
|
30
|
+
assert_equal true, sth.lock?(:bar)
|
31
|
+
assert_equal true, sth.lock?
|
32
|
+
|
33
|
+
assert_raises RuntimeError do
|
34
|
+
sth.foo = 1
|
35
|
+
end
|
36
|
+
|
37
|
+
assert_equal true, sth.secure?
|
38
|
+
end
|
39
|
+
|
40
40
|
end
|
@@ -1,25 +1,25 @@
|
|
1
|
-
require_relative 'helper'
|
2
|
-
|
3
|
-
class Test_Striuct_Subclass_Instance_to_s_Family < Test::Unit::TestCase
|
4
|
-
|
5
|
-
class User < Striuct.new
|
6
|
-
member :id, Integer
|
7
|
-
member :last_name, /\A\w+\z/
|
8
|
-
member :family_name, /\A\w+\z/
|
9
|
-
member :address, /\A((\w+) ?)+\z/
|
10
|
-
member :age, ->age{(20..140).include? age}
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_to_s
|
14
|
-
user = User.new 9999, 'taro', 'yamada', 'Tokyo Japan', 30
|
15
|
-
assert_equal %q!#<struct' Test_Striuct_Subclass_Instance_to_s_Family::User id=9999, last_name="taro", family_name="yamada", address="Tokyo Japan", age=30>!,
|
16
|
-
user.to_s
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_inspect
|
20
|
-
user = User.new 9999, 'taro', 'yamada', 'Tokyo Japan', 30
|
21
|
-
assert_equal %q!#<struct' Test_Striuct_Subclass_Instance_to_s_Family::User strict?:true id=9999(valid?:true, lock?:false), last_name="taro"(valid?:true, lock?:false), family_name="yamada"(valid?:true, lock?:false), address="Tokyo Japan"(valid?:true, lock?:false), age=30(valid?:true, lock?:false)>!,
|
22
|
-
user.inspect
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
class Test_Striuct_Subclass_Instance_to_s_Family < Test::Unit::TestCase
|
4
|
+
|
5
|
+
class User < Striuct.new
|
6
|
+
member :id, Integer
|
7
|
+
member :last_name, /\A\w+\z/
|
8
|
+
member :family_name, /\A\w+\z/
|
9
|
+
member :address, /\A((\w+) ?)+\z/
|
10
|
+
member :age, ->age{(20..140).include? age}
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_to_s
|
14
|
+
user = User.new 9999, 'taro', 'yamada', 'Tokyo Japan', 30
|
15
|
+
assert_equal %q!#<struct' Test_Striuct_Subclass_Instance_to_s_Family::User id=9999, last_name="taro", family_name="yamada", address="Tokyo Japan", age=30>!,
|
16
|
+
user.to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_inspect
|
20
|
+
user = User.new 9999, 'taro', 'yamada', 'Tokyo Japan', 30
|
21
|
+
assert_equal %q!#<struct' Test_Striuct_Subclass_Instance_to_s_Family::User strict?:true id=9999(valid?:true, lock?:false), last_name="taro"(valid?:true, lock?:false), family_name="yamada"(valid?:true, lock?:false), address="Tokyo Japan"(valid?:true, lock?:false), age=30(valid?:true, lock?:false)>!,
|
22
|
+
user.inspect
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -1,51 +1,51 @@
|
|
1
|
-
require_relative 'helper'
|
2
|
-
|
3
|
-
class TestStriuctFunctionalCondition < Test::Unit::TestCase
|
4
|
-
|
5
|
-
Sthlambda = Striuct.new do
|
6
|
-
member :lank, ->lank{lanks.include? lank}
|
7
|
-
member :lanks
|
8
|
-
default :lanks, 1..30
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_lambda
|
12
|
-
sth = Sthlambda.new
|
13
|
-
sth.lank = 2
|
14
|
-
assert_equal 2, sth.lank
|
15
|
-
|
16
|
-
assert_raises Validation::InvalidWritingError do
|
17
|
-
sth.lank = 31
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
max = 9
|
22
|
-
|
23
|
-
SthProc = Striuct.new do
|
24
|
-
member :lank, Proc.new{|n|(3..max) === n}
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_Proc
|
28
|
-
sth = SthProc.new
|
29
|
-
sth.lank = 8
|
30
|
-
assert_equal 8, sth.lank
|
31
|
-
|
32
|
-
assert_raises Validation::InvalidWritingError do
|
33
|
-
sth.lank = 2
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
SthMethod = Striuct.new do
|
38
|
-
member :lank, 7.method(:<)
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_Method
|
42
|
-
sth = SthMethod.new
|
43
|
-
sth.lank = 8
|
44
|
-
assert_equal 8, sth.lank
|
45
|
-
|
46
|
-
assert_raises Validation::InvalidWritingError do
|
47
|
-
sth.lank = 6
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
class TestStriuctFunctionalCondition < Test::Unit::TestCase
|
4
|
+
|
5
|
+
Sthlambda = Striuct.new do
|
6
|
+
member :lank, ->lank{lanks.include? lank}
|
7
|
+
member :lanks
|
8
|
+
default :lanks, 1..30
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_lambda
|
12
|
+
sth = Sthlambda.new
|
13
|
+
sth.lank = 2
|
14
|
+
assert_equal 2, sth.lank
|
15
|
+
|
16
|
+
assert_raises Validation::InvalidWritingError do
|
17
|
+
sth.lank = 31
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
max = 9
|
22
|
+
|
23
|
+
SthProc = Striuct.new do
|
24
|
+
member :lank, Proc.new{|n|(3..max) === n}
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_Proc
|
28
|
+
sth = SthProc.new
|
29
|
+
sth.lank = 8
|
30
|
+
assert_equal 8, sth.lank
|
31
|
+
|
32
|
+
assert_raises Validation::InvalidWritingError do
|
33
|
+
sth.lank = 2
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
SthMethod = Striuct.new do
|
38
|
+
member :lank, 7.method(:<)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_Method
|
42
|
+
sth = SthMethod.new
|
43
|
+
sth.lank = 8
|
44
|
+
assert_equal 8, sth.lank
|
45
|
+
|
46
|
+
assert_raises Validation::InvalidWritingError do
|
47
|
+
sth.lank = 6
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
51
|
end
|