rdl 2.0.0.rc4 → 2.0.0.rc5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +56 -84
- data/lib/rdl/boot.rb +4 -0
- data/lib/rdl/boot_rails.rb +3 -1
- data/lib/rdl/contracts/flat.rb +1 -2
- data/lib/rdl/typecheck.rb +138 -27
- data/lib/rdl/types/annotated_arg.rb +8 -0
- data/lib/rdl/types/finite_hash.rb +32 -17
- data/lib/rdl/types/lexer.rex +1 -0
- data/lib/rdl/types/lexer.rex.rb +3 -0
- data/lib/rdl/types/method.rb +24 -4
- data/lib/rdl/types/optional.rb +8 -1
- data/lib/rdl/types/parser.racc +12 -9
- data/lib/rdl/types/parser.tab.rb +293 -255
- data/lib/rdl/types/type.rb +20 -11
- data/lib/rdl/types/union.rb +3 -0
- data/lib/rdl/types/vararg.rb +7 -2
- data/lib/rdl/wrap.rb +15 -2
- data/lib/types/core-ruby-2.x/proc.rb +16 -0
- data/lib/types/rails-5.x/_helpers.rb +20 -0
- data/lib/types/rails-5.x/active_model/errors.rb +15 -0
- data/lib/types/rails-5.x/active_model/validations.rb +5 -0
- data/lib/types/rails-5.x/active_record/associations.rb +190 -0
- data/lib/types/rails-5.x/active_record/core.rb +3 -0
- data/lib/types/rails-5.x/active_record/model_schema.rb +7 -10
- data/rdl.gemspec +2 -2
- data/test/test_le.rb +24 -0
- data/test/test_member.rb +24 -2
- data/test/test_parser.rb +21 -10
- data/test/test_query.rb +5 -2
- data/test/test_type_contract.rb +34 -2
- data/test/test_typecheck.rb +296 -36
- data/test/test_types.rb +8 -4
- metadata +7 -2
data/test/test_member.rb
CHANGED
@@ -119,17 +119,39 @@ class TestMember < Minitest::Test
|
|
119
119
|
end
|
120
120
|
|
121
121
|
def test_finite_hash
|
122
|
-
t1 = FiniteHashType.new(a: $__rdl_symbol_type, b: $__rdl_string_type)
|
122
|
+
t1 = FiniteHashType.new({a: $__rdl_symbol_type, b: $__rdl_string_type}, nil)
|
123
123
|
assert (t1.member?(a: :foo, b: "foo"))
|
124
124
|
assert (not (t1.member?(a: 1, b: "foo")))
|
125
125
|
assert (not (t1.member?(a: :foo)))
|
126
126
|
assert (not (t1.member?(b: "foo")))
|
127
127
|
assert (not (t1.member?(a: :foo, b: "foo", c: :baz)))
|
128
|
-
t2 = FiniteHashType.new({"a"=>$__rdl_symbol_type, 2=>$__rdl_string_type})
|
128
|
+
t2 = FiniteHashType.new({"a"=>$__rdl_symbol_type, 2=>$__rdl_string_type}, nil)
|
129
129
|
assert (t2.member?({"a"=>:foo, 2=>"foo"}))
|
130
130
|
assert (not (t2.member?({"a"=>2, 2=>"foo"})))
|
131
131
|
assert (not (t2.member?({"a"=>:foo})))
|
132
132
|
assert (not (t2.member?({2=>"foo"})))
|
133
133
|
assert (not (t2.member?({"a"=>:foo, 2=>"foo", 3=>"bar"})))
|
134
|
+
t3 = FiniteHashType.new({"a"=>$__rdl_symbol_type, 2=>$__rdl_string_type}, $__rdl_fixnum_type)
|
135
|
+
assert (t3.member?({"a"=>:foo, 2=>"foo"}))
|
136
|
+
assert (t3.member?({"a"=>:foo, 2=>"foo", two: 2}))
|
137
|
+
assert (t3.member?({"a"=>:foo, 2=>"foo", two: 2, three: 3}))
|
138
|
+
assert (not (t3.member?({"a"=>:foo, 2=>"foo", two: 'two'})))
|
139
|
+
assert (not (t3.member?({"a"=>:foo, 2=>"foo", two: 2, three: 'three'})))
|
140
|
+
assert (not (t3.member?({"a"=>:foo, two: 2})))
|
141
|
+
assert (not (t3.member?({2=>"foo", two: 2})))
|
142
|
+
t4 = FiniteHashType.new({a: $__rdl_symbol_type, b: $__rdl_string_type}, $__rdl_fixnum_type)
|
143
|
+
assert (t4.member?(a: :foo, b: "foo"))
|
144
|
+
assert (t4.member?(a: :foo, b: "foo", c: 3))
|
145
|
+
assert (t4.member?(a: :foo, b: "foo", c: 3, d: 4))
|
146
|
+
assert (not (t4.member?(a: :foo, b: "foo", c: "three")))
|
147
|
+
t5 = FiniteHashType.new({a: $__rdl_symbol_type, b: OptionalType.new($__rdl_string_type)}, $__rdl_fixnum_type)
|
148
|
+
assert (t5.member?(a: :foo, b: "foo"))
|
149
|
+
assert (t5.member?(a: :foo, b: "foo", c: 3))
|
150
|
+
assert (t5.member?(a: :foo, b: "foo", c: 3, d: 4))
|
151
|
+
assert (not (t5.member?(a: :foo, b: "foo", c: "three")))
|
152
|
+
assert (t5.member?(a: :foo))
|
153
|
+
assert (t5.member?(a: :foo, c: 3))
|
154
|
+
assert (t5.member?(a: :foo, c: 3, d: 4))
|
155
|
+
assert (not (t5.member?(a: :foo, c: "three")))
|
134
156
|
end
|
135
157
|
end
|
data/test/test_parser.rb
CHANGED
@@ -174,28 +174,30 @@ class TestParser < Minitest::Test
|
|
174
174
|
|
175
175
|
def test_finite_hash
|
176
176
|
t1 = tt "{a: Fixnum, b: String}"
|
177
|
-
assert_equal (FiniteHashType.new({a: $__rdl_fixnum_type, b: $__rdl_string_type})), t1
|
177
|
+
assert_equal (FiniteHashType.new({a: $__rdl_fixnum_type, b: $__rdl_string_type}, nil)), t1
|
178
178
|
t2 = tt "{'a'=>Fixnum, 2=>String}"
|
179
|
-
assert_equal (FiniteHashType.new({"a"=>$__rdl_fixnum_type, 2=>$__rdl_string_type})), t2
|
179
|
+
assert_equal (FiniteHashType.new({"a"=>$__rdl_fixnum_type, 2=>$__rdl_string_type}, nil)), t2
|
180
180
|
end
|
181
181
|
|
182
182
|
def test_named_params
|
183
183
|
t1 = tm "(Fixnum, x: Fixnum) -> Fixnum"
|
184
|
-
assert_equal (MethodType.new [$__rdl_fixnum_type, FiniteHashType.new(x: $__rdl_fixnum_type)], nil, $__rdl_fixnum_type), t1
|
184
|
+
assert_equal (MethodType.new [$__rdl_fixnum_type, FiniteHashType.new({x: $__rdl_fixnum_type}, nil)], nil, $__rdl_fixnum_type), t1
|
185
185
|
t2 = tm "(Fixnum, x: Fixnum, y: String) -> Fixnum"
|
186
|
-
assert_equal (MethodType.new [$__rdl_fixnum_type, FiniteHashType.new(x: $__rdl_fixnum_type, y: $__rdl_string_type)], nil, $__rdl_fixnum_type), t2
|
186
|
+
assert_equal (MethodType.new [$__rdl_fixnum_type, FiniteHashType.new({x: $__rdl_fixnum_type, y: $__rdl_string_type}, nil)], nil, $__rdl_fixnum_type), t2
|
187
187
|
t3 = tm "(Fixnum, y: String, x: Fixnum) -> Fixnum"
|
188
|
-
assert_equal (MethodType.new [$__rdl_fixnum_type, FiniteHashType.new(x: $__rdl_fixnum_type, y: $__rdl_string_type)], nil, $__rdl_fixnum_type), t3
|
188
|
+
assert_equal (MethodType.new [$__rdl_fixnum_type, FiniteHashType.new({x: $__rdl_fixnum_type, y: $__rdl_string_type}, nil)], nil, $__rdl_fixnum_type), t3
|
189
189
|
t4 = tm "(Fixnum, y: String, x: ?Fixnum) -> Fixnum"
|
190
|
-
assert_equal (MethodType.new [$__rdl_fixnum_type, FiniteHashType.new(x: @tfixnumopt, y: $__rdl_string_type)], nil, $__rdl_fixnum_type), t4
|
190
|
+
assert_equal (MethodType.new [$__rdl_fixnum_type, FiniteHashType.new({x: @tfixnumopt, y: $__rdl_string_type}, nil)], nil, $__rdl_fixnum_type), t4
|
191
191
|
t4 = tm "(Fixnum, y: ?String, x: Fixnum) -> Fixnum"
|
192
|
-
assert_equal (MethodType.new [$__rdl_fixnum_type, FiniteHashType.new(x: $__rdl_fixnum_type, y: @tstringopt)], nil, $__rdl_fixnum_type), t4
|
192
|
+
assert_equal (MethodType.new [$__rdl_fixnum_type, FiniteHashType.new({x: $__rdl_fixnum_type, y: @tstringopt}, nil)], nil, $__rdl_fixnum_type), t4
|
193
193
|
t5 = tm "(Fixnum x, x: Fixnum) -> Fixnum"
|
194
|
-
assert_equal (MethodType.new [@tfixnumx, FiniteHashType.new(x: $__rdl_fixnum_type)], nil, $__rdl_fixnum_type), t5
|
194
|
+
assert_equal (MethodType.new [@tfixnumx, FiniteHashType.new({x: $__rdl_fixnum_type}, nil)], nil, $__rdl_fixnum_type), t5
|
195
195
|
t6 = tm "(x: Fixnum) -> Fixnum"
|
196
|
-
assert_equal (MethodType.new [FiniteHashType.new(x: $__rdl_fixnum_type)], nil, $__rdl_fixnum_type), t6
|
196
|
+
assert_equal (MethodType.new [FiniteHashType.new({x: $__rdl_fixnum_type}, nil)], nil, $__rdl_fixnum_type), t6
|
197
197
|
t7 = tm "(x: Fixnum) { (%any, String) -> nil } -> :symbol"
|
198
|
-
assert_equal (MethodType.new [FiniteHashType.new(x: $__rdl_fixnum_type)], MethodType.new([$__rdl_top_type, $__rdl_string_type], nil, $__rdl_nil_type), @tsymbol), t7
|
198
|
+
assert_equal (MethodType.new [FiniteHashType.new({x: $__rdl_fixnum_type}, nil)], MethodType.new([$__rdl_top_type, $__rdl_string_type], nil, $__rdl_nil_type), @tsymbol), t7
|
199
|
+
t8 = tm "(Fixnum, x: Fixnum, **String) -> Fixnum"
|
200
|
+
assert_equal (MethodType.new [$__rdl_fixnum_type, FiniteHashType.new({x: $__rdl_fixnum_type}, $__rdl_string_type)], nil, $__rdl_fixnum_type), t8
|
199
201
|
end
|
200
202
|
|
201
203
|
def test_nonnull
|
@@ -206,4 +208,13 @@ class TestParser < Minitest::Test
|
|
206
208
|
assert_raises(RuntimeError) { tt("!3") }
|
207
209
|
end
|
208
210
|
|
211
|
+
def test_optional_block
|
212
|
+
t1 = tm "() { (%any) -> nil } -> %any"
|
213
|
+
assert_equal (MethodType.new [], MethodType.new([$__rdl_top_type], nil, $__rdl_nil_type), $__rdl_top_type), t1
|
214
|
+
t2 = tm "() ?{ (%any) -> nil } -> %any"
|
215
|
+
assert_equal (MethodType.new [], OptionalType.new(MethodType.new([$__rdl_top_type], nil, $__rdl_nil_type)), $__rdl_top_type), t2
|
216
|
+
t3 = tm "() ?{ (t) -> nil } -> %any"
|
217
|
+
assert_equal (MethodType.new [], OptionalType.new(MethodType.new([VarType.new('t')], nil, $__rdl_nil_type)), $__rdl_top_type), t3
|
218
|
+
end
|
219
|
+
|
209
220
|
end
|
data/test/test_query.rb
CHANGED
@@ -38,9 +38,9 @@ class TestQuery < Minitest::Test
|
|
38
38
|
q10 = @p.scan_str "#Q ([to_str: () -> .]) -> Fixnum"
|
39
39
|
assert_equal (MethodType.new [StructuralType.new(to_str: (MethodType.new [], nil, @qwild))], nil, @tfixnum), q10
|
40
40
|
q11 = @p.scan_str "#Q ({a: Fixnum, b: .}) -> Fixnum"
|
41
|
-
assert_equal (MethodType.new [FiniteHashType.new({a: @tfixnum, b: @qwild})], nil, @tfixnum), q11
|
41
|
+
assert_equal (MethodType.new [FiniteHashType.new({a: @tfixnum, b: @qwild}, nil)], nil, @tfixnum), q11
|
42
42
|
q12 = @p.scan_str "#Q (Fixnum, x: .) -> Fixnum"
|
43
|
-
assert_equal (MethodType.new [@tfixnum, FiniteHashType.new(x: @qwild)], nil, @tfixnum), q12
|
43
|
+
assert_equal (MethodType.new [@tfixnum, FiniteHashType.new({x: @qwild}, nil)], nil, @tfixnum), q12
|
44
44
|
q13 = @p.scan_str "#Q (Fixnum, ..., Fixnum) -> Fixnum"
|
45
45
|
assert_equal (MethodType.new [@tfixnum, @qdots, @tfixnum], nil, @tfixnum), q13
|
46
46
|
q14 = @p.scan_str "#Q (Fixnum, ...) -> Fixnum"
|
@@ -105,5 +105,8 @@ class TestQuery < Minitest::Test
|
|
105
105
|
assert (@p.scan_str "#Q (. x, Fixnum) -> Fixnum").match(t10)
|
106
106
|
assert (@p.scan_str "#Q (String, Fixnum) -> Fixnum").match(t10)
|
107
107
|
assert (@p.scan_str "#Q (., Fixnum) -> Fixnum").match(t10)
|
108
|
+
t11 = @p.scan_str "(Fixnum, x: String, **Float) -> Fixnum"
|
109
|
+
assert (@p.scan_str "#Q (Fixnum, x: String, **Float) -> Fixnum").match(t11)
|
110
|
+
assert (@p.scan_str "#Q (Fixnum, x: String, **.) -> Fixnum").match(t11)
|
108
111
|
end
|
109
112
|
end
|
data/test/test_type_contract.rb
CHANGED
@@ -152,6 +152,10 @@ class TestTypeContract < Minitest::Test
|
|
152
152
|
assert_raises(TypeError) { block_contract_test2(42) {|z| z} }
|
153
153
|
assert_raises(TypeError) { block_contract_test1(42) }
|
154
154
|
assert_raises(TypeError) { block_contract_test3(42) { |x| x } }
|
155
|
+
assert_equal 42, block_contract_test4(42)
|
156
|
+
assert_equal 42, block_contract_test4(41) {|x| x+1}
|
157
|
+
assert_raises(TypeError) { block_contract_test4(40.5) }
|
158
|
+
assert_raises(TypeError) { block_contract_test4(42) {|x| x+1.5} }
|
155
159
|
|
156
160
|
t15 = @p.scan_str "(Fixnum x {{x>y}}, Fixnum y) -> Fixnum"
|
157
161
|
p15 = t15.to_contract.wrap(self) { |x, y| x+y }
|
@@ -172,6 +176,18 @@ class TestTypeContract < Minitest::Test
|
|
172
176
|
assert_raises(TypeError) { p17.call(42) }
|
173
177
|
assert_raises(TypeError) { p17.call(42, '43') }
|
174
178
|
assert_raises(TypeError) { p17.call(42, 43, '44') }
|
179
|
+
|
180
|
+
t18 = @p.scan_str "(Fixnum, ?{(Fixnum) -> Fixnum}) -> Fixnum"
|
181
|
+
p18 = t18.to_higher_contract(self) { |x,p=nil| if p then p.call(x) else x end }
|
182
|
+
assert_equal 42, p18.call(41, Proc.new {|x| x+1})
|
183
|
+
assert_equal 42, p18.call(42)
|
184
|
+
assert_raises(TypeError) { p18.call(41.5, Proc.new {|x| x+1}) }
|
185
|
+
assert_raises(TypeError) { p18.call(41, 1) }
|
186
|
+
assert_raises(TypeError) { p18.call(41, Proc.new {|x| x+1.5}) }
|
187
|
+
p18b = t18.to_higher_contract(self) { |x,p=nil| if p then p.call(x+0.5) else x end }
|
188
|
+
assert_raises(TypeError) { p18b.call(41, Proc.new {|x| x+1}) }
|
189
|
+
|
190
|
+
|
175
191
|
end
|
176
192
|
|
177
193
|
type '(Fixnum) { (Fixnum) -> Fixnum } -> Fixnum'
|
@@ -189,6 +205,12 @@ class TestTypeContract < Minitest::Test
|
|
189
205
|
42
|
190
206
|
end
|
191
207
|
|
208
|
+
type '(Fixnum) ?{(Fixnum) -> Fixnum} -> Fixnum'
|
209
|
+
def block_contract_test4(x,&blk)
|
210
|
+
return yield(x) if blk
|
211
|
+
return x
|
212
|
+
end
|
213
|
+
|
192
214
|
def test_proc_names
|
193
215
|
t1 = @p.scan_str "(x: Fixnum) -> Fixnum"
|
194
216
|
p1 = t1.to_contract.wrap(self) { |x:| x }
|
@@ -243,7 +265,7 @@ class TestTypeContract < Minitest::Test
|
|
243
265
|
assert_raises(TypeError) { p6.call(x: 43, y: "44", z: 45) }
|
244
266
|
t7 = @p.scan_str "(x: ?Fixnum, y: ?String) -> Fixnum"
|
245
267
|
p7 = t7.to_contract.wrap(self) { |**args| 42 }
|
246
|
-
assert_equal 42, p7.call
|
268
|
+
assert_equal 42, p7.call
|
247
269
|
assert_equal 42, p7.call(x: 43)
|
248
270
|
assert_equal 42, p7.call(y: "44")
|
249
271
|
assert_equal 42, p7.call(x: 43, y: "44")
|
@@ -252,7 +274,7 @@ class TestTypeContract < Minitest::Test
|
|
252
274
|
assert_raises(TypeError) { p7.call(x: 43, y: "44", z: 45) }
|
253
275
|
t8 = @p.scan_str "(?Fixnum, x: ?Symbol, y: ?String) -> Fixnum"
|
254
276
|
p8 = t8.to_contract.wrap(self) { |*args| 42 }
|
255
|
-
assert_equal 42, p8.call
|
277
|
+
assert_equal 42, p8.call
|
256
278
|
assert_equal 42, p8.call(43)
|
257
279
|
assert_equal 42, p8.call(x: :foo)
|
258
280
|
assert_equal 42, p8.call(43, x: :foo)
|
@@ -263,6 +285,16 @@ class TestTypeContract < Minitest::Test
|
|
263
285
|
assert_raises(TypeError) { p8.call(43, 44, x: :foo, y: "foo") }
|
264
286
|
assert_raises(TypeError) { p8.call(43, x: "foo", y: "foo") }
|
265
287
|
assert_raises(TypeError) { p8.call(43, x: :foo, y: "foo", z: 44) }
|
288
|
+
t9 = @p.scan_str "(Fixnum, x: String, y: Fixnum, **Float) -> Fixnum"
|
289
|
+
p9 = t9.to_contract.wrap(self) { |*args| 42 }
|
290
|
+
assert_raises(TypeError) { p9.call }
|
291
|
+
assert_raises(TypeError) { p9.call(43) }
|
292
|
+
assert_raises(TypeError) { p9.call(43, x: "foo") }
|
293
|
+
assert_equal 42, p9.call(43, x: "foo", y: 44)
|
294
|
+
assert_equal 42, p9.call(43, x: "foo", y: 44, pi: 3.14)
|
295
|
+
assert_equal 42, p9.call(43, x: "foo", y: 44, pi: 3.14, e: 2.72)
|
296
|
+
assert_raises(TypeError) { p9.call(43, x: "foo", y: 44, pi: 3) }
|
297
|
+
assert_raises(TypeError) { p9.call(43, x: "foo", y: 44, pi: 3.14, e: 3) }
|
266
298
|
end
|
267
299
|
|
268
300
|
type '() { () -> nil } -> nil'
|
data/test/test_typecheck.rb
CHANGED
@@ -412,52 +412,53 @@ class TestTypecheck < Minitest::Test
|
|
412
412
|
type :_send_named_args6, "(x: ?Fixnum, y: String) -> Fixnum"
|
413
413
|
type :_send_named_args7, "(x: ?Fixnum, y: ?String) -> Fixnum"
|
414
414
|
type :_send_named_args8, "(?Fixnum, x: ?Symbol, y: ?String) -> Fixnum"
|
415
|
+
type :_send_named_args9, "(Fixnum, x: String, y: Fixnum, **Float) -> Fixnum"
|
415
416
|
}
|
416
417
|
assert_equal $__rdl_fixnum_type, do_tc("_send_named_args1(x: 42)", env: @env)
|
417
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
418
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
419
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
420
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
421
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
422
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
418
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args1(x: '42')", env: @env) }
|
419
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args1()", env: @env) }
|
420
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args1(x: 42, y: 42)", env: @env) }
|
421
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args1(y: 42)", env: @env) }
|
422
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args1(42)", env: @env) }
|
423
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args1(42, x: '42')", env: @env) }
|
423
424
|
assert_equal $__rdl_fixnum_type, do_tc("_send_named_args2(x: 42, y: '43')", env: @env)
|
424
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
425
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
426
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
427
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
428
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
429
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
425
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args2()", env: @env) }
|
426
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args2(x: 42)", env: @env) }
|
427
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args2(x: '42', y: '43')", env: @env) }
|
428
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args2(42, '43')", env: @env) }
|
429
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args2(42, x: 42, y: '43')", env: @env) }
|
430
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args2(x: 42, y: '43', z: 44)", env: @env) }
|
430
431
|
assert_equal $__rdl_fixnum_type, do_tc("_send_named_args3(42, y: '43')", env: @env)
|
431
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
432
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
433
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
434
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
432
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args3(42, y: 43)", env: @env) }
|
433
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args3()", env: @env) }
|
434
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args3(42, 43, y: 44)", env: @env) }
|
435
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args3(42, y: 43, z: 44)", env: @env) }
|
435
436
|
assert_equal $__rdl_fixnum_type, do_tc("_send_named_args4(42, x: 43, y: '44')", env: @env)
|
436
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
437
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
438
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
439
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
440
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
437
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args4(42, x: 43)", env: @env) }
|
438
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args4(42, y: '43')", env: @env) }
|
439
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args4()", env: @env) }
|
440
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args4(42, 43, x: 44, y: '45')", env: @env) }
|
441
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args4(42, x: 43, y: '44', z: 45)", env: @env) }
|
441
442
|
assert_equal $__rdl_fixnum_type, do_tc("_send_named_args5(x: 42, y: '43')", env: @env)
|
442
443
|
assert_equal $__rdl_fixnum_type, do_tc("_send_named_args5(x: 42)", env: @env)
|
443
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
444
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
445
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
446
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
447
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
444
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args5()", env: @env) }
|
445
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args5(x: 42, y: 43)", env: @env) }
|
446
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args5(x: 42, y: 43, z: 44)", env: @env) }
|
447
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args5(3, x: 42, y: 43)", env: @env) }
|
448
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args5(3, x: 42)", env: @env) }
|
448
449
|
assert_equal $__rdl_fixnum_type, do_tc("_send_named_args6(x: 43, y: '44')", env: @env)
|
449
450
|
assert_equal $__rdl_fixnum_type, do_tc("_send_named_args6(y: '44')", env: @env)
|
450
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
451
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
452
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
453
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
451
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args6()", env: @env) }
|
452
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args6(x: '43', y: '44')", env: @env) }
|
453
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args6(42, x: 43, y: '44')", env: @env) }
|
454
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args6(x: 43, y: '44', z: 45)", env: @env) }
|
454
455
|
assert_equal $__rdl_fixnum_type, do_tc("_send_named_args7()", env: @env)
|
455
456
|
assert_equal $__rdl_fixnum_type, do_tc("_send_named_args7(x: 43)", env: @env)
|
456
457
|
assert_equal $__rdl_fixnum_type, do_tc("_send_named_args7(y: '44')", env: @env)
|
457
458
|
assert_equal $__rdl_fixnum_type, do_tc("_send_named_args7(x: 43, y: '44')", env: @env)
|
458
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
459
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
460
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
459
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args7(x: '43', y: '44')", env: @env) }
|
460
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args7(41, x: 43, y: '44')", env: @env) }
|
461
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args7(x: 43, y: '44', z: 45)", env: @env) }
|
461
462
|
assert_equal $__rdl_fixnum_type, do_tc("_send_named_args8()", env: @env)
|
462
463
|
assert_equal $__rdl_fixnum_type, do_tc("_send_named_args8(43)", env: @env)
|
463
464
|
assert_equal $__rdl_fixnum_type, do_tc("_send_named_args8(x: :foo)", env: @env)
|
@@ -466,9 +467,17 @@ class TestTypecheck < Minitest::Test
|
|
466
467
|
assert_equal $__rdl_fixnum_type, do_tc("_send_named_args8(43, y: 'foo')", env: @env)
|
467
468
|
assert_equal $__rdl_fixnum_type, do_tc("_send_named_args8(x: :foo, y: 'foo')", env: @env)
|
468
469
|
assert_equal $__rdl_fixnum_type, do_tc("_send_named_args8(43, x: :foo, y: 'foo')", env: @env)
|
469
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
470
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
471
|
-
assert_raises(RDL::Typecheck::StaticTypeError) {
|
470
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args8(43, 44, x: :foo, y: 'foo')", env: @env) }
|
471
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args8(43, x: 'foo', y: 'foo')", env: @env) }
|
472
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args8(43, x: :foo, y: 'foo', z: 44)", env: @env) }
|
473
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args9", env: @env) }
|
474
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args9(43)", env: @env) }
|
475
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args9(43, x: 'foo')", env: @env) }
|
476
|
+
assert_equal $__rdl_fixnum_type, do_tc("_send_named_args9(43, x:'foo', y: 44)", env: @env)
|
477
|
+
assert_equal $__rdl_fixnum_type, do_tc("_send_named_args9(43, x:'foo', y: 44, pi: 3.14)", env: @env)
|
478
|
+
assert_equal $__rdl_fixnum_type, do_tc("_send_named_args9(43, x:'foo', y: 44, pi: 3.14, e: 2.72)", env: @env)
|
479
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args9(43, x: 'foo', y: 44, pi: 3)", env: @env) }
|
480
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_send_named_args9(43, x: 'foo', y: 44, pi: 3.14, e: 3)", env: @env) }
|
472
481
|
end
|
473
482
|
|
474
483
|
def test_send_singleton
|
@@ -608,6 +617,85 @@ class TestTypecheck < Minitest::Test
|
|
608
617
|
}
|
609
618
|
end
|
610
619
|
|
620
|
+
def test_block_arg
|
621
|
+
self.class.class_eval {
|
622
|
+
type "(Fixnum) { (Fixnum) -> Fixnum } -> Fixnum", typecheck: :now
|
623
|
+
def _block_arg1(x, &blk)
|
624
|
+
blk.call x
|
625
|
+
end
|
626
|
+
}
|
627
|
+
|
628
|
+
assert_raises(RDL::Typecheck::StaticTypeError) {
|
629
|
+
self.class.class_eval {
|
630
|
+
type "(Fixnum) { (Fixnum) -> Fixnum } -> Fixnum", typecheck: :now
|
631
|
+
def _block_arg2(x, &blk)
|
632
|
+
blk.call 'forty-two'
|
633
|
+
end
|
634
|
+
}
|
635
|
+
}
|
636
|
+
|
637
|
+
assert_raises(RDL::Typecheck::StaticTypeError) {
|
638
|
+
self.class.class_eval {
|
639
|
+
type "(Fixnum) { (Fixnum) -> String } -> Fixnum", typecheck: :now
|
640
|
+
def _block_arg3(x, &foo)
|
641
|
+
foo.call 42
|
642
|
+
end
|
643
|
+
}
|
644
|
+
}
|
645
|
+
|
646
|
+
assert_raises(RDL::Typecheck::StaticTypeError) {
|
647
|
+
self.class.class_eval {
|
648
|
+
type "(Fixnum) -> Fixnum", typecheck: :now
|
649
|
+
def _block_arg4(x, &blk)
|
650
|
+
blk.call 42
|
651
|
+
end
|
652
|
+
}
|
653
|
+
}
|
654
|
+
|
655
|
+
assert_raises(RDL::Typecheck::StaticTypeError) {
|
656
|
+
self.class.class_eval {
|
657
|
+
type "(Fixnum) { (Fixnum) { (Fixnum) -> Fixnum } -> Fixnum } -> Fixnum", typecheck: :now
|
658
|
+
def _block_arg5(x, &blk)
|
659
|
+
blk.call 42
|
660
|
+
end
|
661
|
+
}
|
662
|
+
}
|
663
|
+
|
664
|
+
self.class.class_eval {
|
665
|
+
type :_block_arg6, "(Fixnum) { (Fixnum) -> Fixnum } -> Fixnum"
|
666
|
+
type "() { (Fixnum) -> Fixnum } -> Fixnum", typecheck: :now
|
667
|
+
def _block_arg7(&blk)
|
668
|
+
_block_arg6(42, &blk)
|
669
|
+
end
|
670
|
+
}
|
671
|
+
|
672
|
+
assert_raises(RDL::Typecheck::StaticTypeError) {
|
673
|
+
self.class.class_eval {
|
674
|
+
type "() { (Fixnum) -> String } -> Fixnum", typecheck: :now
|
675
|
+
def _block_arg8(&blk)
|
676
|
+
_block_arg6(42, &blk)
|
677
|
+
end
|
678
|
+
}
|
679
|
+
}
|
680
|
+
|
681
|
+
assert_raises(RDL::Typecheck::StaticTypeError) {
|
682
|
+
self.class.class_eval {
|
683
|
+
type "() -> Fixnum", typecheck: :now
|
684
|
+
def _block_arg9()
|
685
|
+
_block_arg6(42, &(1+2))
|
686
|
+
end
|
687
|
+
}
|
688
|
+
}
|
689
|
+
|
690
|
+
self.class.class_eval {
|
691
|
+
type :_block_arg10, "(Fixnum) -> Fixnum"
|
692
|
+
type :_block_arg11, "(Fixnum) -> String"
|
693
|
+
}
|
694
|
+
assert_equal $__rdl_fixnum_type, do_tc("_block_arg6(42, &:_block_arg10)", env: @env)
|
695
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_block_arg6(42, &:_block_arg11)", env: @env) }
|
696
|
+
assert_raises(RDL::Typecheck::StaticTypeError) { do_tc("_block_arg6(42, &:_block_arg_does_not_exist)", env: @env) }
|
697
|
+
end
|
698
|
+
|
611
699
|
# class Sup1
|
612
700
|
# type '(Fixnum) -> Fixnum', typecheck: :call
|
613
701
|
# def foo(y)
|
@@ -999,4 +1087,176 @@ class TestTypecheck < Minitest::Test
|
|
999
1087
|
}
|
1000
1088
|
end
|
1001
1089
|
|
1090
|
+
def test_optional_varargs_mapping
|
1091
|
+
assert_raises(RDL::Typecheck::StaticTypeError) {
|
1092
|
+
self.class.class_eval {
|
1093
|
+
type '(?Fixnum) -> Fixnum', typecheck: :now
|
1094
|
+
def _optional_varargs_mapping1(x)
|
1095
|
+
42
|
1096
|
+
end
|
1097
|
+
}
|
1098
|
+
}
|
1099
|
+
|
1100
|
+
assert_raises(RDL::Typecheck::StaticTypeError) {
|
1101
|
+
self.class.class_eval {
|
1102
|
+
type '(Fixnum) -> Fixnum', typecheck: :now
|
1103
|
+
def _optional_varargs_mapping2(x=42)
|
1104
|
+
x
|
1105
|
+
end
|
1106
|
+
}
|
1107
|
+
}
|
1108
|
+
|
1109
|
+
assert_raises(RDL::Typecheck::StaticTypeError) {
|
1110
|
+
self.class.class_eval {
|
1111
|
+
type '(*Fixnum) -> Fixnum', typecheck: :now
|
1112
|
+
def _optional_varargs_mapping3(x=42)
|
1113
|
+
x
|
1114
|
+
end
|
1115
|
+
}
|
1116
|
+
}
|
1117
|
+
|
1118
|
+
self.class.class_eval {
|
1119
|
+
type '(?Fixnum) -> Fixnum', typecheck: :now
|
1120
|
+
def _optional_varargs_mapping4(x=42)
|
1121
|
+
x
|
1122
|
+
end
|
1123
|
+
}
|
1124
|
+
|
1125
|
+
assert_raises(RDL::Typecheck::StaticTypeError) {
|
1126
|
+
self.class.class_eval {
|
1127
|
+
type '(?Fixnum) -> Fixnum', typecheck: :now
|
1128
|
+
def _optional_varargs_mapping5(x='forty-two')
|
1129
|
+
42
|
1130
|
+
end
|
1131
|
+
}
|
1132
|
+
}
|
1133
|
+
|
1134
|
+
assert_raises(RDL::Typecheck::StaticTypeError) {
|
1135
|
+
self.class.class_eval {
|
1136
|
+
type '(Fixnum) -> Fixnum', typecheck: :now
|
1137
|
+
def _optional_varargs_mapping6(*x)
|
1138
|
+
42
|
1139
|
+
end
|
1140
|
+
}
|
1141
|
+
}
|
1142
|
+
|
1143
|
+
assert_raises(RDL::Typecheck::StaticTypeError) {
|
1144
|
+
self.class.class_eval {
|
1145
|
+
type '(?Fixnum) -> Fixnum', typecheck: :now
|
1146
|
+
def _optional_varargs_mapping7(*x)
|
1147
|
+
42
|
1148
|
+
end
|
1149
|
+
}
|
1150
|
+
}
|
1151
|
+
|
1152
|
+
self.class.class_eval {
|
1153
|
+
type '(*Fixnum) -> Array<Fixnum>', typecheck: :now
|
1154
|
+
def _optional_varargs_mapping8(*x)
|
1155
|
+
x
|
1156
|
+
end
|
1157
|
+
}
|
1158
|
+
|
1159
|
+
end
|
1160
|
+
|
1161
|
+
def test_kw_mapping
|
1162
|
+
self.class.class_eval {
|
1163
|
+
type '(kw: Fixnum) -> Fixnum', typecheck: :now
|
1164
|
+
def _kw_mapping1(kw:)
|
1165
|
+
kw
|
1166
|
+
end
|
1167
|
+
}
|
1168
|
+
|
1169
|
+
assert_raises(RDL::Typecheck::StaticTypeError) {
|
1170
|
+
self.class.class_eval {
|
1171
|
+
type '(Fixnum) -> Fixnum', typecheck: :now
|
1172
|
+
def _kw_mapping2(kw:)
|
1173
|
+
kw
|
1174
|
+
end
|
1175
|
+
}
|
1176
|
+
}
|
1177
|
+
|
1178
|
+
self.class.class_eval {
|
1179
|
+
type '(kw: Fixnum) -> Fixnum', typecheck: :now
|
1180
|
+
def _kw_mapping3(kw_args) # slightly awkward example
|
1181
|
+
kw_args[:kw]
|
1182
|
+
end
|
1183
|
+
}
|
1184
|
+
|
1185
|
+
assert_raises(RDL::Typecheck::StaticTypeError) {
|
1186
|
+
self.class.class_eval {
|
1187
|
+
type '(kw: Fixnum) -> Fixnum', typecheck: :now
|
1188
|
+
def _kw_mapping4(kw: 42)
|
1189
|
+
kw
|
1190
|
+
end
|
1191
|
+
}
|
1192
|
+
}
|
1193
|
+
|
1194
|
+
assert_raises(RDL::Typecheck::StaticTypeError) {
|
1195
|
+
self.class.class_eval {
|
1196
|
+
type '(kw: ?Fixnum) -> Fixnum', typecheck: :now
|
1197
|
+
def _kw_mapping5(kw:)
|
1198
|
+
kw
|
1199
|
+
end
|
1200
|
+
}
|
1201
|
+
}
|
1202
|
+
|
1203
|
+
self.class.class_eval {
|
1204
|
+
type '(kw: ?Fixnum) -> Fixnum', typecheck: :now
|
1205
|
+
def _kw_mapping6(kw: 42)
|
1206
|
+
kw
|
1207
|
+
end
|
1208
|
+
}
|
1209
|
+
|
1210
|
+
assert_raises(RDL::Typecheck::StaticTypeError) {
|
1211
|
+
self.class.class_eval {
|
1212
|
+
type '(kw: ?Fixnum) -> Fixnum', typecheck: :now
|
1213
|
+
def _kw_mapping7(kw: 'forty-two')
|
1214
|
+
kw
|
1215
|
+
end
|
1216
|
+
}
|
1217
|
+
}
|
1218
|
+
|
1219
|
+
self.class.class_eval {
|
1220
|
+
type '(kw1: Fixnum, kw2: Fixnum) -> Fixnum', typecheck: :now
|
1221
|
+
def _kw_mapping8(kw1:, kw2:)
|
1222
|
+
kw1
|
1223
|
+
end
|
1224
|
+
}
|
1225
|
+
|
1226
|
+
assert_raises(RDL::Typecheck::StaticTypeError) {
|
1227
|
+
self.class.class_eval {
|
1228
|
+
type '(kw1: Fixnum, kw2: Fixnum, kw3: Fixnum) -> Fixnum', typecheck: :now
|
1229
|
+
def _kw_mapping9(kw2:)
|
1230
|
+
kw1
|
1231
|
+
end
|
1232
|
+
}
|
1233
|
+
}
|
1234
|
+
|
1235
|
+
self.class.class_eval {
|
1236
|
+
type '(kw1: Fixnum, kw2: Fixnum, **String) -> String', typecheck: :now
|
1237
|
+
def _kw_mapping10(kw1:, kw2:, **kws)
|
1238
|
+
kws[:foo]
|
1239
|
+
end
|
1240
|
+
}
|
1241
|
+
|
1242
|
+
assert_raises(RDL::Typecheck::StaticTypeError) {
|
1243
|
+
self.class.class_eval {
|
1244
|
+
type '(kw1: Fixnum, kw2: Fixnum) -> String', typecheck: :now
|
1245
|
+
def _kw_mapping11(kw1:, kw2:, **kws)
|
1246
|
+
kws[:foo]
|
1247
|
+
end
|
1248
|
+
}
|
1249
|
+
}
|
1250
|
+
|
1251
|
+
assert_raises(RDL::Typecheck::StaticTypeError) {
|
1252
|
+
self.class.class_eval {
|
1253
|
+
type '(kw1: Fixnum, kw2: Fixnum, **String) -> Fixnum', typecheck: :now
|
1254
|
+
def _kw_mapping12(kw1:, kw2:)
|
1255
|
+
kw1
|
1256
|
+
end
|
1257
|
+
}
|
1258
|
+
}
|
1259
|
+
|
1260
|
+
end
|
1261
|
+
|
1002
1262
|
end
|