rdl 1.0.0.rc3 → 1.0.0.rc4

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 (77) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +44 -0
  3. data/.travis.yml +19 -0
  4. data/LICENSE +29 -0
  5. data/README.md +509 -0
  6. data/Rakefile +27 -0
  7. data/gemfiles/Gemfile.travis +5 -0
  8. data/lib/rdl/wrap.rb +1 -1
  9. data/lib/rdl_types.rb +4 -2
  10. data/rdl.gemspec +23 -0
  11. data/test/disabled_test_coverage.rb +156 -0
  12. data/test/disabled_test_rdoc.rb +116 -0
  13. data/test/test_alias.rb +66 -0
  14. data/test/test_contract.rb +70 -0
  15. data/test/test_dsl.rb +85 -0
  16. data/test/test_generic.rb +188 -0
  17. data/test/test_intersection.rb +41 -0
  18. data/test/test_le.rb +193 -0
  19. data/test/test_lib_types.rb +194 -0
  20. data/test/test_member.rb +148 -0
  21. data/test/test_parser.rb +196 -0
  22. data/test/test_rdl.rb +301 -0
  23. data/test/test_rdl_type.rb +70 -0
  24. data/test/test_type_contract.rb +187 -0
  25. data/test/test_types.rb +221 -0
  26. data/test/test_wrap.rb +46 -0
  27. data/types/{ruby-2.2.0 → ruby-2.x}/_aliases.rb +0 -0
  28. data/types/{ruby-2.2.0 → ruby-2.x}/abbrev.rb +2 -2
  29. data/types/{ruby-2.2.0 → ruby-2.x}/array.rb +2 -2
  30. data/types/{ruby-2.2.0 → ruby-2.x}/base64.rb +2 -2
  31. data/types/{ruby-2.2.0 → ruby-2.x}/basic_object.rb +2 -1
  32. data/types/{ruby-2.2.0 → ruby-2.x}/benchmark.rb +2 -2
  33. data/types/{ruby-2.2.0 → ruby-2.x}/bigdecimal.rb +4 -4
  34. data/types/{ruby-2.2.0 → ruby-2.x}/bigmath.rb +2 -2
  35. data/types/{ruby-2.2.0 → ruby-2.x}/class.rb +3 -3
  36. data/types/{ruby-2.2.0 → ruby-2.x}/complex.rb +2 -2
  37. data/types/{ruby-2.2.0 → ruby-2.x}/coverage.rb +2 -2
  38. data/types/{ruby-2.2.0 → ruby-2.x}/csv.rb +2 -2
  39. data/types/{ruby-2.2.0 → ruby-2.x}/date.rb +2 -2
  40. data/types/{ruby-2.2.0 → ruby-2.x}/dir.rb +3 -3
  41. data/types/{ruby-2.2.0 → ruby-2.x}/encoding.rb +2 -2
  42. data/types/{ruby-2.2.0 → ruby-2.x}/enumerable.rb +2 -2
  43. data/types/{ruby-2.2.0 → ruby-2.x}/enumerator.rb +1 -1
  44. data/types/{ruby-2.2.0 → ruby-2.x}/exception.rb +2 -0
  45. data/types/{ruby-2.2.0 → ruby-2.x}/file.rb +2 -2
  46. data/types/{ruby-2.2.0 → ruby-2.x}/fileutils.rb +1 -1
  47. data/types/{ruby-2.2.0 → ruby-2.x}/fixnum.rb +2 -2
  48. data/types/{ruby-2.2.0 → ruby-2.x}/float.rb +2 -2
  49. data/types/{ruby-2.2.0 → ruby-2.x}/gem.rb +3 -1
  50. data/types/{ruby-2.2.0 → ruby-2.x}/hash.rb +2 -2
  51. data/types/{ruby-2.2.0 → ruby-2.x}/integer.rb +2 -2
  52. data/types/{ruby-2.2.0 → ruby-2.x}/io.rb +1 -1
  53. data/types/{ruby-2.2.0 → ruby-2.x}/kernel.rb +1 -1
  54. data/types/{ruby-2.2.0 → ruby-2.x}/marshal.rb +2 -2
  55. data/types/{ruby-2.2.0 → ruby-2.x}/matchdata.rb +3 -3
  56. data/types/{ruby-2.2.0 → ruby-2.x}/math.rb +2 -2
  57. data/types/{ruby-2.2.0 → ruby-2.x}/numeric.rb +2 -2
  58. data/types/{ruby-2.2.0 → ruby-2.x}/object.rb +1 -1
  59. data/types/{ruby-2.2.0 → ruby-2.x}/pathname.rb +2 -2
  60. data/types/{ruby-2.2.0 → ruby-2.x}/process.rb +8 -8
  61. data/types/{ruby-2.2.0 → ruby-2.x}/random.rb +2 -2
  62. data/types/{ruby-2.2.0 → ruby-2.x}/range.rb +2 -2
  63. data/types/{ruby-2.2.0 → ruby-2.x}/rational.rb +2 -2
  64. data/types/{ruby-2.2.0 → ruby-2.x}/regexp.rb +2 -2
  65. data/types/{ruby-2.2.0 → ruby-2.x}/set.rb +2 -2
  66. data/types/{ruby-2.2.0 → ruby-2.x}/string.rb +1 -1
  67. data/types/{ruby-2.2.0 → ruby-2.x}/strscan.rb +3 -3
  68. data/types/{ruby-2.2.0 → ruby-2.x}/symbol.rb +2 -2
  69. data/types/{ruby-2.2.0 → ruby-2.x}/time.rb +2 -2
  70. data/types/ruby-2.x/uri.rb +20 -0
  71. data/types/{ruby-2.2.0 → ruby-2.x}/yaml.rb +3 -3
  72. metadata +70 -51
  73. data/lib/rdl/types/wild.rb +0 -26
  74. data/types/other/chronic.rb +0 -5
  75. data/types/other/paperclip_attachment.rb +0 -7
  76. data/types/other/securerandom.rb +0 -4
  77. data/types/ruby-2.2.0/uri.rb +0 -18
@@ -0,0 +1,221 @@
1
+ require 'minitest/autorun'
2
+ require_relative '../lib/rdl.rb'
3
+
4
+ class TestTypes < Minitest::Test
5
+ include RDL::Type
6
+
7
+ def test_nil_top
8
+ tnil = NilType.new
9
+ tnil2 = NilType.new
10
+ assert(tnil.equal? tnil2)
11
+ tnil3 = NominalType.new :NilClass
12
+ assert(tnil.equal? tnil3)
13
+ ttop = TopType.new
14
+ ttop2 = TopType.new
15
+ assert_same ttop, ttop2
16
+ assert (tnil != ttop)
17
+ end
18
+
19
+ def test_nominal
20
+ ta = NominalType.new :A
21
+ ta2 = NominalType.new :A
22
+ ta3 = NominalType.new "A"
23
+ tb = NominalType.new :B
24
+ assert_same ta, ta2
25
+ assert_same ta, ta3
26
+ assert (ta != tb)
27
+ assert_equal "A", ta.name
28
+ end
29
+
30
+ def test_symbol
31
+ ta = SingletonType.new :A
32
+ ta2 = SingletonType.new :A
33
+ tb = SingletonType.new :B
34
+ tan = NominalType.new :A
35
+ assert_same ta, ta2
36
+ assert (ta != tb)
37
+ assert_equal :A, ta.val
38
+ assert (ta != tan)
39
+ end
40
+
41
+ def test_var
42
+ ta = VarType.new :A
43
+ ta2 = VarType.new :A
44
+ ta3 = VarType.new "A"
45
+ tb = VarType.new :B
46
+ tan = NominalType.new :A
47
+ assert_same ta, ta2
48
+ assert_same ta, ta3
49
+ assert (ta != tb)
50
+ assert_equal :A, ta.name
51
+ assert (ta != tan)
52
+ end
53
+
54
+ def u_or_i(c)
55
+ tnil = NilType.new
56
+ ttop = TopType.new
57
+ ta = NominalType.new :A
58
+ tb = NominalType.new :B
59
+ tc = NominalType.new :C
60
+ t1 = c.new ta, tb
61
+ assert_equal 2, t1.types.length
62
+ t2 = c.new tb, ta
63
+ assert_same t1, t2
64
+ t3 = c.new ttop, ttop
65
+ assert_same t3, ttop
66
+ t4 = c.new ttop, tnil, ttop, tnil
67
+ assert_same t4, ttop
68
+ t5 = c.new tnil, tnil
69
+ assert_same t5, tnil
70
+ t6 = c.new ta, tb, tc
71
+ assert_equal 3, t6.types.length
72
+ t7 = c.new ta, (c.new tb, tc)
73
+ assert_same t6, t7
74
+ t8 = c.new (c.new tc, tb), (c.new ta)
75
+ assert_same t6, t8
76
+ assert (t1 != tnil)
77
+ end
78
+
79
+ def test_union_intersection
80
+ u_or_i UnionType
81
+ u_or_i IntersectionType
82
+ end
83
+
84
+ def test_optional
85
+ tnil = NilType.new
86
+ ta = NominalType.new :A
87
+ t1 = OptionalType.new tnil
88
+ assert_equal tnil, t1.type
89
+ t2 = OptionalType.new tnil
90
+ assert_same t1, t2
91
+ t3 = OptionalType.new ta
92
+ assert (t1 != t3)
93
+ end
94
+
95
+ def test_vararg
96
+ tnil = NilType.new
97
+ ta = NominalType.new :A
98
+ t1 = VarargType.new tnil
99
+ assert_equal tnil, t1.type
100
+ t2 = VarargType.new tnil
101
+ assert_same t1, t2
102
+ t3 = VarargType.new ta
103
+ assert (t1 != t3)
104
+ end
105
+
106
+ def test_method
107
+ tnil = NilType.new
108
+ ta = NominalType.new :A
109
+ tb = NominalType.new :B
110
+ tc = NominalType.new :C
111
+ t1 = MethodType.new [ta, tb, tc], nil, tnil
112
+ assert_equal [ta, tb, tc], t1.args
113
+ assert_nil t1.block
114
+ assert_equal tnil, t1.ret
115
+ t2 = MethodType.new [tnil], t1, tnil
116
+ assert_equal t1, t2.block
117
+ end
118
+
119
+ def test_generic
120
+ thash = NominalType.new :Hash
121
+ ta = NominalType.new :A
122
+ tb = NominalType.new :B
123
+ t1 = GenericType.new thash, ta, tb
124
+ assert_equal thash, t1.base
125
+ assert_equal [ta, tb], t1.params
126
+ t2 = GenericType.new thash, ta, tb
127
+ assert_same t1, t2
128
+ t3 = GenericType.new thash, tb, ta
129
+ assert (t1 != t3)
130
+ tavar = VarType.new :a
131
+ tbvar = VarType.new :b
132
+ t4 = GenericType.new thash, tavar, tbvar
133
+ assert_equal "Hash<a, b>", t4.to_s
134
+ end
135
+
136
+ def test_structural
137
+ tnil = NilType.new
138
+ ta = NominalType.new :A
139
+ tb = NominalType.new :B
140
+ tc = NominalType.new :C
141
+ tm1 = MethodType.new [ta, tb, tc], nil, tnil
142
+ tm2 = MethodType.new [ta], tm1, tb
143
+ t1 = StructuralType.new(m1: tm1, m2: tm2)
144
+ assert_equal tm1, t1.methods[:m1]
145
+ assert_equal tm2, t1.methods[:m2]
146
+ t2 = StructuralType.new(m1: tm1, m2: tm2)
147
+ assert_equal t1, t2
148
+ end
149
+
150
+ def test_singleton_caching
151
+ s = Set.new
152
+ r = Set.new
153
+ t1 = SingletonType.new(s)
154
+ t2 = SingletonType.new(r)
155
+ assert (t1 != t2) # shouldn't be the same since they're different
156
+ # objects! e.g., mutating one won't change the
157
+ # other
158
+ end
159
+
160
+ def test_instantiate
161
+ tnil = NilType.new
162
+ ttop = TopType.new
163
+ tA = NominalType.new :A
164
+ tB = NominalType.new :B
165
+ toptionalA = OptionalType.new tA
166
+ tvarargA = VarargType.new tA
167
+ tannotatedA = AnnotatedArgType.new("arg", tA)
168
+ tunionAB = UnionType.new(tA, tB)
169
+ tinterAB = IntersectionType.new(tA, tB)
170
+ tsyma = SingletonType.new(:a)
171
+ tstring = NominalType.new :String
172
+ tfixnum = NominalType.new :Fixnum
173
+ ta = VarType.new :a
174
+ tb = VarType.new :b
175
+ tc = VarType.new :c
176
+ thash = NominalType.new :Hash
177
+ thashAB = GenericType.new(thash, tA, tB)
178
+ thashab = GenericType.new(thash, ta, tb)
179
+ thashstringfixnum = GenericType.new(thash, tstring, tfixnum)
180
+ inst = {a: tstring, b: tfixnum}
181
+ ttupleAB = TupleType.new(tA, tB)
182
+ ttupleab = TupleType.new(ta, tb)
183
+ ttuplestringfixnum = TupleType.new(tstring, tfixnum)
184
+ tfinitehashaAbB = FiniteHashType.new(a: tA, b: tB)
185
+ tfinitehashaabb = FiniteHashType.new(a: ta, b: tb)
186
+ tfinitehashastringbfixnum = FiniteHashType.new(a: tstring, b: tfixnum)
187
+ tmethAAB = MethodType.new([tA, tA], nil, tB)
188
+ tmethaab = MethodType.new([ta, ta], nil, tb)
189
+ tmethstringstringfixnum = MethodType.new([tstring, tstring], nil, tfixnum)
190
+ tmethbAABn = MethodType.new([], tmethAAB, tnil)
191
+ tmethbaabn = MethodType.new([], tmethaab, tnil)
192
+ tmethbssfn = MethodType.new([], tmethstringstringfixnum, tnil)
193
+ tstructorig = StructuralType.new(m1: tmethAAB, m2: tmethaab,
194
+ m3: tmethbAABn, m4: tmethbaabn)
195
+ tstructinst = StructuralType.new(m1: tmethAAB, m2: tmethstringstringfixnum,
196
+ m3: tmethbAABn, m4: tmethbssfn)
197
+ assert_equal tnil, tnil.instantiate(inst)
198
+ assert_equal ttop, ttop.instantiate(inst)
199
+ assert_equal tA, tA.instantiate(inst)
200
+ assert_equal toptionalA, toptionalA.instantiate(inst)
201
+ assert_equal tvarargA, tvarargA.instantiate(inst)
202
+ assert_equal tannotatedA, tannotatedA.instantiate(inst)
203
+ assert_equal tunionAB, tunionAB.instantiate(inst)
204
+ assert_equal tinterAB, tinterAB.instantiate(inst)
205
+ assert_equal tsyma, tsyma.instantiate(inst)
206
+ assert_equal tstring, ta.instantiate(inst)
207
+ assert_equal tfixnum, tb.instantiate(inst)
208
+ assert_equal tc, tc.instantiate(inst)
209
+ assert_equal thashAB, thashAB.instantiate(inst)
210
+ assert_equal thashstringfixnum, thashab.instantiate(inst)
211
+ assert_equal ttupleAB, ttupleAB.instantiate(inst)
212
+ assert_equal ttuplestringfixnum, ttupleab.instantiate(inst)
213
+ assert_equal tfinitehashaAbB, tfinitehashaAbB.instantiate(inst)
214
+ assert_equal tfinitehashastringbfixnum, tfinitehashaabb.instantiate(inst)
215
+ assert_equal tmethAAB, tmethAAB.instantiate(inst)
216
+ assert_equal tmethstringstringfixnum, tmethaab.instantiate(inst)
217
+ assert_equal tmethbAABn, tmethbAABn.instantiate(inst)
218
+ assert_equal tmethbssfn, tmethbaabn.instantiate(inst)
219
+ assert_equal tstructinst, tstructorig.instantiate(inst)
220
+ end
221
+ end
@@ -0,0 +1,46 @@
1
+ require 'minitest/autorun'
2
+ require_relative '../lib/rdl.rb'
3
+
4
+ class TestWrap < Minitest::Test
5
+ class C
6
+ def foo_public(x)
7
+ foo(x)
8
+ end
9
+
10
+ private
11
+
12
+ def foo(x)
13
+ x + 1
14
+ end
15
+ end
16
+
17
+ def test_private_wrap
18
+ type C, :foo, '(Fixnum) -> Fixnum'
19
+ c = C.new
20
+
21
+ assert_raises RDL::Type::TypeError do
22
+ c.foo_public("1")
23
+ end
24
+ end
25
+
26
+ class D
27
+ def foo_public(x)
28
+ foo(x)
29
+ end
30
+
31
+ protected
32
+
33
+ def foo(x)
34
+ x + 1
35
+ end
36
+ end
37
+
38
+ def test_protected_wrap
39
+ type D, :foo, '(Fixnum) -> Fixnum'
40
+ d = D.new
41
+
42
+ assert_raises RDL::Type::TypeError do
43
+ d.foo_public("1")
44
+ end
45
+ end
46
+ end
@@ -1,5 +1,5 @@
1
1
  module Abbrev
2
- nowrap
2
+ rdl_nowrap
3
3
 
4
4
  type 'self.abbrev', '(Array<String>) -> Hash<String,String>'
5
- end
5
+ end
@@ -1,8 +1,8 @@
1
1
  class Array
2
- nowrap
2
+ rdl_nowrap
3
3
 
4
4
  type_params [:t], :all?
5
-
5
+
6
6
  type :<<, '(t) -> Array<t>'
7
7
  type :[], '(Range<Fixnum>) -> Array<t>'
8
8
  type :[], '(Fixnum or Float) -> t'
@@ -1,5 +1,5 @@
1
1
  module Base64
2
- nowrap
2
+ rdl_nowrap
3
3
 
4
4
  type 'self.decode64', '(String) -> String'
5
5
  type 'self.encode64', '(String) -> String'
@@ -7,4 +7,4 @@ module Base64
7
7
  type 'self.strict_encode64', '(String) -> String'
8
8
  type 'self.urlsafe_decode64', '(String) -> String'
9
9
  type 'self.urlsafe_encode64', '(String) -> String'
10
- end
10
+ end
@@ -1,5 +1,6 @@
1
1
  class BasicObject
2
- nowrap
2
+ rdl_nowrap
3
+
3
4
  type :==, '(%any other) -> %bool'
4
5
  type :equal?, '(%any other) -> %bool'
5
6
  type :!, '() -> %bool'
@@ -1,5 +1,5 @@
1
1
  module Benchmark
2
- nowrap
2
+ rdl_nowrap
3
3
 
4
4
  type 'self.benchmark', '(String, ?Fixnum, ?String, *String) -> Array<Benchmark::Tms>'
5
5
  type 'self.bm', '(?Fixnum, *String) { (Benchmark::Process) -> nil} -> Array<Benchmark::Tms>'
@@ -8,4 +8,4 @@ module Benchmark
8
8
  type 'self.bmbm', '(?Fixnum label_width) { (Benchmark::Process) -> nil} -> Array<Benchmark::Tms>'
9
9
  type 'self.measure', '(?String label) -> Benchmark::Tms'
10
10
  type 'self.realtime', '() {(*%any) -> %any} -> Fixnum'
11
- end
11
+ end
@@ -1,6 +1,6 @@
1
1
  class BigDecimal
2
- nowrap
3
-
2
+ rdl_nowrap
3
+
4
4
  #type 'self._load', '()'
5
5
  type 'self.double_fig', '() -> Fixnum'
6
6
  type 'self.limit', '(Fixnum) -> Fixnum'
@@ -10,6 +10,6 @@ class BigDecimal
10
10
  type 'self.save_limit', '() { (*%any) -> %any } -> %any'
11
11
  type 'self.save_rounding_mode', '() { (*%any) -> %any } -> %any'
12
12
  type 'self.ver', '() -> String'
13
-
13
+
14
14
  # TODO
15
- end
15
+ end
@@ -1,5 +1,5 @@
1
1
  module BigMath
2
- nowrap
2
+ rdl_nowrap
3
3
 
4
4
  type 'self.exp', '(Fixnum, Fixnum) -> BigDecimal'
5
5
  type 'self.log', '(Fixnum, Fixnum) -> BigDecimal'
@@ -9,4 +9,4 @@ module BigMath
9
9
  type :cos, '(Fixnum, Fixnum) -> BigDecimal'
10
10
  type :sin, '(Fixnum, Fixnum) -> BigDecimal'
11
11
  type :sqrt, '(Fixnum, Fixnum) -> BigDecimal'
12
- end
12
+ end
@@ -1,12 +1,12 @@
1
1
  class Class
2
- nowrap
3
-
2
+ rdl_nowrap
3
+
4
4
  type 'allocate', '() -> %any' # Instance of class self
5
5
  type 'inherited', '(Class) -> %any'
6
6
  #type 'initialize', '() -> '
7
7
  #type 'new', '(*%any) -> %any' #Causes two other test cases to fail
8
8
  type 'superclass', '() -> Class or nil'
9
-
9
+
10
10
  # type :class_eval, '() {() -> %any} -> %any'
11
11
  # type :method_defined?, '(String or Symbol) -> %bool'
12
12
  # type :define_method, '(String or Symbol) {(*%any) -> %any} -> Proc'
@@ -1,5 +1,5 @@
1
1
  class Complex
2
- nowrap
2
+ rdl_nowrap
3
3
 
4
4
  type 'self.polar', '(%real abs, ?%real arg) -> Complex'
5
5
  type 'self.rect', '(%real real, ?%real imag) -> Complex'
@@ -39,4 +39,4 @@ class Complex
39
39
  type :to_i, '() -> Integer'
40
40
  type :to_r, '() -> Rational'
41
41
  type :to_s, '() -> String'
42
- end
42
+ end
@@ -1,6 +1,6 @@
1
1
  module Coverage
2
- nowrap
2
+ rdl_nowrap
3
3
 
4
4
  type 'self.start', '() -> nil'
5
5
  type 'self.result', '() -> Hash<String,Array<Fixnum or nil>>'
6
- end
6
+ end
@@ -1,5 +1,5 @@
1
1
  class CSV
2
- nowrap
2
+ rdl_nowrap
3
3
 
4
4
  type 'self.foreach', '(String or File, ?Hash<Symbol, %any>) {(Array<String>) -> %any} -> NilClass'
5
- end
5
+ end
@@ -1,6 +1,6 @@
1
1
  class Date
2
- nowrap
3
-
2
+ rdl_nowrap
3
+
4
4
  type('self.now', "() -> DateTime")
5
5
  type(:strftime, "(String) -> String")
6
6
  end
@@ -1,6 +1,6 @@
1
1
  class Dir
2
- nowrap
3
-
2
+ rdl_nowrap
3
+
4
4
  rdl_alias :[], :glob
5
5
  type 'self.chdir', '(?(String or Pathname)) -> 0'
6
6
  type 'self.chdir', '(?(String or Pathname)) { (String) -> u } -> u'
@@ -35,4 +35,4 @@ class Dir
35
35
  type :seek, '(Fixnum) -> self'
36
36
  type :tell, '() -> Fixnum'
37
37
  type :to_path, '() -> String or nil'
38
- end
38
+ end
@@ -1,5 +1,5 @@
1
1
  class Encoding
2
- nowrap
2
+ rdl_nowrap
3
3
 
4
4
  type 'self.aliases', '() -> Hash<String, String>'
5
5
  type 'self.compatible?', '(%any obj1, %any obj2) -> Encoding or nil'
@@ -20,4 +20,4 @@ class Encoding
20
20
  type :names, '() -> Array<String>'
21
21
  type :replicate, '(String name) -> Encoding'
22
22
  rdl_alias :to_s, :name
23
- end
23
+ end
@@ -1,8 +1,8 @@
1
1
  module Enumerable
2
- nowrap
2
+ rdl_nowrap
3
3
 
4
4
  type_params [:t], :all?
5
-
5
+
6
6
  type :all?, '() -> %bool'
7
7
  type :all?, '() { (t) -> %bool } -> %bool'
8
8
  type :any?, '() -> %bool'