rdl 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/.travis.yml +7 -6
  4. data/CHANGES.md +29 -0
  5. data/README.md +94 -26
  6. data/lib/rdl/boot.rb +82 -41
  7. data/lib/rdl/boot_rails.rb +5 -0
  8. data/lib/rdl/config.rb +9 -1
  9. data/lib/rdl/query.rb +2 -2
  10. data/lib/rdl/typecheck.rb +972 -225
  11. data/lib/rdl/types/annotated_arg.rb +8 -0
  12. data/lib/rdl/types/ast_node.rb +73 -0
  13. data/lib/rdl/types/bot.rb +8 -0
  14. data/lib/rdl/types/bound_arg.rb +63 -0
  15. data/lib/rdl/types/computed.rb +48 -0
  16. data/lib/rdl/types/dependent_arg.rb +9 -0
  17. data/lib/rdl/types/dynamic.rb +61 -0
  18. data/lib/rdl/types/finite_hash.rb +54 -9
  19. data/lib/rdl/types/generic.rb +33 -0
  20. data/lib/rdl/types/intersection.rb +8 -0
  21. data/lib/rdl/types/lexer.rex +6 -1
  22. data/lib/rdl/types/lexer.rex.rb +13 -1
  23. data/lib/rdl/types/method.rb +14 -0
  24. data/lib/rdl/types/nominal.rb +8 -0
  25. data/lib/rdl/types/non_null.rb +8 -0
  26. data/lib/rdl/types/optional.rb +8 -0
  27. data/lib/rdl/types/parser.racc +31 -5
  28. data/lib/rdl/types/parser.tab.rb +540 -302
  29. data/lib/rdl/types/rdl_types.rb +45 -0
  30. data/lib/rdl/types/singleton.rb +14 -1
  31. data/lib/rdl/types/string.rb +104 -0
  32. data/lib/rdl/types/structural.rb +8 -0
  33. data/lib/rdl/types/top.rb +8 -0
  34. data/lib/rdl/types/tuple.rb +32 -8
  35. data/lib/rdl/types/type.rb +54 -11
  36. data/lib/rdl/types/union.rb +41 -2
  37. data/lib/rdl/types/var.rb +10 -0
  38. data/lib/rdl/types/vararg.rb +8 -0
  39. data/lib/rdl/util.rb +13 -10
  40. data/lib/rdl/wrap.rb +271 -27
  41. data/lib/rdl_disable.rb +16 -2
  42. data/lib/types/active_record.rb +1 -0
  43. data/lib/types/core/array.rb +442 -23
  44. data/lib/types/core/basic_object.rb +3 -3
  45. data/lib/types/core/bigdecimal.rb +5 -0
  46. data/lib/types/core/class.rb +2 -0
  47. data/lib/types/core/dir.rb +3 -3
  48. data/lib/types/core/enumerable.rb +4 -4
  49. data/lib/types/core/enumerator.rb +1 -1
  50. data/lib/types/core/file.rb +4 -4
  51. data/lib/types/core/float.rb +203 -0
  52. data/lib/types/core/hash.rb +390 -15
  53. data/lib/types/core/integer.rb +223 -10
  54. data/lib/types/core/io.rb +2 -2
  55. data/lib/types/core/kernel.rb +8 -5
  56. data/lib/types/core/marshal.rb +3 -0
  57. data/lib/types/core/module.rb +3 -3
  58. data/lib/types/core/numeric.rb +0 -2
  59. data/lib/types/core/object.rb +5 -5
  60. data/lib/types/core/pathname.rb +2 -2
  61. data/lib/types/core/process.rb +1 -3
  62. data/lib/types/core/range.rb +1 -1
  63. data/lib/types/core/regexp.rb +2 -2
  64. data/lib/types/core/set.rb +1 -1
  65. data/lib/types/core/string.rb +408 -16
  66. data/lib/types/core/symbol.rb +3 -3
  67. data/lib/types/core/time.rb +1 -1
  68. data/lib/types/core/uri.rb +13 -13
  69. data/lib/types/rails/_helpers.rb +7 -1
  70. data/lib/types/rails/action_controller/mime_responds.rb +2 -0
  71. data/lib/types/rails/active_record/associations.rb +42 -30
  72. data/lib/types/rails/active_record/comp_types.rb +637 -0
  73. data/lib/types/rails/active_record/finder_methods.rb +1 -1
  74. data/lib/types/rails/active_record/model_schema.rb +28 -16
  75. data/lib/types/rails/active_record/relation.rb +5 -3
  76. data/lib/types/rails/active_record/sql-strings.rb +166 -0
  77. data/lib/types/rails/string.rb +1 -1
  78. data/lib/types/sequel.rb +1 -0
  79. data/lib/types/sequel/comp_types.rb +581 -0
  80. data/rdl.gemspec +5 -4
  81. data/test/test_alias.rb +4 -0
  82. data/test/test_array_types.rb +244 -0
  83. data/test/test_bound_types.rb +80 -0
  84. data/test/test_contract.rb +4 -0
  85. data/test/test_dsl.rb +5 -0
  86. data/test/test_dyn_comptype_checks.rb +206 -0
  87. data/test/test_generic.rb +21 -20
  88. data/test/test_hash_types.rb +322 -0
  89. data/test/test_intersection.rb +1 -0
  90. data/test/test_le.rb +29 -4
  91. data/test/test_member.rb +3 -1
  92. data/test/test_parser.rb +5 -0
  93. data/test/test_query.rb +1 -0
  94. data/test/test_rdl.rb +63 -28
  95. data/test/test_rdl_type.rb +4 -0
  96. data/test/test_string_types.rb +102 -0
  97. data/test/test_type_contract.rb +59 -37
  98. data/test/test_typecheck.rb +480 -75
  99. data/test/test_types.rb +17 -0
  100. data/test/test_wrap.rb +5 -0
  101. metadata +35 -5
  102. data/lib/types/rails/active_record/schema_types.rb +0 -51
@@ -9,6 +9,10 @@ class TestTypes < Minitest::Test
9
9
  class B; end
10
10
  class C; end
11
11
 
12
+ def setup
13
+ RDL.reset
14
+ end
15
+
12
16
  def test_nil_top
13
17
  tnil = NominalType.new :NilClass
14
18
  assert_equal RDL::Globals.types[:nil], tnil
@@ -20,6 +24,14 @@ class TestTypes < Minitest::Test
20
24
  assert (RDL::Globals.types[:nil] != ttop)
21
25
  end
22
26
 
27
+ def test_dyn
28
+ tdyn = DynamicType.new
29
+ tdyn2 = DynamicType.new
30
+ assert_equal tdyn, tdyn2
31
+ assert_equal RDL::Globals.types[:dyn], tdyn
32
+ assert (RDL::Globals.types[:nil] != tdyn)
33
+ end
34
+
23
35
  def test_nominal
24
36
  ta = NominalType.new :A
25
37
  ta2 = NominalType.new :A
@@ -220,4 +232,9 @@ class TestTypes < Minitest::Test
220
232
  assert_equal tmethbssfn, tmethbaabn.instantiate(inst)
221
233
  assert_equal tstructinst, tstructorig.instantiate(inst)
222
234
  end
235
+
236
+ def test_canonical
237
+ t = RDL::Globals.parser.scan_str '#T Array<Integer or Integer>'
238
+ assert_equal 'Array<Integer>', t.canonical.to_s
239
+ end
223
240
  end
@@ -4,6 +4,11 @@ require 'rdl'
4
4
 
5
5
  class TestWrap < Minitest::Test
6
6
  extend RDL::Annotate
7
+
8
+ def setup
9
+ RDL.reset
10
+ end
11
+
7
12
  class C
8
13
  def foo_public(x)
9
14
  foo(x)
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.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeffrey S. Foster
@@ -9,10 +9,11 @@ authors:
9
9
  - T. Stephen Strickland
10
10
  - Alexander T. Yu
11
11
  - Milod Kazerounian
12
+ - Sankha Narayan Guria
12
13
  autorequire:
13
14
  bindir: bin
14
15
  cert_chain: []
15
- date: 2017-06-14 00:00:00.000000000 Z
16
+ date: 2019-06-09 00:00:00.000000000 Z
16
17
  dependencies:
17
18
  - !ruby/object:Gem::Dependency
18
19
  name: parser
@@ -34,6 +35,20 @@ dependencies:
34
35
  - - ">="
35
36
  - !ruby/object:Gem::Version
36
37
  version: 2.3.1.4
38
+ - !ruby/object:Gem::Dependency
39
+ name: sql-parser
40
+ requirement: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - "~>"
43
+ - !ruby/object:Gem::Version
44
+ version: 0.0.2
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - "~>"
50
+ - !ruby/object:Gem::Version
51
+ version: 0.0.2
37
52
  description: |
38
53
  RDL is a gem that adds types and contracts to Ruby. RDL includes extensive
39
54
  support for specifying method types, which can either be enforced as
@@ -68,9 +83,13 @@ files:
68
83
  - lib/rdl/switch.rb
69
84
  - lib/rdl/typecheck.rb
70
85
  - lib/rdl/types/annotated_arg.rb
86
+ - lib/rdl/types/ast_node.rb
71
87
  - lib/rdl/types/bot.rb
88
+ - lib/rdl/types/bound_arg.rb
89
+ - lib/rdl/types/computed.rb
72
90
  - lib/rdl/types/dependent_arg.rb
73
91
  - lib/rdl/types/dots_query.rb
92
+ - lib/rdl/types/dynamic.rb
74
93
  - lib/rdl/types/finite_hash.rb
75
94
  - lib/rdl/types/generic.rb
76
95
  - lib/rdl/types/intersection.rb
@@ -82,7 +101,9 @@ files:
82
101
  - lib/rdl/types/optional.rb
83
102
  - lib/rdl/types/parser.racc
84
103
  - lib/rdl/types/parser.tab.rb
104
+ - lib/rdl/types/rdl_types.rb
85
105
  - lib/rdl/types/singleton.rb
106
+ - lib/rdl/types/string.rb
86
107
  - lib/rdl/types/structural.rb
87
108
  - lib/rdl/types/top.rb
88
109
  - lib/rdl/types/tuple.rb
@@ -96,6 +117,7 @@ files:
96
117
  - lib/rdl/util.rb
97
118
  - lib/rdl/wrap.rb
98
119
  - lib/rdl_disable.rb
120
+ - lib/types/active_record.rb
99
121
  - lib/types/core.rb
100
122
  - lib/types/core/_aliases.rb
101
123
  - lib/types/core/abbrev.rb
@@ -168,11 +190,12 @@ files:
168
190
  - lib/types/rails/active_model/validations.rb
169
191
  - lib/types/rails/active_record/associations.rb
170
192
  - lib/types/rails/active_record/base.rb
193
+ - lib/types/rails/active_record/comp_types.rb
171
194
  - lib/types/rails/active_record/core.rb
172
195
  - lib/types/rails/active_record/finder_methods.rb
173
196
  - lib/types/rails/active_record/model_schema.rb
174
197
  - lib/types/rails/active_record/relation.rb
175
- - lib/types/rails/active_record/schema_types.rb
198
+ - lib/types/rails/active_record/sql-strings.rb
176
199
  - lib/types/rails/active_record/validations.rb
177
200
  - lib/types/rails/active_support/base.rb
178
201
  - lib/types/rails/active_support/logger.rb
@@ -184,13 +207,19 @@ files:
184
207
  - lib/types/rails/rack/request.rb
185
208
  - lib/types/rails/string.rb
186
209
  - lib/types/rails/time.rb
210
+ - lib/types/sequel.rb
211
+ - lib/types/sequel/comp_types.rb
187
212
  - rdl.gemspec
188
213
  - test/disabled_test_coverage.rb
189
214
  - test/disabled_test_rdoc.rb
190
215
  - test/test_alias.rb
216
+ - test/test_array_types.rb
217
+ - test/test_bound_types.rb
191
218
  - test/test_contract.rb
192
219
  - test/test_dsl.rb
220
+ - test/test_dyn_comptype_checks.rb
193
221
  - test/test_generic.rb
222
+ - test/test_hash_types.rb
194
223
  - test/test_intersection.rb
195
224
  - test/test_le.rb
196
225
  - test/test_lib_types.rb
@@ -199,11 +228,12 @@ files:
199
228
  - test/test_query.rb
200
229
  - test/test_rdl.rb
201
230
  - test/test_rdl_type.rb
231
+ - test/test_string_types.rb
202
232
  - test/test_type_contract.rb
203
233
  - test/test_typecheck.rb
204
234
  - test/test_types.rb
205
235
  - test/test_wrap.rb
206
- homepage: https://github.com/plum-umd/rdl
236
+ homepage: https://github.com/tupl-tufts/rdl
207
237
  licenses:
208
238
  - BSD-3-Clause
209
239
  metadata: {}
@@ -223,7 +253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
253
  version: '0'
224
254
  requirements: []
225
255
  rubyforge_project:
226
- rubygems_version: 2.6.12
256
+ rubygems_version: 2.7.8
227
257
  signing_key:
228
258
  specification_version: 4
229
259
  summary: Ruby type and contract system
@@ -1,51 +0,0 @@
1
- class ActiveRecord::Base
2
- extend RDL::RDLAnnotate
3
-
4
- def self.add_schema_types
5
- end
6
-
7
- rdl_post('self.add_schema_types') { |ret| # load_schema! doesn't return anything interesting
8
- type 'self.where', "(*%any) -> ActiveRecord::Relation<#{self}>"
9
-
10
- columns_hash.each { |name, col|
11
- t = RDL::Rails.column_to_rdl(col.type)
12
- if col.null
13
- # may be null; show nullability in return type
14
- rdl_type name, "() -> #{t} or nil" # getter
15
- rdl_type "#{name}_id", "() -> #{t} or nil" # getter
16
- rdl_type "#{name}=", "(#{t}) -> #{t} or nil" # setter
17
- rdl_type "write_attribute", "(:#{name}, #{t}) -> %bool"
18
- rdl_type "update_attribute", "(:#{name}, #{t}) -> %bool"
19
- rdl_type "update_column", "(:#{name}, #{t}) -> %bool"
20
- else
21
- # not null; can't truly check in type system but hint via the name
22
- rdl_type name, "() -> !#{t}" # getter
23
- rdl_type "#{name}_id", "() -> !#{t}" # getter
24
- rdl_type "#{name}=", "(!#{t}) -> !#{t}" # setter
25
- rdl_type "write_attribute", "(:#{name}, !#{t}) -> %bool"
26
- rdl_type "update_attribute", "(:#{name}, #{t}) -> %bool"
27
- rdl_type "update_column", "(:#{name}, #{t}) -> %bool"
28
- end
29
- }
30
-
31
- attribute_types = RDL::Rails.attribute_types(self)
32
-
33
- rdl_type 'self.find', "(Fixnum) -> #{self}"
34
- rdl_type 'self.find', "(String) -> #{self}"
35
- rdl_type 'self.find', '({' + attribute_types + "}) -> #{self}"
36
-
37
- =begin
38
- type 'self.find_by', '(' + attribute_types + ") -> #{self} or nil"
39
- type 'self.find_by!', '(' + attribute_types + ") -> #{self}"
40
- type 'update', '(' + attribute_types + ') -> %bool'
41
- type 'update_columns', '(' + attribute_types + ') -> %bool'
42
- type 'attributes=', '(' + attribute_types + ') -> %bool'
43
-
44
- # If called with String arguments, can't check types as precisely
45
- type 'write_attribute', '(String, %any) -> %bool'
46
- type 'update_attribute', '(String, %any) -> %bool'
47
- type 'update_column', '(String, %any) -> %bool'
48
- =end
49
- true
50
- }
51
- end