rdl 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +13 -0
- data/CHANGES.md +35 -0
- data/README.md +153 -116
- data/bin/rdl_query +1 -1
- data/extras/type_tests/typetests.rb +905 -0
- data/lib/rdl.rb +0 -1
- data/lib/rdl/boot.rb +108 -77
- data/lib/rdl/boot_rails.rb +2 -8
- data/lib/rdl/config.rb +44 -17
- data/lib/rdl/contracts/flat.rb +1 -1
- data/lib/rdl/info.rb +3 -3
- data/lib/rdl/query.rb +11 -11
- data/lib/rdl/typecheck.rb +399 -136
- data/lib/rdl/types/finite_hash.rb +3 -2
- data/lib/rdl/types/generic.rb +7 -6
- data/lib/rdl/types/intersection.rb +3 -2
- data/lib/rdl/types/lexer.rex +2 -3
- data/lib/rdl/types/lexer.rex.rb +1 -4
- data/lib/rdl/types/method.rb +7 -6
- data/lib/rdl/types/nominal.rb +10 -1
- data/lib/rdl/types/parser.racc +7 -8
- data/lib/rdl/types/parser.tab.rb +108 -109
- data/lib/rdl/types/structural.rb +1 -0
- data/lib/rdl/types/tuple.rb +2 -2
- data/lib/rdl/types/type.rb +8 -8
- data/lib/rdl/types/type_inferencer.rb +1 -1
- data/lib/rdl/types/union.rb +2 -1
- data/lib/rdl/util.rb +28 -3
- data/lib/rdl/wrap.rb +216 -165
- data/lib/rdl_disable.rb +22 -15
- data/lib/types/core.rb +2 -4
- data/lib/types/core/_aliases.rb +14 -0
- data/lib/types/core/abbrev.rb +3 -0
- data/lib/types/core/array.rb +139 -0
- data/lib/types/core/base64.rb +8 -0
- data/lib/types/core/basic_object.rb +12 -0
- data/lib/types/core/benchmark.rb +9 -0
- data/lib/types/core/bigdecimal.rb +223 -0
- data/lib/types/core/bigmath.rb +10 -0
- data/lib/types/core/bignum.rb +214 -0
- data/lib/types/core/class.rb +15 -0
- data/lib/types/core/complex.rb +123 -0
- data/lib/types/core/coverage.rb +4 -0
- data/lib/types/core/csv.rb +3 -0
- data/lib/types/core/date.rb +4 -0
- data/lib/types/core/dir.rb +37 -0
- data/lib/types/core/encoding.rb +21 -0
- data/lib/types/core/enumerable.rb +96 -0
- data/lib/types/core/enumerator.rb +24 -0
- data/lib/types/core/exception.rb +15 -0
- data/lib/types/core/file.rb +125 -0
- data/lib/types/core/fileutils.rb +4 -0
- data/lib/types/core/fixnum.rb +213 -0
- data/lib/types/core/float.rb +199 -0
- data/lib/types/core/gem.rb +19 -0
- data/lib/types/core/hash.rb +72 -0
- data/lib/types/core/integer.rb +194 -0
- data/lib/types/core/io.rb +101 -0
- data/lib/types/core/kernel.rb +89 -0
- data/lib/types/core/marshal.rb +3 -0
- data/lib/types/core/matchdata.rb +24 -0
- data/lib/types/core/math.rb +50 -0
- data/lib/types/core/module.rb +81 -0
- data/lib/types/core/nil.rb +11 -0
- data/lib/types/core/numeric.rb +56 -0
- data/lib/types/core/object.rb +73 -0
- data/lib/types/core/pathname.rb +104 -0
- data/lib/types/core/proc.rb +12 -0
- data/lib/types/core/process.rb +110 -0
- data/lib/types/core/random.rb +13 -0
- data/lib/types/core/range.rb +37 -0
- data/lib/types/core/rational.rb +207 -0
- data/lib/types/core/regexp.rb +28 -0
- data/lib/types/core/set.rb +56 -0
- data/lib/types/core/string.rb +140 -0
- data/lib/types/core/strscan.rb +6 -0
- data/lib/types/core/symbol.rb +27 -0
- data/lib/types/core/time.rb +66 -0
- data/lib/types/core/uri.rb +18 -0
- data/lib/types/core/yaml.rb +3 -0
- data/lib/types/devise.rb +1 -0
- data/lib/types/devise/controller_helpers.rb +3 -0
- data/lib/types/devise/parameter_sanitizer.rb +2 -0
- data/lib/types/pundit.rb +2 -0
- data/lib/types/rails/_helpers.rb +50 -0
- data/lib/types/rails/abstract_controller/translation.rb +2 -0
- data/lib/types/rails/action_controller/base.rb +3 -0
- data/lib/types/rails/action_controller/instrumentation.rb +6 -0
- data/lib/types/rails/action_controller/metal.rb +3 -0
- data/lib/types/rails/action_controller/mime_responds.rb +13 -0
- data/lib/types/rails/action_controller/parameters.rb +3 -0
- data/lib/types/{rails-5.x → rails}/action_controller/strong_parameters.rb +4 -8
- data/lib/types/rails/action_dispatch/flashhash.rb +8 -0
- data/lib/types/rails/action_dispatch/routing.rb +10 -0
- data/lib/types/rails/action_mailer/base.rb +2 -0
- data/lib/types/rails/action_mailer/message_delivery.rb +2 -0
- data/lib/types/rails/action_view/helpers_sanitizehelper.rb +2 -0
- data/lib/types/rails/action_view/helpers_urlhelper.rb +5 -0
- data/lib/types/rails/active_model/errors.rb +14 -0
- data/lib/types/rails/active_model/validations.rb +2 -0
- data/lib/types/rails/active_record/associations.rb +208 -0
- data/lib/types/rails/active_record/base.rb +2 -0
- data/lib/types/rails/active_record/core.rb +2 -0
- data/lib/types/rails/active_record/finder_methods.rb +2 -0
- data/lib/types/rails/active_record/model_schema.rb +37 -0
- data/lib/types/rails/active_record/relation.rb +11 -0
- data/lib/types/rails/active_record/schema_types.rb +51 -0
- data/lib/types/rails/active_record/validations.rb +2 -0
- data/lib/types/rails/active_support/base.rb +2 -0
- data/lib/types/rails/active_support/logger.rb +3 -0
- data/lib/types/rails/active_support/tagged_logging.rb +2 -0
- data/lib/types/rails/active_support/time_with_zone.rb +13 -0
- data/lib/types/rails/active_support/time_zone.rb +2 -0
- data/lib/types/rails/fixnum.rb +2 -0
- data/lib/types/rails/integer.rb +2 -0
- data/lib/types/rails/rack/request.rb +2 -0
- data/lib/types/rails/string.rb +3 -0
- data/lib/types/rails/time.rb +1 -0
- data/rdl.gemspec +2 -2
- data/test/disabled_test_rdoc.rb +8 -8
- data/test/test_alias.rb +1 -0
- data/test/test_dsl.rb +4 -4
- data/test/test_generic.rb +45 -38
- data/test/test_intersection.rb +10 -10
- data/test/test_le.rb +103 -102
- data/test/test_member.rb +33 -33
- data/test/test_parser.rb +101 -96
- data/test/test_query.rb +84 -84
- data/test/test_rdl.rb +87 -52
- data/test/test_rdl_type.rb +26 -9
- data/test/test_type_contract.rb +32 -31
- data/test/test_typecheck.rb +802 -436
- data/test/test_types.rb +39 -39
- data/test/test_wrap.rb +3 -2
- metadata +91 -120
- data/extras/type_tests/%.rb +0 -171
- data/extras/type_tests/&.rb +0 -159
- data/extras/type_tests/**.rb +0 -222
- data/extras/type_tests/*.rb +0 -177
- data/extras/type_tests/+.rb +0 -170
- data/extras/type_tests/-.rb +0 -171
- data/extras/type_tests/1scomp.rb +0 -157
- data/extras/type_tests/<.rb +0 -170
- data/extras/type_tests/<<.rb +0 -159
- data/extras/type_tests/>>.rb +0 -159
- data/extras/type_tests/[].rb +0 -163
- data/extras/type_tests/^.rb +0 -159
- data/extras/type_tests/abs.rb +0 -155
- data/extras/type_tests/abs2.rb +0 -164
- data/extras/type_tests/angle.rb +0 -157
- data/extras/type_tests/arg.rb +0 -157
- data/extras/type_tests/bit_length.rb +0 -157
- data/extras/type_tests/ceil.rb +0 -157
- data/extras/type_tests/ceilRational.rb +0 -160
- data/extras/type_tests/conj.rb +0 -158
- data/extras/type_tests/defwhere.rb +0 -86
- data/extras/type_tests/denominator.rb +0 -157
- data/extras/type_tests/div.rb +0 -172
- data/extras/type_tests/divslash.rb +0 -179
- data/extras/type_tests/even?.rb +0 -157
- data/extras/type_tests/fdiv.rb +0 -244
- data/extras/type_tests/finite?.rb +0 -157
- data/extras/type_tests/floor.rb +0 -157
- data/extras/type_tests/floorRational.rb +0 -161
- data/extras/type_tests/hash.rb +0 -157
- data/extras/type_tests/imag.rb +0 -158
- data/extras/type_tests/infinite?.rb +0 -157
- data/extras/type_tests/modulo.rb +0 -171
- data/extras/type_tests/nan?.rb +0 -157
- data/extras/type_tests/neg.rb +0 -155
- data/extras/type_tests/next.rb +0 -157
- data/extras/type_tests/next_float.rb +0 -157
- data/extras/type_tests/numerator.rb +0 -157
- data/extras/type_tests/phase.rb +0 -157
- data/extras/type_tests/prev_float.rb +0 -157
- data/extras/type_tests/quo.rb +0 -179
- data/extras/type_tests/rationalize.rb +0 -157
- data/extras/type_tests/rationalizeArg.rb +0 -198
- data/extras/type_tests/real.rb +0 -157
- data/extras/type_tests/real?.rb +0 -157
- data/extras/type_tests/round.rb +0 -157
- data/extras/type_tests/roundArg.rb +0 -169
- data/extras/type_tests/size.rb +0 -157
- data/extras/type_tests/to_c.rb +0 -157
- data/extras/type_tests/to_f.rb +0 -155
- data/extras/type_tests/to_i.rb +0 -157
- data/extras/type_tests/to_r.rb +0 -157
- data/extras/type_tests/to_s.rb +0 -157
- data/extras/type_tests/truncate.rb +0 -157
- data/extras/type_tests/truncateArg.rb +0 -166
- data/extras/type_tests/type tests +0 -1
- data/extras/type_tests/zero?.rb +0 -155
- data/extras/type_tests/|.rb +0 -159
- data/lib/types/core-ruby-2.x/_aliases.rb +0 -15
- data/lib/types/core-ruby-2.x/abbrev.rb +0 -5
- data/lib/types/core-ruby-2.x/array.rb +0 -137
- data/lib/types/core-ruby-2.x/base64.rb +0 -10
- data/lib/types/core-ruby-2.x/basic_object.rb +0 -14
- data/lib/types/core-ruby-2.x/benchmark.rb +0 -11
- data/lib/types/core-ruby-2.x/bigdecimal.rb +0 -224
- data/lib/types/core-ruby-2.x/bigmath.rb +0 -12
- data/lib/types/core-ruby-2.x/bignum.rb +0 -214
- data/lib/types/core-ruby-2.x/class.rb +0 -17
- data/lib/types/core-ruby-2.x/complex.rb +0 -124
- data/lib/types/core-ruby-2.x/coverage.rb +0 -6
- data/lib/types/core-ruby-2.x/csv.rb +0 -5
- data/lib/types/core-ruby-2.x/date.rb +0 -6
- data/lib/types/core-ruby-2.x/dir.rb +0 -38
- data/lib/types/core-ruby-2.x/encoding.rb +0 -23
- data/lib/types/core-ruby-2.x/enumerable.rb +0 -98
- data/lib/types/core-ruby-2.x/enumerator.rb +0 -26
- data/lib/types/core-ruby-2.x/exception.rb +0 -17
- data/lib/types/core-ruby-2.x/file.rb +0 -126
- data/lib/types/core-ruby-2.x/fileutils.rb +0 -6
- data/lib/types/core-ruby-2.x/fixnum.rb +0 -213
- data/lib/types/core-ruby-2.x/float.rb +0 -199
- data/lib/types/core-ruby-2.x/gem.rb +0 -247
- data/lib/types/core-ruby-2.x/hash.rb +0 -72
- data/lib/types/core-ruby-2.x/integer.rb +0 -197
- data/lib/types/core-ruby-2.x/io.rb +0 -103
- data/lib/types/core-ruby-2.x/kernel.rb +0 -90
- data/lib/types/core-ruby-2.x/marshal.rb +0 -5
- data/lib/types/core-ruby-2.x/matchdata.rb +0 -26
- data/lib/types/core-ruby-2.x/math.rb +0 -53
- data/lib/types/core-ruby-2.x/module.rb +0 -83
- data/lib/types/core-ruby-2.x/nil.rb +0 -12
- data/lib/types/core-ruby-2.x/numeric.rb +0 -56
- data/lib/types/core-ruby-2.x/object.rb +0 -75
- data/lib/types/core-ruby-2.x/pathname.rb +0 -106
- data/lib/types/core-ruby-2.x/proc.rb +0 -16
- data/lib/types/core-ruby-2.x/process.rb +0 -127
- data/lib/types/core-ruby-2.x/random.rb +0 -17
- data/lib/types/core-ruby-2.x/range.rb +0 -39
- data/lib/types/core-ruby-2.x/rational.rb +0 -209
- data/lib/types/core-ruby-2.x/regexp.rb +0 -30
- data/lib/types/core-ruby-2.x/set.rb +0 -58
- data/lib/types/core-ruby-2.x/string.rb +0 -143
- data/lib/types/core-ruby-2.x/strscan.rb +0 -7
- data/lib/types/core-ruby-2.x/symbol.rb +0 -29
- data/lib/types/core-ruby-2.x/time.rb +0 -68
- data/lib/types/core-ruby-2.x/uri.rb +0 -20
- data/lib/types/core-ruby-2.x/yaml.rb +0 -5
- data/lib/types/rails-5.x/_helpers.rb +0 -52
- data/lib/types/rails-5.x/action_controller/mime_responds.rb +0 -11
- data/lib/types/rails-5.x/action_dispatch/routing.rb +0 -10
- data/lib/types/rails-5.x/active_model/errors.rb +0 -15
- data/lib/types/rails-5.x/active_model/validations.rb +0 -5
- data/lib/types/rails-5.x/active_record/associations.rb +0 -190
- data/lib/types/rails-5.x/active_record/core.rb +0 -3
- data/lib/types/rails-5.x/active_record/model_schema.rb +0 -39
- data/lib/types/rails-5.x/fixnum.rb +0 -3
data/test/test_types.rb
CHANGED
@@ -11,13 +11,13 @@ class TestTypes < Minitest::Test
|
|
11
11
|
|
12
12
|
def test_nil_top
|
13
13
|
tnil = NominalType.new :NilClass
|
14
|
-
assert_equal
|
14
|
+
assert_equal RDL::Globals.types[:nil], tnil
|
15
15
|
tnil2 = SingletonType.new nil
|
16
|
-
assert_equal
|
16
|
+
assert_equal RDL::Globals.types[:nil], tnil2
|
17
17
|
ttop = TopType.new
|
18
18
|
ttop2 = TopType.new
|
19
19
|
assert_equal ttop, ttop2
|
20
|
-
assert (
|
20
|
+
assert (RDL::Globals.types[:nil] != ttop)
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_nominal
|
@@ -63,31 +63,31 @@ class TestTypes < Minitest::Test
|
|
63
63
|
assert_equal 2, t1.types.length
|
64
64
|
t2 = c.new tb, ta
|
65
65
|
assert_equal t1, t2
|
66
|
-
t3 = c.new
|
67
|
-
assert_equal
|
68
|
-
t4 = c.new
|
69
|
-
assert_equal
|
70
|
-
t5 = c.new
|
71
|
-
assert_equal
|
72
|
-
t6 = c.new ta, tb, tc
|
73
|
-
assert_equal
|
74
|
-
t7 = c.new
|
75
|
-
assert_equal
|
76
|
-
|
77
|
-
assert_equal t6, t8
|
78
|
-
assert (t1 != $__rdl_nil_type)
|
66
|
+
t3 = c.new RDL::Globals.types[:top], RDL::Globals.types[:top]
|
67
|
+
assert_equal RDL::Globals.types[:top], t3
|
68
|
+
t4 = c.new RDL::Globals.types[:nil], RDL::Globals.types[:nil]
|
69
|
+
assert_equal RDL::Globals.types[:nil], t4
|
70
|
+
t5 = c.new ta, tb, tc
|
71
|
+
assert_equal 3, t5.types.length
|
72
|
+
t6 = c.new ta, (c.new tb, tc)
|
73
|
+
assert_equal t5, t6
|
74
|
+
t7 = c.new (c.new tc, tb), (c.new ta)
|
75
|
+
assert_equal t5, t7
|
76
|
+
assert (t1 != RDL::Globals.types[:nil])
|
79
77
|
end
|
80
78
|
|
81
79
|
def test_union_intersection
|
82
80
|
u_or_i UnionType
|
83
81
|
u_or_i IntersectionType
|
82
|
+
t = UnionType.new RDL::Globals.types[:top], RDL::Globals.types[:nil], RDL::Globals.types[:top], RDL::Globals.types[:nil]
|
83
|
+
assert_equal RDL::Globals.types[:top], t
|
84
84
|
end
|
85
85
|
|
86
86
|
def test_optional
|
87
87
|
ta = NominalType.new :A
|
88
|
-
t1 = OptionalType.new
|
89
|
-
assert_equal
|
90
|
-
t2 = OptionalType.new
|
88
|
+
t1 = OptionalType.new RDL::Globals.types[:nil]
|
89
|
+
assert_equal RDL::Globals.types[:nil], t1.type
|
90
|
+
t2 = OptionalType.new RDL::Globals.types[:nil]
|
91
91
|
assert_equal t1, t2
|
92
92
|
t3 = OptionalType.new ta
|
93
93
|
assert (t1 != t3)
|
@@ -95,9 +95,9 @@ class TestTypes < Minitest::Test
|
|
95
95
|
|
96
96
|
def test_vararg
|
97
97
|
ta = NominalType.new :A
|
98
|
-
t1 = VarargType.new
|
99
|
-
assert_equal
|
100
|
-
t2 = VarargType.new
|
98
|
+
t1 = VarargType.new RDL::Globals.types[:nil]
|
99
|
+
assert_equal RDL::Globals.types[:nil], t1.type
|
100
|
+
t2 = VarargType.new RDL::Globals.types[:nil]
|
101
101
|
assert_equal t1, t2
|
102
102
|
t3 = VarargType.new ta
|
103
103
|
assert (t1 != t3)
|
@@ -107,11 +107,11 @@ class TestTypes < Minitest::Test
|
|
107
107
|
ta = NominalType.new :A
|
108
108
|
tb = NominalType.new :B
|
109
109
|
tc = NominalType.new :C
|
110
|
-
t1 = MethodType.new [ta, tb, tc], nil,
|
110
|
+
t1 = MethodType.new [ta, tb, tc], nil, RDL::Globals.types[:nil]
|
111
111
|
assert_equal [ta, tb, tc], t1.args
|
112
112
|
assert_nil t1.block
|
113
|
-
assert_equal
|
114
|
-
t2 = MethodType.new [
|
113
|
+
assert_equal RDL::Globals.types[:nil], t1.ret
|
114
|
+
t2 = MethodType.new [RDL::Globals.types[:nil]], t1, RDL::Globals.types[:nil]
|
115
115
|
assert_equal t1, t2.block
|
116
116
|
end
|
117
117
|
|
@@ -136,7 +136,7 @@ class TestTypes < Minitest::Test
|
|
136
136
|
ta = NominalType.new :A
|
137
137
|
tb = NominalType.new :B
|
138
138
|
tc = NominalType.new :C
|
139
|
-
tm1 = MethodType.new [ta, tb, tc], nil,
|
139
|
+
tm1 = MethodType.new [ta, tb, tc], nil, RDL::Globals.types[:nil]
|
140
140
|
tm2 = MethodType.new [ta], tm1, tb
|
141
141
|
t1 = StructuralType.new(m1: tm1, m2: tm2)
|
142
142
|
assert_equal tm1, t1.methods[:m1]
|
@@ -166,7 +166,7 @@ class TestTypes < Minitest::Test
|
|
166
166
|
tinterAB = IntersectionType.new(tA, tB)
|
167
167
|
tsyma = SingletonType.new(:a)
|
168
168
|
tstring = NominalType.new :String
|
169
|
-
|
169
|
+
tinteger = NominalType.new :Integer
|
170
170
|
ta = VarType.new :a
|
171
171
|
tb = VarType.new :b
|
172
172
|
tc = VarType.new :c
|
@@ -174,28 +174,28 @@ class TestTypes < Minitest::Test
|
|
174
174
|
thash = NominalType.new :Hash
|
175
175
|
thashAB = GenericType.new(thash, tA, tB)
|
176
176
|
thashab = GenericType.new(thash, ta, tb)
|
177
|
-
thashstringfixnum = GenericType.new(thash, tstring,
|
178
|
-
inst = {a: tstring, b:
|
177
|
+
thashstringfixnum = GenericType.new(thash, tstring, tinteger)
|
178
|
+
inst = {a: tstring, b: tinteger, d: tsyma}
|
179
179
|
ttupleAB = TupleType.new(tA, tB)
|
180
180
|
ttupleab = TupleType.new(ta, tb)
|
181
|
-
ttuplestringfixnum = TupleType.new(tstring,
|
181
|
+
ttuplestringfixnum = TupleType.new(tstring, tinteger)
|
182
182
|
tfinitehashaAbB = FiniteHashType.new({a: tA, b: tB}, nil)
|
183
183
|
tfinitehashaabb = FiniteHashType.new({a: ta, b: tb}, nil)
|
184
|
-
tfinitehashastringbfixnum = FiniteHashType.new({a: tstring, b:
|
184
|
+
tfinitehashastringbfixnum = FiniteHashType.new({a: tstring, b: tinteger}, nil)
|
185
185
|
tfinitehashaabbrd = FiniteHashType.new({a: ta, b: tb}, td)
|
186
|
-
tfinitehashastringbfixnumrsyma = FiniteHashType.new({a: tstring, b:
|
186
|
+
tfinitehashastringbfixnumrsyma = FiniteHashType.new({a: tstring, b: tinteger}, tsyma)
|
187
187
|
tmethAAB = MethodType.new([tA, tA], nil, tB)
|
188
188
|
tmethaab = MethodType.new([ta, ta], nil, tb)
|
189
|
-
tmethstringstringfixnum = MethodType.new([tstring, tstring], nil,
|
190
|
-
tmethbAABn = MethodType.new([], tmethAAB,
|
191
|
-
tmethbaabn = MethodType.new([], tmethaab,
|
192
|
-
tmethbssfn = MethodType.new([], tmethstringstringfixnum,
|
189
|
+
tmethstringstringfixnum = MethodType.new([tstring, tstring], nil, tinteger)
|
190
|
+
tmethbAABn = MethodType.new([], tmethAAB, RDL::Globals.types[:nil])
|
191
|
+
tmethbaabn = MethodType.new([], tmethaab, RDL::Globals.types[:nil])
|
192
|
+
tmethbssfn = MethodType.new([], tmethstringstringfixnum, RDL::Globals.types[:nil])
|
193
193
|
tstructorig = StructuralType.new(m1: tmethAAB, m2: tmethaab,
|
194
194
|
m3: tmethbAABn, m4: tmethbaabn)
|
195
195
|
tstructinst = StructuralType.new(m1: tmethAAB, m2: tmethstringstringfixnum,
|
196
196
|
m3: tmethbAABn, m4: tmethbssfn)
|
197
|
-
assert_equal
|
198
|
-
assert_equal
|
197
|
+
assert_equal RDL::Globals.types[:nil], RDL::Globals.types[:nil].instantiate(inst)
|
198
|
+
assert_equal RDL::Globals.types[:top], RDL::Globals.types[:top].instantiate(inst)
|
199
199
|
assert_equal tA, tA.instantiate(inst)
|
200
200
|
assert_equal toptionalA, toptionalA.instantiate(inst)
|
201
201
|
assert_equal tvarargA, tvarargA.instantiate(inst)
|
@@ -205,7 +205,7 @@ class TestTypes < Minitest::Test
|
|
205
205
|
assert_equal tinterAB, tinterAB.instantiate(inst)
|
206
206
|
assert_equal tsyma, tsyma.instantiate(inst)
|
207
207
|
assert_equal tstring, ta.instantiate(inst)
|
208
|
-
assert_equal
|
208
|
+
assert_equal tinteger, tb.instantiate(inst)
|
209
209
|
assert_equal tc, tc.instantiate(inst)
|
210
210
|
assert_equal thashAB, thashAB.instantiate(inst)
|
211
211
|
assert_equal thashstringfixnum, thashab.instantiate(inst)
|
data/test/test_wrap.rb
CHANGED
@@ -3,6 +3,7 @@ $LOAD_PATH << File.dirname(__FILE__) + "/../lib"
|
|
3
3
|
require 'rdl'
|
4
4
|
|
5
5
|
class TestWrap < Minitest::Test
|
6
|
+
extend RDL::Annotate
|
6
7
|
class C
|
7
8
|
def foo_public(x)
|
8
9
|
foo(x)
|
@@ -16,7 +17,7 @@ class TestWrap < Minitest::Test
|
|
16
17
|
end
|
17
18
|
|
18
19
|
def test_private_wrap
|
19
|
-
type C, :foo, '(
|
20
|
+
RDL.type C, :foo, '(Integer) -> Integer'
|
20
21
|
c = C.new
|
21
22
|
|
22
23
|
assert_raises RDL::Type::TypeError do
|
@@ -37,7 +38,7 @@ class TestWrap < Minitest::Test
|
|
37
38
|
end
|
38
39
|
|
39
40
|
def test_protected_wrap
|
40
|
-
type D, :foo, '(
|
41
|
+
RDL.type D, :foo, '(Integer) -> Integer'
|
41
42
|
d = D.new
|
42
43
|
|
43
44
|
assert_raises RDL::Type::TypeError do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeffrey S. Foster
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date:
|
15
|
+
date: 2017-06-14 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: parser
|
@@ -52,64 +52,7 @@ files:
|
|
52
52
|
- README.md
|
53
53
|
- Rakefile
|
54
54
|
- bin/rdl_query
|
55
|
-
- extras/type_tests
|
56
|
-
- extras/type_tests/&.rb
|
57
|
-
- extras/type_tests/**.rb
|
58
|
-
- extras/type_tests/*.rb
|
59
|
-
- extras/type_tests/+.rb
|
60
|
-
- extras/type_tests/-.rb
|
61
|
-
- extras/type_tests/1scomp.rb
|
62
|
-
- extras/type_tests/<.rb
|
63
|
-
- extras/type_tests/<<.rb
|
64
|
-
- extras/type_tests/>>.rb
|
65
|
-
- extras/type_tests/[].rb
|
66
|
-
- extras/type_tests/^.rb
|
67
|
-
- extras/type_tests/abs.rb
|
68
|
-
- extras/type_tests/abs2.rb
|
69
|
-
- extras/type_tests/angle.rb
|
70
|
-
- extras/type_tests/arg.rb
|
71
|
-
- extras/type_tests/bit_length.rb
|
72
|
-
- extras/type_tests/ceil.rb
|
73
|
-
- extras/type_tests/ceilRational.rb
|
74
|
-
- extras/type_tests/conj.rb
|
75
|
-
- extras/type_tests/defwhere.rb
|
76
|
-
- extras/type_tests/denominator.rb
|
77
|
-
- extras/type_tests/div.rb
|
78
|
-
- extras/type_tests/divslash.rb
|
79
|
-
- extras/type_tests/even?.rb
|
80
|
-
- extras/type_tests/fdiv.rb
|
81
|
-
- extras/type_tests/finite?.rb
|
82
|
-
- extras/type_tests/floor.rb
|
83
|
-
- extras/type_tests/floorRational.rb
|
84
|
-
- extras/type_tests/hash.rb
|
85
|
-
- extras/type_tests/imag.rb
|
86
|
-
- extras/type_tests/infinite?.rb
|
87
|
-
- extras/type_tests/modulo.rb
|
88
|
-
- extras/type_tests/nan?.rb
|
89
|
-
- extras/type_tests/neg.rb
|
90
|
-
- extras/type_tests/next.rb
|
91
|
-
- extras/type_tests/next_float.rb
|
92
|
-
- extras/type_tests/numerator.rb
|
93
|
-
- extras/type_tests/phase.rb
|
94
|
-
- extras/type_tests/prev_float.rb
|
95
|
-
- extras/type_tests/quo.rb
|
96
|
-
- extras/type_tests/rationalize.rb
|
97
|
-
- extras/type_tests/rationalizeArg.rb
|
98
|
-
- extras/type_tests/real.rb
|
99
|
-
- extras/type_tests/real?.rb
|
100
|
-
- extras/type_tests/round.rb
|
101
|
-
- extras/type_tests/roundArg.rb
|
102
|
-
- extras/type_tests/size.rb
|
103
|
-
- extras/type_tests/to_c.rb
|
104
|
-
- extras/type_tests/to_f.rb
|
105
|
-
- extras/type_tests/to_i.rb
|
106
|
-
- extras/type_tests/to_r.rb
|
107
|
-
- extras/type_tests/to_s.rb
|
108
|
-
- extras/type_tests/truncate.rb
|
109
|
-
- extras/type_tests/truncateArg.rb
|
110
|
-
- extras/type_tests/type tests
|
111
|
-
- extras/type_tests/zero?.rb
|
112
|
-
- extras/type_tests/|.rb
|
55
|
+
- extras/type_tests/typetests.rb
|
113
56
|
- gemfiles/Gemfile.travis
|
114
57
|
- lib/rdl.rb
|
115
58
|
- lib/rdl/boot.rb
|
@@ -153,66 +96,94 @@ files:
|
|
153
96
|
- lib/rdl/util.rb
|
154
97
|
- lib/rdl/wrap.rb
|
155
98
|
- lib/rdl_disable.rb
|
156
|
-
- lib/types/core-ruby-2.x/_aliases.rb
|
157
|
-
- lib/types/core-ruby-2.x/abbrev.rb
|
158
|
-
- lib/types/core-ruby-2.x/array.rb
|
159
|
-
- lib/types/core-ruby-2.x/base64.rb
|
160
|
-
- lib/types/core-ruby-2.x/basic_object.rb
|
161
|
-
- lib/types/core-ruby-2.x/benchmark.rb
|
162
|
-
- lib/types/core-ruby-2.x/bigdecimal.rb
|
163
|
-
- lib/types/core-ruby-2.x/bigmath.rb
|
164
|
-
- lib/types/core-ruby-2.x/bignum.rb
|
165
|
-
- lib/types/core-ruby-2.x/class.rb
|
166
|
-
- lib/types/core-ruby-2.x/complex.rb
|
167
|
-
- lib/types/core-ruby-2.x/coverage.rb
|
168
|
-
- lib/types/core-ruby-2.x/csv.rb
|
169
|
-
- lib/types/core-ruby-2.x/date.rb
|
170
|
-
- lib/types/core-ruby-2.x/dir.rb
|
171
|
-
- lib/types/core-ruby-2.x/encoding.rb
|
172
|
-
- lib/types/core-ruby-2.x/enumerable.rb
|
173
|
-
- lib/types/core-ruby-2.x/enumerator.rb
|
174
|
-
- lib/types/core-ruby-2.x/exception.rb
|
175
|
-
- lib/types/core-ruby-2.x/file.rb
|
176
|
-
- lib/types/core-ruby-2.x/fileutils.rb
|
177
|
-
- lib/types/core-ruby-2.x/fixnum.rb
|
178
|
-
- lib/types/core-ruby-2.x/float.rb
|
179
|
-
- lib/types/core-ruby-2.x/gem.rb
|
180
|
-
- lib/types/core-ruby-2.x/hash.rb
|
181
|
-
- lib/types/core-ruby-2.x/integer.rb
|
182
|
-
- lib/types/core-ruby-2.x/io.rb
|
183
|
-
- lib/types/core-ruby-2.x/kernel.rb
|
184
|
-
- lib/types/core-ruby-2.x/marshal.rb
|
185
|
-
- lib/types/core-ruby-2.x/matchdata.rb
|
186
|
-
- lib/types/core-ruby-2.x/math.rb
|
187
|
-
- lib/types/core-ruby-2.x/module.rb
|
188
|
-
- lib/types/core-ruby-2.x/nil.rb
|
189
|
-
- lib/types/core-ruby-2.x/numeric.rb
|
190
|
-
- lib/types/core-ruby-2.x/object.rb
|
191
|
-
- lib/types/core-ruby-2.x/pathname.rb
|
192
|
-
- lib/types/core-ruby-2.x/proc.rb
|
193
|
-
- lib/types/core-ruby-2.x/process.rb
|
194
|
-
- lib/types/core-ruby-2.x/random.rb
|
195
|
-
- lib/types/core-ruby-2.x/range.rb
|
196
|
-
- lib/types/core-ruby-2.x/rational.rb
|
197
|
-
- lib/types/core-ruby-2.x/regexp.rb
|
198
|
-
- lib/types/core-ruby-2.x/set.rb
|
199
|
-
- lib/types/core-ruby-2.x/string.rb
|
200
|
-
- lib/types/core-ruby-2.x/strscan.rb
|
201
|
-
- lib/types/core-ruby-2.x/symbol.rb
|
202
|
-
- lib/types/core-ruby-2.x/time.rb
|
203
|
-
- lib/types/core-ruby-2.x/uri.rb
|
204
|
-
- lib/types/core-ruby-2.x/yaml.rb
|
205
99
|
- lib/types/core.rb
|
206
|
-
- lib/types/
|
207
|
-
- lib/types/
|
208
|
-
- lib/types/
|
209
|
-
- lib/types/
|
210
|
-
- lib/types/
|
211
|
-
- lib/types/
|
212
|
-
- lib/types/
|
213
|
-
- lib/types/
|
214
|
-
- lib/types/
|
215
|
-
- lib/types/
|
100
|
+
- lib/types/core/_aliases.rb
|
101
|
+
- lib/types/core/abbrev.rb
|
102
|
+
- lib/types/core/array.rb
|
103
|
+
- lib/types/core/base64.rb
|
104
|
+
- lib/types/core/basic_object.rb
|
105
|
+
- lib/types/core/benchmark.rb
|
106
|
+
- lib/types/core/bigdecimal.rb
|
107
|
+
- lib/types/core/bigmath.rb
|
108
|
+
- lib/types/core/bignum.rb
|
109
|
+
- lib/types/core/class.rb
|
110
|
+
- lib/types/core/complex.rb
|
111
|
+
- lib/types/core/coverage.rb
|
112
|
+
- lib/types/core/csv.rb
|
113
|
+
- lib/types/core/date.rb
|
114
|
+
- lib/types/core/dir.rb
|
115
|
+
- lib/types/core/encoding.rb
|
116
|
+
- lib/types/core/enumerable.rb
|
117
|
+
- lib/types/core/enumerator.rb
|
118
|
+
- lib/types/core/exception.rb
|
119
|
+
- lib/types/core/file.rb
|
120
|
+
- lib/types/core/fileutils.rb
|
121
|
+
- lib/types/core/fixnum.rb
|
122
|
+
- lib/types/core/float.rb
|
123
|
+
- lib/types/core/gem.rb
|
124
|
+
- lib/types/core/hash.rb
|
125
|
+
- lib/types/core/integer.rb
|
126
|
+
- lib/types/core/io.rb
|
127
|
+
- lib/types/core/kernel.rb
|
128
|
+
- lib/types/core/marshal.rb
|
129
|
+
- lib/types/core/matchdata.rb
|
130
|
+
- lib/types/core/math.rb
|
131
|
+
- lib/types/core/module.rb
|
132
|
+
- lib/types/core/nil.rb
|
133
|
+
- lib/types/core/numeric.rb
|
134
|
+
- lib/types/core/object.rb
|
135
|
+
- lib/types/core/pathname.rb
|
136
|
+
- lib/types/core/proc.rb
|
137
|
+
- lib/types/core/process.rb
|
138
|
+
- lib/types/core/random.rb
|
139
|
+
- lib/types/core/range.rb
|
140
|
+
- lib/types/core/rational.rb
|
141
|
+
- lib/types/core/regexp.rb
|
142
|
+
- lib/types/core/set.rb
|
143
|
+
- lib/types/core/string.rb
|
144
|
+
- lib/types/core/strscan.rb
|
145
|
+
- lib/types/core/symbol.rb
|
146
|
+
- lib/types/core/time.rb
|
147
|
+
- lib/types/core/uri.rb
|
148
|
+
- lib/types/core/yaml.rb
|
149
|
+
- lib/types/devise.rb
|
150
|
+
- lib/types/devise/controller_helpers.rb
|
151
|
+
- lib/types/devise/parameter_sanitizer.rb
|
152
|
+
- lib/types/pundit.rb
|
153
|
+
- lib/types/rails/_helpers.rb
|
154
|
+
- lib/types/rails/abstract_controller/translation.rb
|
155
|
+
- lib/types/rails/action_controller/base.rb
|
156
|
+
- lib/types/rails/action_controller/instrumentation.rb
|
157
|
+
- lib/types/rails/action_controller/metal.rb
|
158
|
+
- lib/types/rails/action_controller/mime_responds.rb
|
159
|
+
- lib/types/rails/action_controller/parameters.rb
|
160
|
+
- lib/types/rails/action_controller/strong_parameters.rb
|
161
|
+
- lib/types/rails/action_dispatch/flashhash.rb
|
162
|
+
- lib/types/rails/action_dispatch/routing.rb
|
163
|
+
- lib/types/rails/action_mailer/base.rb
|
164
|
+
- lib/types/rails/action_mailer/message_delivery.rb
|
165
|
+
- lib/types/rails/action_view/helpers_sanitizehelper.rb
|
166
|
+
- lib/types/rails/action_view/helpers_urlhelper.rb
|
167
|
+
- lib/types/rails/active_model/errors.rb
|
168
|
+
- lib/types/rails/active_model/validations.rb
|
169
|
+
- lib/types/rails/active_record/associations.rb
|
170
|
+
- lib/types/rails/active_record/base.rb
|
171
|
+
- lib/types/rails/active_record/core.rb
|
172
|
+
- lib/types/rails/active_record/finder_methods.rb
|
173
|
+
- lib/types/rails/active_record/model_schema.rb
|
174
|
+
- lib/types/rails/active_record/relation.rb
|
175
|
+
- lib/types/rails/active_record/schema_types.rb
|
176
|
+
- lib/types/rails/active_record/validations.rb
|
177
|
+
- lib/types/rails/active_support/base.rb
|
178
|
+
- lib/types/rails/active_support/logger.rb
|
179
|
+
- lib/types/rails/active_support/tagged_logging.rb
|
180
|
+
- lib/types/rails/active_support/time_with_zone.rb
|
181
|
+
- lib/types/rails/active_support/time_zone.rb
|
182
|
+
- lib/types/rails/fixnum.rb
|
183
|
+
- lib/types/rails/integer.rb
|
184
|
+
- lib/types/rails/rack/request.rb
|
185
|
+
- lib/types/rails/string.rb
|
186
|
+
- lib/types/rails/time.rb
|
216
187
|
- rdl.gemspec
|
217
188
|
- test/disabled_test_coverage.rb
|
218
189
|
- test/disabled_test_rdoc.rb
|
@@ -252,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
252
223
|
version: '0'
|
253
224
|
requirements: []
|
254
225
|
rubyforge_project:
|
255
|
-
rubygems_version: 2.
|
226
|
+
rubygems_version: 2.6.12
|
256
227
|
signing_key:
|
257
228
|
specification_version: 4
|
258
229
|
summary: Ruby type and contract system
|
data/extras/type_tests/%.rb
DELETED
@@ -1,171 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'bigdecimal'
|
4
|
-
require 'rdl'
|
5
|
-
require 'rdl_types'
|
6
|
-
|
7
|
-
MAX_FIXNUM = 2**(0.size*8-2)-1 #Largest fixnum. -2 since 1 bit used for sign, 1 bit used as int marker.
|
8
|
-
MIN_FIXNUM = -(2**(0.size*8-2)) #Smallest fixnum.
|
9
|
-
|
10
|
-
def test()
|
11
|
-
x = gen_number(0.2,0.2,0.2,0.05,0.05,0.2,0,0.1)
|
12
|
-
type_one = x.class.to_s
|
13
|
-
if type_one=="BigDecimal"
|
14
|
-
y = gen_number(0.25,0.25,0.2,0,0,0.2,0,0.1)
|
15
|
-
type_two = y.class.to_s
|
16
|
-
elsif type_one=="Rational"
|
17
|
-
y = gen_number(0.2,0.2,0.2,0.1,0,0.2,0,0.1)
|
18
|
-
type_two = y.class.to_s
|
19
|
-
elsif x.is_a?(Float)&&(x==Float::INFINITY|| x.nan?)
|
20
|
-
y = gen_number(0.2,0.2,0,0.1,0.1,0.3,0,0.1)
|
21
|
-
type_two = y.class.to_s
|
22
|
-
else
|
23
|
-
y = gen_number(0.2,0.2,0.2,0.05,0.05,0.2,0,0.1)
|
24
|
-
type_two = y.class.to_s
|
25
|
-
end
|
26
|
-
#puts "Arg1= #{x} and type = #{type_one}"
|
27
|
-
#puts "Arg2= #{y} and type = #{type_two}"
|
28
|
-
operation_type = query(type_one+'#%',y)
|
29
|
-
expected_type = operation_type[operation_type.index('->')+3..-1]
|
30
|
-
w = x%y
|
31
|
-
#puts "here"
|
32
|
-
test_result = w.is_a?(Object.const_get(expected_type))
|
33
|
-
if !test_result
|
34
|
-
puts "Arg1= #{x} (type: #{type_one})"
|
35
|
-
puts "Arg2= #{y} (type: #{type_two})"
|
36
|
-
puts "Res= #{w}"
|
37
|
-
puts "Expected type: #{expected_type}"
|
38
|
-
puts "Received type: #{w.class}"
|
39
|
-
end
|
40
|
-
#puts test_result
|
41
|
-
return test_result
|
42
|
-
end
|
43
|
-
|
44
|
-
def gen_fixnum()
|
45
|
-
return Random.rand(MIN_FIXNUM..MAX_FIXNUM)
|
46
|
-
end
|
47
|
-
|
48
|
-
def gen_bignum()
|
49
|
-
r = Random.rand()
|
50
|
-
if r<0.5
|
51
|
-
return Random.rand(MAX_FIXNUM+1..MAX_FIXNUM*1000)
|
52
|
-
else
|
53
|
-
return -1*Random.rand(MAX_FIXNUM+1..MAX_FIXNUM*1000)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def gen_float()
|
58
|
-
r = Random.rand()
|
59
|
-
if r<0.5
|
60
|
-
return Float::MAX*Random.rand
|
61
|
-
else
|
62
|
-
return -1*Float::MAX*Random.rand
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def gen_bigdec()
|
67
|
-
r = Random.rand()
|
68
|
-
if r<0.33
|
69
|
-
return BigDecimal.new(gen_fixnum())
|
70
|
-
elsif r<0.66
|
71
|
-
return BigDecimal.new(gen_bignum())
|
72
|
-
else
|
73
|
-
return BigDecimal.new(gen_float(),0)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def gen_complex()
|
78
|
-
x = gen_number(0.2,0.2,0.1,0.05,0.05,0.3,0,0.1)
|
79
|
-
#puts x
|
80
|
-
y = gen_number(0.2,0.2,0.1,0.05,0.05,0.3,0,0.1)
|
81
|
-
#puts y
|
82
|
-
return Complex(x,y)
|
83
|
-
end
|
84
|
-
|
85
|
-
def gen_rational()
|
86
|
-
x = gen_fixnum()
|
87
|
-
y = gen_fixnum()
|
88
|
-
return Rational(x,y)
|
89
|
-
end
|
90
|
-
|
91
|
-
|
92
|
-
def gen_number(probFixnum,probBignum,probBigDec,probInf,probNAN,probFloat,probComplex,probRational)
|
93
|
-
r = Random.rand()
|
94
|
-
if r<probFixnum then
|
95
|
-
#Fixnum type
|
96
|
-
x = gen_fixnum()
|
97
|
-
elsif r<(probFixnum+probBignum)
|
98
|
-
x = gen_bignum()
|
99
|
-
elsif r<(probFixnum+probBignum+probBigDec)
|
100
|
-
#BigDecimal type
|
101
|
-
x = gen_bigdec()
|
102
|
-
elsif r<(probFixnum+probBignum+probBigDec+probInf)
|
103
|
-
x=Float::INFINITY
|
104
|
-
elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN)
|
105
|
-
x=Float::NAN
|
106
|
-
elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat)
|
107
|
-
#Random Float type
|
108
|
-
x = gen_float()
|
109
|
-
elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat+probComplex)
|
110
|
-
x= gen_complex()
|
111
|
-
elsif (probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat+probComplex+probRational)
|
112
|
-
x = gen_rational()
|
113
|
-
end
|
114
|
-
return x
|
115
|
-
end
|
116
|
-
|
117
|
-
def rounds(x)
|
118
|
-
counter = 0
|
119
|
-
for i in 0..x
|
120
|
-
b= test()
|
121
|
-
if (!b) then
|
122
|
-
counter=counter+1
|
123
|
-
end
|
124
|
-
|
125
|
-
end
|
126
|
-
return counter
|
127
|
-
end
|
128
|
-
|
129
|
-
|
130
|
-
def query(q,y)
|
131
|
-
$__rdl_contract_switch.off {
|
132
|
-
if q =~ /^(\w+(#|\.))?(\w+(!|\?|=)?|!|~|\+|\*\*|-|\*|\/|%|<<|>>|&|\||\^|<|<=|=>|>|==|===|!=|=~|!~|<=>|\[\]|\[\]=)$/
|
133
|
-
klass = nil
|
134
|
-
klass_pref = nil
|
135
|
-
meth = nil
|
136
|
-
if q =~ /(.+)#(.+)/
|
137
|
-
klass = $1
|
138
|
-
klass_pref = "#{klass}#"
|
139
|
-
meth = $2.to_sym
|
140
|
-
elsif q =~ /(.+)\.(.+)/
|
141
|
-
klass_pref = "#{$1}."
|
142
|
-
klass = RDL::Util.add_singleton_marker($1)
|
143
|
-
meth = $2.to_sym
|
144
|
-
else
|
145
|
-
klass = self.class.to_s
|
146
|
-
klass_pref = "#{klass}#"
|
147
|
-
meth = q.to_sym
|
148
|
-
end
|
149
|
-
if RDL::Wrap.has_contracts?(klass, meth, :type)
|
150
|
-
typs = RDL::Wrap.get_contracts(klass, meth, :type)
|
151
|
-
typs.each { |t|
|
152
|
-
#puts "#{klass_pref}#{meth}: #{t}"
|
153
|
-
t_string = "#{t}"
|
154
|
-
t_string =~ /\((\w*)\)(.+)/
|
155
|
-
|
156
|
-
#puts y
|
157
|
-
if y.is_a?(Object.const_get($1))
|
158
|
-
return t_string
|
159
|
-
end
|
160
|
-
#return "#{t}"
|
161
|
-
}
|
162
|
-
nil
|
163
|
-
else
|
164
|
-
#puts "No type for #{klass_pref}#{meth}"
|
165
|
-
end
|
166
|
-
else
|
167
|
-
#puts "Not implemented"
|
168
|
-
end
|
169
|
-
}
|
170
|
-
end
|
171
|
-
|