rdl 1.1.1 → 2.0.0.rc1

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.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +6 -0
  3. data/README.md +211 -32
  4. data/gemfiles/Gemfile.travis +1 -1
  5. data/lib/rdl.rb +85 -18
  6. data/lib/rdl/info.rb +74 -0
  7. data/lib/rdl/query.rb +8 -9
  8. data/lib/rdl/typecheck.rb +1057 -0
  9. data/lib/rdl/types/annotated_arg.rb +5 -5
  10. data/lib/rdl/types/{nil.rb → bot.rb} +9 -13
  11. data/lib/rdl/types/dependent_arg.rb +5 -5
  12. data/lib/rdl/types/dots_query.rb +2 -0
  13. data/lib/rdl/types/finitehash.rb +67 -24
  14. data/lib/rdl/types/generic.rb +13 -21
  15. data/lib/rdl/types/intersection.rb +9 -8
  16. data/lib/rdl/types/method.rb +30 -32
  17. data/lib/rdl/types/nominal.rb +22 -16
  18. data/lib/rdl/types/optional.rb +8 -22
  19. data/lib/rdl/types/parser.racc +8 -3
  20. data/lib/rdl/types/parser.tab.rb +131 -118
  21. data/lib/rdl/types/singleton.rb +15 -10
  22. data/lib/rdl/types/structural.rb +6 -6
  23. data/lib/rdl/types/top.rb +6 -6
  24. data/lib/rdl/types/tuple.rb +56 -24
  25. data/lib/rdl/types/type.rb +9 -0
  26. data/lib/rdl/types/type_inferencer.rb +1 -1
  27. data/lib/rdl/types/union.rb +52 -26
  28. data/lib/rdl/types/var.rb +7 -6
  29. data/lib/rdl/types/vararg.rb +5 -6
  30. data/lib/rdl/types/wild_query.rb +9 -2
  31. data/lib/rdl/util.rb +9 -7
  32. data/lib/rdl/wrap.rb +90 -72
  33. data/lib/rdl_types.rb +2 -2
  34. data/rdl.gemspec +6 -8
  35. data/test/test_alias.rb +4 -3
  36. data/test/test_contract.rb +5 -4
  37. data/test/test_dsl.rb +2 -1
  38. data/test/test_generic.rb +30 -26
  39. data/test/test_intersection.rb +3 -3
  40. data/test/test_le.rb +129 -61
  41. data/test/test_lib_types.rb +3 -2
  42. data/test/test_member.rb +33 -46
  43. data/test/test_parser.rb +113 -116
  44. data/test/test_query.rb +2 -1
  45. data/test/test_rdl.rb +64 -6
  46. data/test/test_rdl_type.rb +3 -2
  47. data/test/test_type_contract.rb +30 -12
  48. data/test/test_typecheck.rb +893 -0
  49. data/test/test_types.rb +50 -54
  50. data/test/test_wrap.rb +2 -1
  51. data/types/ruby-2.x/_aliases.rb +13 -2
  52. data/types/ruby-2.x/bigdecimal.rb +60 -85
  53. data/types/ruby-2.x/bignum.rb +80 -119
  54. data/types/ruby-2.x/complex.rb +33 -40
  55. data/types/ruby-2.x/fixnum.rb +81 -120
  56. data/types/ruby-2.x/float.rb +79 -116
  57. data/types/ruby-2.x/integer.rb +187 -22
  58. data/types/ruby-2.x/nil.rb +12 -0
  59. data/types/ruby-2.x/numeric.rb +38 -38
  60. data/types/ruby-2.x/object.rb +3 -3
  61. data/types/ruby-2.x/random.rb +2 -0
  62. data/types/ruby-2.x/range.rb +20 -19
  63. data/types/ruby-2.x/rational.rb +40 -40
  64. data/types/ruby-2.x/regexp.rb +4 -4
  65. data/types/ruby-2.x/string.rb +15 -17
  66. metadata +17 -16
  67. data/lib/rdl/types/.#lexer.rex +0 -1
@@ -1,5 +1,6 @@
1
1
  require 'minitest/autorun'
2
- require_relative '../lib/rdl.rb'
2
+ $LOAD_PATH << File.dirname(__FILE__) + "/../lib"
3
+ require 'rdl'
3
4
 
4
5
  class TestIntersection < Minitest::Test
5
6
  include RDL::Type
@@ -14,7 +15,7 @@ class TestIntersection < Minitest::Test
14
15
  @true_n = NominalType.new(TrueClass)
15
16
 
16
17
  @tparam_t = VarType.new(:t)
17
-
18
+
18
19
  @f_or_s = UnionType.new(@fixnum, @string)
19
20
  @string_or_true = UnionType.new(@string, @true_n)
20
21
 
@@ -38,4 +39,3 @@ class TestIntersection < Minitest::Test
38
39
  assert_equal(t1, i)
39
40
  end
40
41
  end
41
-
@@ -1,5 +1,7 @@
1
1
  require 'minitest/autorun'
2
- require_relative '../lib/rdl.rb'
2
+ $LOAD_PATH << File.dirname(__FILE__) + "/../lib"
3
+ require 'rdl'
4
+ require 'rdl_types'
3
5
 
4
6
  class TestLe < Minitest::Test
5
7
  include RDL::Type
@@ -14,63 +16,57 @@ class TestLe < Minitest::Test
14
16
  end
15
17
 
16
18
  def setup
17
- @tnil = NilType.new
18
- @ttop = TopType.new
19
- @tstring = NominalType.new "String"
20
- @tobject = NominalType.new "Object"
21
19
  @tbasicobject = NominalType.new "BasicObject"
22
20
  @tsymfoo = SingletonType.new :foo
23
- @tsym = NominalType.new Symbol
24
21
  @ta = NominalType.new A
25
22
  @tb = NominalType.new B
26
23
  @tc = NominalType.new C
27
- @tfixnum = NominalType.new "Fixnum"
28
24
  end
29
25
 
30
26
  def test_nil
31
- assert (@tnil <= @ttop)
32
- assert (@tnil <= @tstring)
33
- assert (@tnil <= @tobject)
34
- assert (@tnil <= @tbasicobject)
35
- assert (@tnil <= @tsymfoo)
36
- assert (not (@ttop <= @tnil))
37
- assert (not (@tstring <= @tnil))
38
- assert (not (@tobject <= @tnil))
39
- assert (not (@tbasicobject <= @tnil))
40
- assert (not (@tsymfoo <= @tnil))
27
+ assert ($__rdl_nil_type <= $__rdl_top_type)
28
+ assert ($__rdl_nil_type <= $__rdl_string_type)
29
+ assert ($__rdl_nil_type <= $__rdl_object_type)
30
+ assert ($__rdl_nil_type <= @tbasicobject)
31
+ assert (not ($__rdl_nil_type <= @tsymfoo)) # nil no longer <= other singleton types
32
+ assert (not ($__rdl_top_type <= $__rdl_nil_type))
33
+ assert (not ($__rdl_string_type <= $__rdl_nil_type))
34
+ assert (not ($__rdl_object_type <= $__rdl_nil_type))
35
+ assert (not (@tbasicobject <= $__rdl_nil_type))
36
+ assert (not (@tsymfoo <= $__rdl_nil_type))
41
37
  end
42
38
 
43
39
  def test_top
44
- assert (not (@ttop <= @tnil))
45
- assert (not (@ttop <= @tstring))
46
- assert (not (@ttop <= @tobject))
47
- assert (not (@ttop <= @tbasicobject))
48
- assert (not (@ttop <= @tsymfoo))
49
- assert (@ttop <= @ttop)
50
- assert (@tstring <= @ttop)
51
- assert (@tobject <= @ttop)
52
- assert (@tbasicobject <= @ttop)
53
- assert (@tsymfoo <= @ttop)
40
+ assert (not ($__rdl_top_type <= $__rdl_nil_type))
41
+ assert (not ($__rdl_top_type <= $__rdl_string_type))
42
+ assert (not ($__rdl_top_type <= $__rdl_object_type))
43
+ assert (not ($__rdl_top_type <= @tbasicobject))
44
+ assert (not ($__rdl_top_type <= @tsymfoo))
45
+ assert ($__rdl_top_type <= $__rdl_top_type)
46
+ assert ($__rdl_string_type <= $__rdl_top_type)
47
+ assert ($__rdl_object_type <= $__rdl_top_type)
48
+ assert (@tbasicobject <= $__rdl_top_type)
49
+ assert (@tsymfoo <= $__rdl_top_type)
54
50
  end
55
51
 
56
52
  def test_sym
57
- assert (@tsym <= @tsym)
53
+ assert ($__rdl_symbol_type <= $__rdl_symbol_type)
58
54
  assert (@tsymfoo <= @tsymfoo)
59
- assert (@tsymfoo <= @tsym)
60
- assert (not (@tsym <= @tsymfoo))
55
+ assert (@tsymfoo <= $__rdl_symbol_type)
56
+ assert (not ($__rdl_symbol_type <= @tsymfoo))
61
57
  end
62
58
 
63
59
  def test_nominal
64
- assert (@tstring <= @tstring)
65
- assert (@tsym <= @tsym)
66
- assert (not (@tstring <= @tsym))
67
- assert (not (@tsym <= @tstring))
68
- assert (@tstring <= @tobject)
69
- assert (@tstring <= @tbasicobject)
70
- assert (@tobject <= @tbasicobject)
71
- assert (not (@tobject <= @tstring))
72
- assert (not (@tbasicobject <= @tstring))
73
- assert (not (@tbasicobject <= @tobject))
60
+ assert ($__rdl_string_type <= $__rdl_string_type)
61
+ assert ($__rdl_symbol_type <= $__rdl_symbol_type)
62
+ assert (not ($__rdl_string_type <= $__rdl_symbol_type))
63
+ assert (not ($__rdl_symbol_type <= $__rdl_string_type))
64
+ assert ($__rdl_string_type <= $__rdl_object_type)
65
+ assert ($__rdl_string_type <= @tbasicobject)
66
+ assert ($__rdl_object_type <= @tbasicobject)
67
+ assert (not ($__rdl_object_type <= $__rdl_string_type))
68
+ assert (not (@tbasicobject <= $__rdl_string_type))
69
+ assert (not (@tbasicobject <= $__rdl_object_type))
74
70
  assert (@ta <= @ta)
75
71
  assert (@tb <= @ta)
76
72
  assert (@tc <= @ta)
@@ -83,28 +79,100 @@ class TestLe < Minitest::Test
83
79
  end
84
80
 
85
81
  def test_union
86
- tstring_or_sym = UnionType.new(@tstring, @tsym)
87
- assert (tstring_or_sym <= @tobject)
88
- assert (not (@tobject <= tstring_or_sym))
82
+ tstring_or_sym = UnionType.new($__rdl_string_type, $__rdl_symbol_type)
83
+ assert (tstring_or_sym <= $__rdl_object_type)
84
+ assert (not ($__rdl_object_type <= tstring_or_sym))
89
85
  end
90
86
 
91
87
  def test_tuple
92
- t1 = TupleType.new(@tsym, @tstring)
93
- t2 = TupleType.new(@tobject, @tobject)
88
+ t1 = TupleType.new($__rdl_symbol_type, $__rdl_string_type)
89
+ t2 = TupleType.new($__rdl_object_type, $__rdl_object_type)
94
90
  tarray = NominalType.new("Array")
95
91
  assert (t1 <= t1)
96
92
  assert (t2 <= t2)
97
- assert (not (t1 <= t2)) # invariant subtyping since tuples are mutable
98
93
  assert (not (t2 <= t1))
99
- assert (not (t1 <= tarray)) # no convertability to arrays due to mutability
100
94
  assert (not (tarray <= t1))
95
+ assert (t1 <= t2) # covariant subtyping since tuples are *immutable*
96
+ t123 = $__rdl_parser.scan_str "#T [1, 2, 3]"
97
+ tfff = $__rdl_parser.scan_str "#T [Fixnum, Fixnum, Fixnum]"
98
+ tooo = $__rdl_parser.scan_str "#T [Object, Object, Object]"
99
+ assert (t123 <= tfff) # covariant subtyping with singletons
100
+ assert (tfff <= tooo)
101
+ assert (t123 <= tooo)
102
+
103
+ # subtyping of tuples and arrays
104
+ tfs_1 = $__rdl_parser.scan_str "#T [Fixnum, String]"
105
+ tafs_1 = $__rdl_parser.scan_str "#T Array<Fixnum or String>"
106
+ assert (tfs_1 <= tafs_1) # subtyping allowed by tfs_1 promoted to array
107
+ tfs2_1 = $__rdl_parser.scan_str "#T [Fixnum, String]"
108
+ assert (not (tfs_1 <= tfs2_1)) # t12 has been promoted to array, no longer subtype
109
+
110
+ tfs_2 = $__rdl_parser.scan_str "#T [Fixnum, String]"
111
+ tfs2_2 = $__rdl_parser.scan_str "#T [Fixnum, String]"
112
+ assert (tfs_2 <= tfs2_2) # this is allowed here because tfs_2 is still a tuple
113
+ tafs_2 = $__rdl_parser.scan_str "#T Array<Fixnum or String>"
114
+ assert (not (tfs_2 <= tafs_2)) # subtyping not allowed because tfs_2 <= tfs2_2 unsatisfiable after tfs_2 promoted
115
+
116
+ tfs_3 = $__rdl_parser.scan_str "#T [Fixnum, String]"
117
+ tfs2_3 = $__rdl_parser.scan_str "#T [Object, Object]"
118
+ assert (tfs_3 <= tfs2_3) # this is allowed here because t12a is still a tuple
119
+ tafs_3 = $__rdl_parser.scan_str "#T Array<Object>"
120
+ assert (not (tfs2_3 <= tafs_3)) # subtyping not allowed because tfs_3 <= tfs2_3 unsatisfiable after tfs2_3 promoted
121
+
122
+ tfs_4 = $__rdl_parser.scan_str "#T [Fixnum, String]"
123
+ tfs2_4 = $__rdl_parser.scan_str "#T [Fixnum, String]"
124
+ assert (tfs_4 <= tfs2_4) # allowed, types are the same
125
+ tafs_4 = $__rdl_parser.scan_str "#T Array<Fixnum or String>"
126
+ assert (tfs2_4 <= tafs_4) # allowed, both tfs2_4 and tfs_4 promoted to array
127
+ tfs3_4 = $__rdl_parser.scan_str "#T [Fixnum, String]"
128
+ assert (not(tfs_4 <= tfs3_4)) # not allowed, tfs_4 has been promoted
129
+ end
130
+
131
+ def test_finite_hash
132
+ t12 = $__rdl_parser.scan_str "#T {a: 1, b: 2}"
133
+ tfs = $__rdl_parser.scan_str "#T {a: Fixnum, b: Fixnum}"
134
+ too = $__rdl_parser.scan_str "#T {a: Object, b: Object}"
135
+ assert (t12 <= tfs)
136
+ assert (t12 <= too)
137
+ assert (tfs <= too)
138
+ assert (not (tfs <= t12))
139
+ assert (not (too <= tfs))
140
+ assert (not (too <= t12))
141
+
142
+ # subtyping of finite hashes and hashes; same pattern as tuples
143
+ # subtyping of tuples and arrays
144
+ tfs_1 = $__rdl_parser.scan_str "#T {x: Fixnum, y: String}"
145
+ thfs_1 = $__rdl_parser.scan_str "#T Hash<Symbol, Fixnum or String>"
146
+ assert (tfs_1 <= thfs_1) # subtyping allowed because tfs_1 promoted to hash
147
+ tfs2_1 = $__rdl_parser.scan_str "#T {x: Fixnum, y: String}"
148
+ assert (not (tfs_1 <= tfs2_1)) # t12 has been promoted to hash, no longer subtype
149
+
150
+ tfs_2 = $__rdl_parser.scan_str "#T {x: Fixnum, y: String}"
151
+ tfs2_2 = $__rdl_parser.scan_str "#T {x: Fixnum, y: String}"
152
+ assert (tfs_2 <= tfs2_2) # this is allowed here because tfs_2 is still finite
153
+ thfs_2 = $__rdl_parser.scan_str "#T Hash<Symbol, Fixnum or String>"
154
+ assert (not (tfs_2 <= thfs_2)) # subtyping not allowed because tfs_2 <= tfs2_2 unsatisfiable after tfs_2 promoted
155
+
156
+ tfs_3 = $__rdl_parser.scan_str "#T {x: Fixnum, y: String}"
157
+ tfs2_3 = $__rdl_parser.scan_str "#T {x: Object, y: Object}"
158
+ assert (tfs_3 <= tfs2_3) # this is allowed here because t12a is still finite
159
+ thfs_3 = $__rdl_parser.scan_str "#T Hash<Symbol, Object>"
160
+ assert (not (tfs2_3 <= thfs_3)) # subtyping not allowed because tfs_3 <= tfs2_3 unsatisfiable after tfs2_3 promoted
161
+
162
+ tfs_4 = $__rdl_parser.scan_str "#T {x: Fixnum, y: String}"
163
+ tfs2_4 = $__rdl_parser.scan_str "#T {x: Fixnum, y: String}"
164
+ assert (tfs_4 <= tfs2_4) # allowed, types are the same
165
+ thfs_4 = $__rdl_parser.scan_str "#T Hash<Symbol, Fixnum or String>"
166
+ assert (tfs2_4 <= thfs_4) # allowed, both tfs2_4 and tfs_4 promoted to hash
167
+ tfs3_4 = $__rdl_parser.scan_str "#T {x: Fixnum, y: String}"
168
+ assert (not(tfs_4 <= tfs3_4)) # not allowed, tfs_4 has been promoted
101
169
  end
102
170
 
103
171
  def test_method
104
- tss = MethodType.new([@tstring], nil, @tstring)
105
- tso = MethodType.new([@tstring], nil, @tobject)
106
- tos = MethodType.new([@tobject], nil, @tstring)
107
- too = MethodType.new([@tobject], nil, @tobject)
172
+ tss = MethodType.new([$__rdl_string_type], nil, $__rdl_string_type)
173
+ tso = MethodType.new([$__rdl_string_type], nil, $__rdl_object_type)
174
+ tos = MethodType.new([$__rdl_object_type], nil, $__rdl_string_type)
175
+ too = MethodType.new([$__rdl_object_type], nil, $__rdl_object_type)
108
176
  assert (tss <= tss)
109
177
  assert (tss <= tso)
110
178
  assert (not (tss <= tos))
@@ -121,8 +189,8 @@ class TestLe < Minitest::Test
121
189
  assert (too <= tso)
122
190
  assert (not (too <= tos))
123
191
  assert (too <= too)
124
- tbos = MethodType.new([], tos, @tobject)
125
- tbso = MethodType.new([], tso, @tobject)
192
+ tbos = MethodType.new([], tos, $__rdl_object_type)
193
+ tbso = MethodType.new([], tso, $__rdl_object_type)
126
194
  assert (tbos <= tbos)
127
195
  assert (not (tbos <= tbso))
128
196
  assert (tbso <= tbso)
@@ -130,11 +198,11 @@ class TestLe < Minitest::Test
130
198
  end
131
199
 
132
200
  def test_structural
133
- tso = MethodType.new([@tstring], nil, @tobject)
134
- tos = MethodType.new([@tobject], nil, @tstring)
201
+ tso = MethodType.new([$__rdl_string_type], nil, $__rdl_object_type)
202
+ tos = MethodType.new([$__rdl_object_type], nil, $__rdl_string_type)
135
203
  ts1 = StructuralType.new(m1: tso)
136
204
  ts2 = StructuralType.new(m1: tos)
137
- assert (ts1 <= @ttop)
205
+ assert (ts1 <= $__rdl_top_type)
138
206
  assert (ts1 <= ts1)
139
207
  assert (ts2 <= ts2)
140
208
  assert (ts2 <= ts1)
@@ -167,8 +235,8 @@ class TestLe < Minitest::Test
167
235
  def test_nominal_structural
168
236
  tnom = NominalType.new(Nom)
169
237
  tnomt = NominalType.new(NomT)
170
- tma = MethodType.new([], nil, @tnil)
171
- tmb = MethodType.new([@tfixnum], nil, @tnil)
238
+ tma = MethodType.new([], nil, $__rdl_nil_type)
239
+ tmb = MethodType.new([$__rdl_fixnum_type], nil, $__rdl_nil_type)
172
240
  ts1 = StructuralType.new(m1: tma)
173
241
  assert (tnom <= ts1)
174
242
  assert (tnomt <= ts1)
@@ -185,9 +253,9 @@ class TestLe < Minitest::Test
185
253
 
186
254
  # def test_intersection
187
255
  # skip "<= not defined on intersection"
188
- # tobject_and_basicobject = IntersectionType.new(@tobject, @tbasicobject)
189
- # assert (not (tobject_and_basicobject <= @tobject))
190
- # assert (@tobject <= tobject_and_basicobject)
256
+ # tobject_and_basicobject = IntersectionType.new($__rdl_object_type, @tbasicobject)
257
+ # assert (not (tobject_and_basicobject <= $__rdl_object_type))
258
+ # assert ($__rdl_object_type <= tobject_and_basicobject)
191
259
  # end
192
260
 
193
261
  end
@@ -8,8 +8,9 @@ require 'coverage.so'
8
8
  require 'uri'
9
9
 
10
10
  require 'minitest/autorun'
11
- require_relative '../lib/rdl.rb'
12
- require_relative '../lib/rdl_types.rb'
11
+ $LOAD_PATH << File.dirname(__FILE__) + "/../lib"
12
+ require 'rdl'
13
+ require 'rdl_types.rb'
13
14
 
14
15
  class Dummy
15
16
  def self.each
@@ -1,5 +1,6 @@
1
1
  require 'minitest/autorun'
2
- require_relative '../lib/rdl.rb'
2
+ $LOAD_PATH << File.dirname(__FILE__) + "/../lib"
3
+ require 'rdl'
3
4
 
4
5
  class TestMember < Minitest::Test
5
6
  include RDL::Type
@@ -14,60 +15,46 @@ class TestMember < Minitest::Test
14
15
  end
15
16
 
16
17
  def setup
17
- @tnil = NilType.new
18
- @ttop = TopType.new
19
- @tstring = NominalType.new "String"
20
- @tobject = NominalType.new "Object"
21
18
  @tbasicobject = NominalType.new "BasicObject"
22
19
  @tsymfoo = SingletonType.new :foo
23
- @tsym = NominalType.new Symbol
24
- @tarray = NominalType.new Array
25
- @tarraystring = GenericType.new(@tarray, @tstring)
26
- @tarrayobject = GenericType.new(@tarray, @tobject)
27
- @tarrayarraystring = GenericType.new(@tarray, @tarraystring)
28
- @tarrayarrayobject = GenericType.new(@tarray, @tarrayobject)
29
- @thash = NominalType.new Hash
30
- @thashstringstring = GenericType.new(@thash, @tstring, @tstring)
31
- @thashobjectobject = GenericType.new(@thash, @tobject, @tobject)
32
- @tstring_or_sym = UnionType.new(@tstring, @tsym)
33
- @tstring_and_sym = IntersectionType.new(@tstring, @tsym)
34
- @tobject_and_basicobject = IntersectionType.new(@tobject, @tbasicobject)
20
+ @tarraystring = GenericType.new($__rdl_array_type, $__rdl_string_type)
21
+ @tarrayobject = GenericType.new($__rdl_array_type, $__rdl_object_type)
22
+ @tarrayarraystring = GenericType.new($__rdl_array_type, @tarraystring)
23
+ @tarrayarrayobject = GenericType.new($__rdl_array_type, @tarrayobject)
24
+ $__rdl_hash_type = NominalType.new Hash
25
+ @thashstringstring = GenericType.new($__rdl_hash_type, $__rdl_string_type, $__rdl_string_type)
26
+ @thashobjectobject = GenericType.new($__rdl_hash_type, $__rdl_object_type, $__rdl_object_type)
27
+ @tstring_or_sym = UnionType.new($__rdl_string_type, $__rdl_symbol_type)
28
+ @tstring_and_sym = IntersectionType.new($__rdl_string_type, $__rdl_symbol_type)
29
+ @tobject_and_basicobject = IntersectionType.new($__rdl_object_type, @tbasicobject)
35
30
  @ta = NominalType.new A
36
31
  @tb = NominalType.new B
37
32
  @tc = NominalType.new C
38
33
  @tkernel = NominalType.new Kernel
39
- @tarray = NominalType.new Array
40
- @tarraystring = GenericType.new(@tarray, @tstring)
41
- @tarrayobject = GenericType.new(@tarray, @tobject)
42
- @tarrayarraystring = GenericType.new(@tarray, @tarraystring)
43
- @tarrayarrayobject = GenericType.new(@tarray, @tarrayobject)
44
- @thash = NominalType.new Hash
45
- @thashsymstring = GenericType.new(@thash, @tsym, @tstring)
46
- @thashobjectobject = GenericType.new(@thash, @tobject, @tobject)
47
34
  @tavar = VarType.new :a
48
35
  end
49
36
 
50
37
  def test_nil
51
- assert (@tnil.member? nil)
52
- assert (not (@tnil.member? "foo"))
53
- assert (not (@tnil.member? (Object.new)))
38
+ assert ($__rdl_nil_type.member? nil)
39
+ assert (not ($__rdl_nil_type.member? "foo"))
40
+ assert (not ($__rdl_nil_type.member? (Object.new)))
54
41
  end
55
42
 
56
43
  def test_top
57
- assert (@ttop.member? nil)
58
- assert (@ttop.member? "foo")
59
- assert (@ttop.member? (Object.new))
44
+ assert ($__rdl_top_type.member? nil)
45
+ assert ($__rdl_top_type.member? "foo")
46
+ assert ($__rdl_top_type.member? (Object.new))
60
47
  end
61
48
 
62
49
  def test_nominal
63
50
  o = Object.new
64
- assert (@tstring.member? "Foo")
65
- assert (not (@tstring.member? :Foo))
66
- assert (not (@tstring.member? o))
51
+ assert ($__rdl_string_type.member? "Foo")
52
+ assert (not ($__rdl_string_type.member? :Foo))
53
+ assert (not ($__rdl_string_type.member? o))
67
54
 
68
- assert (@tobject.member? "Foo")
69
- assert (@tobject.member? :Foo)
70
- assert (@tobject.member? o)
55
+ assert ($__rdl_object_type.member? "Foo")
56
+ assert ($__rdl_object_type.member? :Foo)
57
+ assert ($__rdl_object_type.member? o)
71
58
 
72
59
  assert (@tkernel.member? "Foo")
73
60
  assert (@tkernel.member? :Foo)
@@ -86,18 +73,18 @@ class TestMember < Minitest::Test
86
73
  assert (not (@tc.member? b))
87
74
  assert (@tc.member? c)
88
75
 
89
- assert (@tstring.member? nil)
90
- assert (@tobject.member? nil)
76
+ assert ($__rdl_string_type.member? nil)
77
+ assert ($__rdl_object_type.member? nil)
91
78
  end
92
79
 
93
80
  def test_symbol
94
- assert (@tsym.member? :foo)
95
- assert (@tsym.member? :bar)
96
- assert (not (@tsym.member? "foo"))
81
+ assert ($__rdl_symbol_type.member? :foo)
82
+ assert ($__rdl_symbol_type.member? :bar)
83
+ assert (not ($__rdl_symbol_type.member? "foo"))
97
84
  assert (@tsymfoo.member? :foo)
98
85
  assert (not (@tsymfoo.member? :bar))
99
86
  assert (not (@tsymfoo.member? "foo"))
100
- assert (@tsymfoo.member? nil)
87
+ assert (not(@tsymfoo.member? nil)) # nil no longer subtype of other singletons
101
88
  end
102
89
 
103
90
  def test_union_intersection
@@ -122,7 +109,7 @@ class TestMember < Minitest::Test
122
109
  end
123
110
 
124
111
  def test_tuple
125
- t1 = TupleType.new(@tsym, @tstring)
112
+ t1 = TupleType.new($__rdl_symbol_type, $__rdl_string_type)
126
113
  assert (t1.member? [:foo, "foo"])
127
114
  assert (not (t1.member? ["foo", :foo]))
128
115
  assert (not (t1.member? [:foo, "foo", "bar"]))
@@ -132,13 +119,13 @@ class TestMember < Minitest::Test
132
119
  end
133
120
 
134
121
  def test_finite_hash
135
- t1 = FiniteHashType.new(a: @tsym, b: @tstring)
122
+ t1 = FiniteHashType.new(a: $__rdl_symbol_type, b: $__rdl_string_type)
136
123
  assert (t1.member?(a: :foo, b: "foo"))
137
124
  assert (not (t1.member?(a: 1, b: "foo")))
138
125
  assert (not (t1.member?(a: :foo)))
139
126
  assert (not (t1.member?(b: "foo")))
140
127
  assert (not (t1.member?(a: :foo, b: "foo", c: :baz)))
141
- t2 = FiniteHashType.new({"a"=>@tsym, 2=>@tstring})
128
+ t2 = FiniteHashType.new({"a"=>$__rdl_symbol_type, 2=>$__rdl_string_type})
142
129
  assert (t2.member?({"a"=>:foo, 2=>"foo"}))
143
130
  assert (not (t2.member?({"a"=>2, 2=>"foo"})))
144
131
  assert (not (t2.member?({"a"=>:foo})))
@@ -1,28 +1,25 @@
1
1
  require 'minitest/autorun'
2
- require_relative '../lib/rdl.rb'
2
+ $LOAD_PATH << File.dirname(__FILE__) + "/../lib"
3
+ require 'rdl'
3
4
 
4
5
  class TestParser < Minitest::Test
5
6
  include RDL::Type
6
7
 
8
+ class A; end
9
+ class B; end
10
+ class C; end
11
+
7
12
  def setup
8
- @p = Parser.new
9
- @tnil = NilType.new
10
- @ttop = TopType.new
11
- @tfixnum = NominalType.new Fixnum
12
- @tfixnumopt = OptionalType.new @tfixnum
13
- @tfixnumvararg = VarargType.new @tfixnum
14
- @tstring = NominalType.new String
15
- @tstringopt = OptionalType.new @tstring
13
+ @tfixnumopt = OptionalType.new $__rdl_fixnum_type
14
+ @tfixnumvararg = VarargType.new $__rdl_fixnum_type
15
+ @tstringopt = OptionalType.new $__rdl_string_type
16
16
  @tenum = NominalType.new :Enumerator
17
- @ttrue = NominalType.new TrueClass
18
- @tfalse = NominalType.new FalseClass
19
- @tbool = UnionType.new @ttrue, @tfalse
20
17
  @ta = NominalType.new :A
21
18
  @tb = NominalType.new :B
22
19
  @tc = NominalType.new :C
23
- @tfixnumx = AnnotatedArgType.new("x", @tfixnum)
24
- @tfixnumy = AnnotatedArgType.new("y", @tfixnum)
25
- @tfixnumret = AnnotatedArgType.new("ret", @tfixnum)
20
+ @tfixnumx = AnnotatedArgType.new("x", $__rdl_fixnum_type)
21
+ @tfixnumy = AnnotatedArgType.new("y", $__rdl_fixnum_type)
22
+ @tfixnumret = AnnotatedArgType.new("ret", $__rdl_fixnum_type)
26
23
  @tfixnumoptx = AnnotatedArgType.new("x", @tfixnumopt)
27
24
  @tfixnumvarargx = AnnotatedArgType.new("x", @tfixnumvararg)
28
25
  @tsymbol = SingletonType.new(:symbol)
@@ -30,167 +27,167 @@ class TestParser < Minitest::Test
30
27
  end
31
28
 
32
29
  def test_basic
33
- t1 = @p.scan_str "(nil) -> nil"
34
- assert_equal (MethodType.new [@tnil], nil, @tnil), t1
35
- t2 = @p.scan_str "(Fixnum, Fixnum) -> Fixnum"
36
- assert_equal (MethodType.new [@tfixnum, @tfixnum], nil, @tfixnum), t2
37
- t3 = @p.scan_str "() -> Enumerator"
30
+ t1 = $__rdl_parser.scan_str "(nil) -> nil"
31
+ assert_equal (MethodType.new [$__rdl_nil_type], nil, $__rdl_nil_type), t1
32
+ t2 = $__rdl_parser.scan_str "(Fixnum, Fixnum) -> Fixnum"
33
+ assert_equal (MethodType.new [$__rdl_fixnum_type, $__rdl_fixnum_type], nil, $__rdl_fixnum_type), t2
34
+ t3 = $__rdl_parser.scan_str "() -> Enumerator"
38
35
  assert_equal (MethodType.new [], nil, @tenum), t3
39
- t4 = @p.scan_str "(%any) -> nil"
40
- assert_equal (MethodType.new [@ttop], nil, @tnil), t4
41
- t5 = @p.scan_str "(%bool) -> Fixnum"
42
- assert_equal (MethodType.new [@tbool], nil, @tfixnum), t5
43
- assert_raises(RuntimeError) { @p.scan_str "(%foo) -> nil" }
44
- t6 = @p.scan_str "(A) -> nil"
45
- assert_equal (MethodType.new [@ta], nil, @tnil), t6
46
- t7 = @p.scan_str "(TestParser::A) -> nil"
47
- assert_equal (MethodType.new [NominalType.new("TestParser::A")], nil, @tnil), t7
48
- t8 = @p.scan_str "(Fixnum) { (%any, String) -> nil } -> :symbol"
49
- assert_equal (MethodType.new [@tfixnum], MethodType.new([@ttop, @tstring], nil, @tnil), @tsymbol), t8
36
+ t4 = $__rdl_parser.scan_str "(%any) -> nil"
37
+ assert_equal (MethodType.new [$__rdl_top_type], nil, $__rdl_nil_type), t4
38
+ t5 = $__rdl_parser.scan_str "(%bool) -> Fixnum"
39
+ assert_equal (MethodType.new [$__rdl_bool_type], nil, $__rdl_fixnum_type), t5
40
+ assert_raises(RuntimeError) { $__rdl_parser.scan_str "(%foo) -> nil" }
41
+ t6 = $__rdl_parser.scan_str "(A) -> nil"
42
+ assert_equal (MethodType.new [@ta], nil, $__rdl_nil_type), t6
43
+ t7 = $__rdl_parser.scan_str "(TestParser::A) -> nil"
44
+ assert_equal (MethodType.new [NominalType.new("TestParser::A")], nil, $__rdl_nil_type), t7
45
+ t8 = $__rdl_parser.scan_str "(Fixnum) { (%any, String) -> nil } -> :symbol"
46
+ assert_equal (MethodType.new [$__rdl_fixnum_type], MethodType.new([$__rdl_top_type, $__rdl_string_type], nil, $__rdl_nil_type), @tsymbol), t8
47
+ t9 = $__rdl_parser.scan_str "(true) -> false"
48
+ assert_equal (MethodType.new [$__rdl_true_type], nil, $__rdl_false_type), t9
50
49
  end
51
50
 
52
51
  def test_opt_vararg
53
- t1 = @p.scan_str "(Fixnum, ?Fixnum) -> Fixnum"
54
- assert_equal (MethodType.new [@tfixnum, @tfixnumopt], nil, @tfixnum), t1
55
- t2 = @p.scan_str "(Fixnum, *Fixnum) -> Fixnum"
56
- assert_equal (MethodType.new [@tfixnum, @tfixnumvararg], nil, @tfixnum), t2
57
- t3 = @p.scan_str "(Fixnum, ?Fixnum, ?Fixnum, *Fixnum) -> Fixnum"
58
- assert_equal (MethodType.new [@tfixnum, @tfixnumopt, @tfixnumopt, @tfixnumvararg], nil, @tfixnum), t3
59
- t4 = @p.scan_str "(?Fixnum) -> nil"
60
- assert_equal (MethodType.new [@tfixnumopt], nil, @tnil), t4
61
- t5 = @p.scan_str "(*Fixnum) -> nil"
62
- assert_equal (MethodType.new [@tfixnumvararg], nil, @tnil), t5
52
+ t1 = $__rdl_parser.scan_str "(Fixnum, ?Fixnum) -> Fixnum"
53
+ assert_equal (MethodType.new [$__rdl_fixnum_type, @tfixnumopt], nil, $__rdl_fixnum_type), t1
54
+ t2 = $__rdl_parser.scan_str "(Fixnum, *Fixnum) -> Fixnum"
55
+ assert_equal (MethodType.new [$__rdl_fixnum_type, @tfixnumvararg], nil, $__rdl_fixnum_type), t2
56
+ t3 = $__rdl_parser.scan_str "(Fixnum, ?Fixnum, ?Fixnum, *Fixnum) -> Fixnum"
57
+ assert_equal (MethodType.new [$__rdl_fixnum_type, @tfixnumopt, @tfixnumopt, @tfixnumvararg], nil, $__rdl_fixnum_type), t3
58
+ t4 = $__rdl_parser.scan_str "(?Fixnum) -> nil"
59
+ assert_equal (MethodType.new [@tfixnumopt], nil, $__rdl_nil_type), t4
60
+ t5 = $__rdl_parser.scan_str "(*Fixnum) -> nil"
61
+ assert_equal (MethodType.new [@tfixnumvararg], nil, $__rdl_nil_type), t5
63
62
  end
64
63
 
65
64
  def test_union
66
- t1 = @p.scan_str "(A or B) -> nil"
67
- assert_equal (MethodType.new [UnionType.new(@ta, @tb)], nil, @tnil), t1
68
- t2 = @p.scan_str "(A or B or C) -> nil"
69
- assert_equal (MethodType.new [UnionType.new(@ta, @tb, @tc)], nil, @tnil), t2
70
- t3 = @p.scan_str "() -> A or B or C"
71
- assert_equal (MethodType.new [], nil, UnionType.new(@ta, @tb, @tc)), t3
65
+ t1 = $__rdl_parser.scan_str "(Fixnum or String) -> nil"
66
+ assert_equal (MethodType.new [UnionType.new($__rdl_fixnum_type, $__rdl_string_type)], nil, $__rdl_nil_type), t1
67
+ t2 = $__rdl_parser.scan_str "(Fixnum or String or Symbol) -> nil"
68
+ assert_equal (MethodType.new [UnionType.new($__rdl_fixnum_type, $__rdl_string_type, $__rdl_symbol_type)], nil, $__rdl_nil_type), t2
69
+ t3 = $__rdl_parser.scan_str "() -> Fixnum or String or Symbol"
70
+ assert_equal (MethodType.new [], nil, UnionType.new($__rdl_fixnum_type, $__rdl_string_type, $__rdl_symbol_type)), t3
72
71
  end
73
72
 
74
73
  def test_bare
75
- t1 = @p.scan_str "#T nil"
76
- assert_equal @tnil, t1
77
- t2 = @p.scan_str "#T %any"
78
- assert_equal @ttop, t2
79
- t3 = @p.scan_str "#T A"
74
+ t1 = $__rdl_parser.scan_str "#T nil"
75
+ assert_equal $__rdl_nil_type, t1
76
+ t2 = $__rdl_parser.scan_str "#T %any"
77
+ assert_equal $__rdl_top_type, t2
78
+ t3 = $__rdl_parser.scan_str "#T A"
80
79
  assert_equal NominalType.new("A"), t3
81
80
  end
82
81
 
83
82
  def test_symbol
84
- t1 = @p.scan_str "#T :symbol"
83
+ t1 = $__rdl_parser.scan_str "#T :symbol"
85
84
  assert_equal @tsymbol, t1
86
85
  end
87
86
 
88
87
  def test_annotated_params
89
- t1 = @p.scan_str "(Fixnum x, Fixnum) -> Fixnum"
90
- assert_equal (MethodType.new [@tfixnumx, @tfixnum], nil, @tfixnum), t1
91
- t2 = @p.scan_str "(Fixnum, ?Fixnum x) -> Fixnum"
92
- assert_equal (MethodType.new [@tfixnum, @tfixnumoptx], nil, @tfixnum), t2
93
- t3 = @p.scan_str "(Fixnum, *Fixnum x) -> Fixnum"
94
- assert_equal (MethodType.new [@tfixnum, @tfixnumvarargx], nil, @tfixnum), t3
95
- t4 = @p.scan_str "(Fixnum, Fixnum y) -> Fixnum"
96
- assert_equal (MethodType.new [@tfixnum, @tfixnumy], nil, @tfixnum), t4
97
- t5 = @p.scan_str "(Fixnum x, Fixnum y) -> Fixnum"
98
- assert_equal (MethodType.new [@tfixnumx, @tfixnumy], nil, @tfixnum), t5
99
- t6 = @p.scan_str "(Fixnum, Fixnum) -> Fixnum ret"
100
- assert_equal (MethodType.new [@tfixnum, @tfixnum], nil, @tfixnumret), t6
101
- t7 = @p.scan_str "(Fixnum x, Fixnum) -> Fixnum ret"
102
- assert_equal (MethodType.new [@tfixnumx, @tfixnum], nil, @tfixnumret), t7
103
- t8 = @p.scan_str "(Fixnum, Fixnum y) -> Fixnum ret"
104
- assert_equal (MethodType.new [@tfixnum, @tfixnumy], nil, @tfixnumret), t8
105
- t9 = @p.scan_str "(Fixnum x, Fixnum y) -> Fixnum ret"
88
+ t1 = $__rdl_parser.scan_str "(Fixnum x, Fixnum) -> Fixnum"
89
+ assert_equal (MethodType.new [@tfixnumx, $__rdl_fixnum_type], nil, $__rdl_fixnum_type), t1
90
+ t2 = $__rdl_parser.scan_str "(Fixnum, ?Fixnum x) -> Fixnum"
91
+ assert_equal (MethodType.new [$__rdl_fixnum_type, @tfixnumoptx], nil, $__rdl_fixnum_type), t2
92
+ t3 = $__rdl_parser.scan_str "(Fixnum, *Fixnum x) -> Fixnum"
93
+ assert_equal (MethodType.new [$__rdl_fixnum_type, @tfixnumvarargx], nil, $__rdl_fixnum_type), t3
94
+ t4 = $__rdl_parser.scan_str "(Fixnum, Fixnum y) -> Fixnum"
95
+ assert_equal (MethodType.new [$__rdl_fixnum_type, @tfixnumy], nil, $__rdl_fixnum_type), t4
96
+ t5 = $__rdl_parser.scan_str "(Fixnum x, Fixnum y) -> Fixnum"
97
+ assert_equal (MethodType.new [@tfixnumx, @tfixnumy], nil, $__rdl_fixnum_type), t5
98
+ t6 = $__rdl_parser.scan_str "(Fixnum, Fixnum) -> Fixnum ret"
99
+ assert_equal (MethodType.new [$__rdl_fixnum_type, $__rdl_fixnum_type], nil, @tfixnumret), t6
100
+ t7 = $__rdl_parser.scan_str "(Fixnum x, Fixnum) -> Fixnum ret"
101
+ assert_equal (MethodType.new [@tfixnumx, $__rdl_fixnum_type], nil, @tfixnumret), t7
102
+ t8 = $__rdl_parser.scan_str "(Fixnum, Fixnum y) -> Fixnum ret"
103
+ assert_equal (MethodType.new [$__rdl_fixnum_type, @tfixnumy], nil, @tfixnumret), t8
104
+ t9 = $__rdl_parser.scan_str "(Fixnum x, Fixnum y) -> Fixnum ret"
106
105
  assert_equal (MethodType.new [@tfixnumx, @tfixnumy], nil, @tfixnumret), t9
107
- t10 = @p.scan_str "(:symbol x) -> Fixnum"
108
- assert_equal (MethodType.new [@tsymbolx], nil, @tfixnum), t10
106
+ t10 = $__rdl_parser.scan_str "(:symbol x) -> Fixnum"
107
+ assert_equal (MethodType.new [@tsymbolx], nil, $__rdl_fixnum_type), t10
109
108
  end
110
109
 
111
110
  def test_generic
112
- t1 = @p.scan_str "#T t"
111
+ t1 = $__rdl_parser.scan_str "#T t"
113
112
  assert_equal (VarType.new "t"), t1
114
- t2 = @p.scan_str "#T Array"
113
+ t2 = $__rdl_parser.scan_str "#T Array"
115
114
  assert_equal (NominalType.new "Array"), t2
116
- t3 = @p.scan_str "#T Array<t>"
115
+ t3 = $__rdl_parser.scan_str "#T Array<t>"
117
116
  assert_equal (GenericType.new(t2, t1)), t3
118
- t4 = @p.scan_str "#T Array<Array<t>>"
117
+ t4 = $__rdl_parser.scan_str "#T Array<Array<t>>"
119
118
  assert_equal (GenericType.new(t2, t3)), t4
120
- t5 = @p.scan_str "#T Hash"
119
+ t5 = $__rdl_parser.scan_str "#T Hash"
121
120
  assert_equal (NominalType.new "Hash"), t5
122
- t6 = @p.scan_str "#T Hash<u, v>"
121
+ t6 = $__rdl_parser.scan_str "#T Hash<u, v>"
123
122
  assert_equal (GenericType.new(t5, VarType.new("u"), VarType.new("v"))), t6
124
- t7 = @p.scan_str "#T Foo<String, Array<t>, Array<Array<t>>>"
125
- assert_equal (GenericType.new(NominalType.new("Foo"), @tstring, t3, t4)), t7
123
+ t7 = $__rdl_parser.scan_str "#T Foo<String, Array<t>, Array<Array<t>>>"
124
+ assert_equal (GenericType.new(NominalType.new("Foo"), $__rdl_string_type, t3, t4)), t7
126
125
  end
127
126
 
128
127
  def test_tuple
129
- t1 = @p.scan_str "#T [Fixnum, String]"
130
- assert_equal (TupleType.new(@tfixnum, @tstring)), t1
131
- t2 = @p.scan_str "#T [String]"
132
- assert_equal (TupleType.new(@tstring)), t2
128
+ t1 = $__rdl_parser.scan_str "#T [Fixnum, String]"
129
+ assert_equal (TupleType.new($__rdl_fixnum_type, $__rdl_string_type)), t1
130
+ t2 = $__rdl_parser.scan_str "#T [String]"
131
+ assert_equal (TupleType.new($__rdl_string_type)), t2
133
132
  end
134
133
 
135
134
  def test_fixnum
136
- t1 = @p.scan_str "#T 42"
135
+ t1 = $__rdl_parser.scan_str "#T 42"
137
136
  assert_equal (SingletonType.new(42)), t1
138
- t2 = @p.scan_str "#T -42"
137
+ t2 = $__rdl_parser.scan_str "#T -42"
139
138
  assert_equal (SingletonType.new(-42)), t2
140
139
  end
141
140
 
142
141
  def test_float
143
- t1 = @p.scan_str "#T 3.14"
142
+ t1 = $__rdl_parser.scan_str "#T 3.14"
144
143
  assert_equal (SingletonType.new(3.14)), t1
145
144
  end
146
145
 
147
146
  def test_const
148
- t1 = @p.scan_str "#T ${Math::PI}"
147
+ t1 = $__rdl_parser.scan_str "#T ${Math::PI}"
149
148
  assert_equal (SingletonType.new(Math::PI)), t1
150
149
  end
151
150
 
152
151
  def test_type_alias
153
- type_alias '%foobarbaz', @tnil
154
- assert_equal @tnil, (@p.scan_str "#T %foobarbaz")
152
+ type_alias '%foobarbaz', $__rdl_nil_type
153
+ assert_equal $__rdl_nil_type, ($__rdl_parser.scan_str "#T %foobarbaz")
155
154
  type_alias '%quxquxqux', 'nil'
156
- assert_equal @tnil, (@p.scan_str "#T %quxquxqux")
155
+ assert_equal $__rdl_nil_type, ($__rdl_parser.scan_str "#T %quxquxqux")
157
156
  assert_raises(RuntimeError) { type_alias '%quxquxqux', 'nil' }
158
- assert_raises(RuntimeError) { @p.scan_str "#T %qux" }
157
+ assert_raises(RuntimeError) { $__rdl_parser.scan_str "#T %qux" }
159
158
  end
160
159
 
161
160
  def test_structural
162
- t1 = @p.scan_str "#T [to_str: () -> String]"
163
- tm1 = MethodType.new [], nil, @tstring
161
+ t1 = $__rdl_parser.scan_str "#T [to_str: () -> String]"
162
+ tm1 = MethodType.new [], nil, $__rdl_string_type
164
163
  ts1 = StructuralType.new(to_str: tm1)
165
164
  assert_equal ts1, t1
166
165
  end
167
166
 
168
167
  def test_finite_hash
169
- t1 = @p.scan_str "#T {a: Fixnum, b: String}"
170
- assert_equal (FiniteHashType.new({a: @tfixnum, b: @tstring})), t1
171
- t2 = @p.scan_str "#T {'a'=>Fixnum, 2=>String}"
172
- assert_equal (FiniteHashType.new({"a"=>@tfixnum, 2=>@tstring})), t2
168
+ t1 = $__rdl_parser.scan_str "#T {a: Fixnum, b: String}"
169
+ assert_equal (FiniteHashType.new({a: $__rdl_fixnum_type, b: $__rdl_string_type})), t1
170
+ t2 = $__rdl_parser.scan_str "#T {'a'=>Fixnum, 2=>String}"
171
+ assert_equal (FiniteHashType.new({"a"=>$__rdl_fixnum_type, 2=>$__rdl_string_type})), t2
173
172
  end
174
173
 
175
174
  def test_named_params
176
- t1 = @p.scan_str "(Fixnum, x: Fixnum) -> Fixnum"
177
- assert_equal (MethodType.new [@tfixnum, FiniteHashType.new(x: @tfixnum)], nil, @tfixnum), t1
178
- t2 = @p.scan_str "(Fixnum, x: Fixnum, y: String) -> Fixnum"
179
- assert_equal (MethodType.new [@tfixnum, FiniteHashType.new(x: @tfixnum, y: @tstring)], nil, @tfixnum), t2
180
- t3 = @p.scan_str "(Fixnum, y: String, x: Fixnum) -> Fixnum"
181
- assert_equal (MethodType.new [@tfixnum, FiniteHashType.new(x: @tfixnum, y: @tstring)], nil, @tfixnum), t3
182
- t4 = @p.scan_str "(Fixnum, y: String, x: ?Fixnum) -> Fixnum"
183
- assert_equal (MethodType.new [@tfixnum, FiniteHashType.new(x: @tfixnumopt, y: @tstring)], nil, @tfixnum), t4
184
- t4 = @p.scan_str "(Fixnum, y: ?String, x: Fixnum) -> Fixnum"
185
- assert_equal (MethodType.new [@tfixnum, FiniteHashType.new(x: @tfixnum, y: @tstringopt)], nil, @tfixnum), t4
186
- t5 = @p.scan_str "(Fixnum x, x: Fixnum) -> Fixnum"
187
- assert_equal (MethodType.new [@tfixnumx, FiniteHashType.new(x: @tfixnum)], nil, @tfixnum), t5
188
- t5 = @p.scan_str "(Fixnum x, x: Fixnum) -> Fixnum"
189
- assert_equal (MethodType.new [@tfixnumx, FiniteHashType.new(x: @tfixnum)], nil, @tfixnum), t5
190
- t6 = @p.scan_str "(x: Fixnum) -> Fixnum"
191
- assert_equal (MethodType.new [FiniteHashType.new(x: @tfixnum)], nil, @tfixnum), t6
192
- t7 = @p.scan_str "(x: Fixnum) { (%any, String) -> nil } -> :symbol"
193
- assert_equal (MethodType.new [FiniteHashType.new(x: @tfixnum)], MethodType.new([@ttop, @tstring], nil, @tnil), @tsymbol), t7
175
+ t1 = $__rdl_parser.scan_str "(Fixnum, x: Fixnum) -> Fixnum"
176
+ assert_equal (MethodType.new [$__rdl_fixnum_type, FiniteHashType.new(x: $__rdl_fixnum_type)], nil, $__rdl_fixnum_type), t1
177
+ t2 = $__rdl_parser.scan_str "(Fixnum, x: Fixnum, y: String) -> Fixnum"
178
+ assert_equal (MethodType.new [$__rdl_fixnum_type, FiniteHashType.new(x: $__rdl_fixnum_type, y: $__rdl_string_type)], nil, $__rdl_fixnum_type), t2
179
+ t3 = $__rdl_parser.scan_str "(Fixnum, y: String, x: Fixnum) -> Fixnum"
180
+ assert_equal (MethodType.new [$__rdl_fixnum_type, FiniteHashType.new(x: $__rdl_fixnum_type, y: $__rdl_string_type)], nil, $__rdl_fixnum_type), t3
181
+ t4 = $__rdl_parser.scan_str "(Fixnum, y: String, x: ?Fixnum) -> Fixnum"
182
+ assert_equal (MethodType.new [$__rdl_fixnum_type, FiniteHashType.new(x: @tfixnumopt, y: $__rdl_string_type)], nil, $__rdl_fixnum_type), t4
183
+ t4 = $__rdl_parser.scan_str "(Fixnum, y: ?String, x: Fixnum) -> Fixnum"
184
+ assert_equal (MethodType.new [$__rdl_fixnum_type, FiniteHashType.new(x: $__rdl_fixnum_type, y: @tstringopt)], nil, $__rdl_fixnum_type), t4
185
+ t5 = $__rdl_parser.scan_str "(Fixnum x, x: Fixnum) -> Fixnum"
186
+ assert_equal (MethodType.new [@tfixnumx, FiniteHashType.new(x: $__rdl_fixnum_type)], nil, $__rdl_fixnum_type), t5
187
+ t6 = $__rdl_parser.scan_str "(x: Fixnum) -> Fixnum"
188
+ assert_equal (MethodType.new [FiniteHashType.new(x: $__rdl_fixnum_type)], nil, $__rdl_fixnum_type), t6
189
+ t7 = $__rdl_parser.scan_str "(x: Fixnum) { (%any, String) -> nil } -> :symbol"
190
+ assert_equal (MethodType.new [FiniteHashType.new(x: $__rdl_fixnum_type)], MethodType.new([$__rdl_top_type, $__rdl_string_type], nil, $__rdl_nil_type), @tsymbol), t7
194
191
  end
195
192
 
196
193
  end