rdl 1.0.0 → 1.0.1.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/README.md +75 -12
- data/bin/rdl_query +24 -0
- data/lib/rdl.rb +2 -1
- data/lib/rdl/query.rb +96 -0
- data/lib/rdl/types/annotated_arg.rb +4 -1
- data/lib/rdl/types/dots_query.rb +26 -0
- data/lib/rdl/types/finitehash.rb +11 -3
- data/lib/rdl/types/generic.rb +8 -2
- data/lib/rdl/types/intersection.rb +10 -3
- data/lib/rdl/types/lexer.rex +4 -1
- data/lib/rdl/types/lexer.rex.rb +11 -2
- data/lib/rdl/types/method.rb +41 -4
- data/lib/rdl/types/nil.rb +8 -2
- data/lib/rdl/types/nominal.rb +8 -2
- data/lib/rdl/types/optional.rb +9 -3
- data/lib/rdl/types/parser.racc +10 -6
- data/lib/rdl/types/parser.tab.rb +305 -257
- data/lib/rdl/types/singleton.rb +10 -3
- data/lib/rdl/types/structural.rb +9 -2
- data/lib/rdl/types/top.rb +9 -3
- data/lib/rdl/types/tuple.rb +9 -3
- data/lib/rdl/types/type_query.rb +5 -0
- data/lib/rdl/types/union.rb +11 -4
- data/lib/rdl/types/var.rb +6 -0
- data/lib/rdl/types/vararg.rb +8 -2
- data/lib/rdl/types/wild_query.rb +28 -0
- data/lib/rdl/util.rb +18 -5
- data/lib/rdl/wrap.rb +3 -37
- data/rdl.gemspec +3 -2
- data/test/test_parser.rb +24 -24
- data/test/test_query.rb +108 -0
- data/test/test_rdl.rb +4 -4
- data/types/ruby-2.x/file.rb +3 -1
- data/types/ruby-2.x/fileutils.rb +2 -2
- metadata +13 -6
data/test/test_query.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require_relative '../lib/rdl.rb'
|
3
|
+
|
4
|
+
class TestQuery < Minitest::Test
|
5
|
+
include RDL::Type
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@p = Parser.new
|
9
|
+
@tfixnum = NominalType.new Fixnum
|
10
|
+
@tarray = NominalType.new Array
|
11
|
+
@qwild = WildQuery.new
|
12
|
+
@qwildopt = OptionalType.new @qwild
|
13
|
+
@qwildvararg = VarargType.new @qwild
|
14
|
+
@qwildx = AnnotatedArgType.new("x", @qwild)
|
15
|
+
@qdots = DotsQuery.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_parse
|
19
|
+
q1 = @p.scan_str "#Q (.) -> ."
|
20
|
+
assert_equal (MethodType.new [@qwild], nil, @qwild), q1
|
21
|
+
q2 = @p.scan_str "#Q (., Fixnum) -> Fixnum"
|
22
|
+
assert_equal (MethodType.new [@qwild, @tfixnum], nil, @tfixnum), q2
|
23
|
+
q3 = @p.scan_str "#Q (Fixnum, ?.) -> Fixnum"
|
24
|
+
assert_equal (MethodType.new [@tfixnum, @qwildopt], nil, @tfixnum), q3
|
25
|
+
q4 = @p.scan_str "#Q (*.) -> Fixnum"
|
26
|
+
assert_equal (MethodType.new [@qwildvararg], nil, @tfixnum), q4
|
27
|
+
q5 = @p.scan_str "#Q (. or Fixnum) -> Fixnum"
|
28
|
+
assert_equal (MethodType.new [UnionType.new(@qwild, @tfixnum)], nil, @tfixnum), q5
|
29
|
+
q6 = @p.scan_str "#Q (. x, Fixnum) -> Fixnum"
|
30
|
+
assert_equal (MethodType.new [@qwildx, @tfixnum], nil, @tfixnum), q6
|
31
|
+
q7 = @p.scan_str "#Q (Array<.>) -> Fixnum"
|
32
|
+
assert_equal (MethodType.new [GenericType.new(@tarray, @qwild)], nil, @tfixnum), q7
|
33
|
+
# q8 = @p.scan_str "#Q (.<Fixnum>) -> Fixnum"
|
34
|
+
# assert_equal (MethodType.new [GenericType.new(@twild, @tfixnum)], nil, @tfixnum), q8
|
35
|
+
q9 = @p.scan_str "#Q ([Fixnum, .]) -> Fixnum"
|
36
|
+
assert_equal (MethodType.new [TupleType.new(@tfixnum, @qwild)], nil, @tfixnum), q9
|
37
|
+
q10 = @p.scan_str "#Q ([to_str: () -> .]) -> Fixnum"
|
38
|
+
assert_equal (MethodType.new [StructuralType.new(to_str: (MethodType.new [], nil, @qwild))], nil, @tfixnum), q10
|
39
|
+
q11 = @p.scan_str "#Q ({a: Fixnum, b: .}) -> Fixnum"
|
40
|
+
assert_equal (MethodType.new [FiniteHashType.new({a: @tfixnum, b: @qwild})], nil, @tfixnum), q11
|
41
|
+
q12 = @p.scan_str "#Q (Fixnum, x: .) -> Fixnum"
|
42
|
+
assert_equal (MethodType.new [@tfixnum, FiniteHashType.new(x: @qwild)], nil, @tfixnum), q12
|
43
|
+
q13 = @p.scan_str "#Q (Fixnum, ..., Fixnum) -> Fixnum"
|
44
|
+
assert_equal (MethodType.new [@tfixnum, @qdots, @tfixnum], nil, @tfixnum), q13
|
45
|
+
q14 = @p.scan_str "#Q (Fixnum, ...) -> Fixnum"
|
46
|
+
assert_equal (MethodType.new [@tfixnum, @qdots], nil, @tfixnum), q14
|
47
|
+
q15 = @p.scan_str "#Q (...) -> Fixnum"
|
48
|
+
assert_equal (MethodType.new [@qdots], nil, @tfixnum), q15
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_match
|
52
|
+
t1 = @p.scan_str "(Fixnum, Fixnum) -> Fixnum"
|
53
|
+
assert (@p.scan_str "#Q (Fixnum, Fixnum) -> Fixnum").match(t1)
|
54
|
+
assert (@p.scan_str "#Q (., .) -> .").match(t1)
|
55
|
+
assert (@p.scan_str "#Q (..., Fixnum) -> Fixnum").match(t1)
|
56
|
+
assert (@p.scan_str "#Q (Fixnum, ...) -> Fixnum").match(t1)
|
57
|
+
assert (@p.scan_str "#Q (...) -> Fixnum").match(t1)
|
58
|
+
assert (not (@p.scan_str "#Q (Fixnum, String) -> Fixnum").match(t1))
|
59
|
+
assert (not (@p.scan_str "#Q (String, Fixnum) -> Fixnum").match(t1))
|
60
|
+
assert (not (@p.scan_str "#Q (Fixnum, String) -> String").match(t1))
|
61
|
+
assert (not (@p.scan_str "#Q (..., String) -> String").match(t1))
|
62
|
+
assert (not (@p.scan_str "#Q (String, ...) -> String").match(t1))
|
63
|
+
t2 = @p.scan_str "(String or Fixnum) -> Fixnum"
|
64
|
+
assert (@p.scan_str "#Q (String or Fixnum) -> Fixnum").match(t2)
|
65
|
+
assert (@p.scan_str "#Q (String or .) -> Fixnum").match(t2)
|
66
|
+
assert (@p.scan_str "#Q (. or Fixnum) -> Fixnum").match(t2)
|
67
|
+
assert (@p.scan_str "#Q (Fixnum or String) -> Fixnum").match(t2)
|
68
|
+
assert (@p.scan_str "#Q (Fixnum or .) -> Fixnum").match(t2)
|
69
|
+
assert (@p.scan_str "#Q (. or String) -> Fixnum").match(t2)
|
70
|
+
t3 = @p.scan_str "(Array<Fixnum>) -> Fixnum"
|
71
|
+
assert (@p.scan_str "#Q (Array<Fixnum>) -> Fixnum").match(t3)
|
72
|
+
assert (@p.scan_str "#Q (Array<.>) -> Fixnum").match(t3)
|
73
|
+
t4 = @p.scan_str "([Fixnum, String]) -> Fixnum"
|
74
|
+
assert (@p.scan_str "#Q ([Fixnum, String]) -> Fixnum").match(t4)
|
75
|
+
assert (@p.scan_str "#Q ([Fixnum, .]) -> Fixnum").match(t4)
|
76
|
+
assert (@p.scan_str "#Q ([., String]) -> Fixnum").match(t4)
|
77
|
+
t5 = @p.scan_str "([to_str: () -> Fixnum]) -> Fixnum"
|
78
|
+
assert (@p.scan_str "#Q ([to_str: () -> Fixnum]) -> Fixnum").match(t5)
|
79
|
+
assert (@p.scan_str "#Q ([to_str: () -> .]) -> Fixnum").match(t5)
|
80
|
+
t6 = @p.scan_str "(Fixnum, ?Fixnum) -> Fixnum"
|
81
|
+
assert (@p.scan_str "#Q (Fixnum, ?Fixnum) -> Fixnum").match(t6)
|
82
|
+
assert (@p.scan_str "#Q (Fixnum, ?.) -> Fixnum").match(t6)
|
83
|
+
assert (@p.scan_str "#Q (Fixnum, .) -> Fixnum").match(t6)
|
84
|
+
t7 = @p.scan_str "(*Fixnum) -> Fixnum"
|
85
|
+
assert (@p.scan_str "#Q (*Fixnum) -> Fixnum").match(t7)
|
86
|
+
assert (@p.scan_str "#Q (*.) -> Fixnum").match(t7)
|
87
|
+
assert (@p.scan_str "#Q (.) -> Fixnum").match(t7)
|
88
|
+
t8 = @p.scan_str "({a: Fixnum, b: String}) -> Fixnum"
|
89
|
+
assert (@p.scan_str "#Q ({a: Fixnum, b: String}) -> Fixnum").match(t8)
|
90
|
+
assert (@p.scan_str "#Q ({a: Fixnum, b: .}) -> Fixnum").match(t8)
|
91
|
+
assert (@p.scan_str "#Q ({a: ., b: String}) -> Fixnum").match(t8)
|
92
|
+
assert (@p.scan_str "#Q ({a: ., b: .}) -> Fixnum").match(t8)
|
93
|
+
assert (@p.scan_str "#Q ({b: String, a: Fixnum}) -> Fixnum").match(t8)
|
94
|
+
assert (@p.scan_str "#Q ({b: ., a: Fixnum}) -> Fixnum").match(t8)
|
95
|
+
assert (@p.scan_str "#Q ({b: String, a: .}) -> Fixnum").match(t8)
|
96
|
+
assert (@p.scan_str "#Q ({b: ., a: .}) -> Fixnum").match(t8)
|
97
|
+
assert (@p.scan_str "#Q (.) -> Fixnum").match(t8)
|
98
|
+
t9 = @p.scan_str "(Fixnum, x: String) -> Fixnum"
|
99
|
+
assert (@p.scan_str "#Q (Fixnum, x: String) -> Fixnum").match(t9)
|
100
|
+
assert (@p.scan_str "#Q (Fixnum, x: .) -> Fixnum").match(t9)
|
101
|
+
assert (@p.scan_str "#Q (Fixnum, .) -> Fixnum").match(t9)
|
102
|
+
t10 = @p.scan_str "(String x, Fixnum) -> Fixnum"
|
103
|
+
assert (@p.scan_str "#Q (String x, Fixnum) -> Fixnum").match(t10)
|
104
|
+
assert (@p.scan_str "#Q (. x, Fixnum) -> Fixnum").match(t10)
|
105
|
+
assert (@p.scan_str "#Q (String, Fixnum) -> Fixnum").match(t10)
|
106
|
+
assert (@p.scan_str "#Q (., Fixnum) -> Fixnum").match(t10)
|
107
|
+
end
|
108
|
+
end
|
data/test/test_rdl.rb
CHANGED
@@ -31,7 +31,7 @@ class TestRDL < Minitest::Test
|
|
31
31
|
ppos = RDL::Contract::FlatContract.new("Positive") { |x| x > 0 }
|
32
32
|
assert_equal ["TestRDL", :m1, ppos], RDL::Wrap.process_pre_post_args(self.class, "C", TestRDL, :m1, ppos)
|
33
33
|
assert_equal ["TestRDL", :m1, ppos], RDL::Wrap.process_pre_post_args(self.class, "C", TestRDL, "m1", ppos)
|
34
|
-
assert_equal ["
|
34
|
+
assert_equal ["#{RDL::Util::SINGLETON_MARKER}TestRDL", :m1, ppos], RDL::Wrap.process_pre_post_args(self.class, "C", TestRDL, "self.m1", ppos)
|
35
35
|
assert_equal ["TestRDL", :m1, ppos], RDL::Wrap.process_pre_post_args(self.class, "C", :m1, ppos)
|
36
36
|
assert_equal ["TestRDL", nil, ppos], RDL::Wrap.process_pre_post_args(self.class, "C", ppos)
|
37
37
|
klass1, meth1, c1 = RDL::Wrap.process_pre_post_args(self.class, "C", TestRDL, :m1) { |x| x > 0 }
|
@@ -45,7 +45,7 @@ class TestRDL < Minitest::Test
|
|
45
45
|
klass3, meth3, c3 = RDL::Wrap.process_pre_post_args(self.class, "C") { |x| x > 0 }
|
46
46
|
assert_equal ["TestRDL", nil], [klass3, meth3]
|
47
47
|
assert (c3.is_a? RDL::Contract::FlatContract)
|
48
|
-
|
48
|
+
|
49
49
|
assert_raises(ArgumentError) { RDL::Wrap.process_pre_post_args(self.class, "C") }
|
50
50
|
assert_raises(ArgumentError) { RDL::Wrap.process_pre_post_args(self.class, "C", 42) }
|
51
51
|
assert_raises(ArgumentError) { RDL::Wrap.process_pre_post_args(self.class, "C", 42) { |x| x > 0} }
|
@@ -297,5 +297,5 @@ RUBY
|
|
297
297
|
}
|
298
298
|
assert_equal 3, m23(3)
|
299
299
|
end
|
300
|
-
|
301
|
-
end
|
300
|
+
|
301
|
+
end
|
data/types/ruby-2.x/file.rb
CHANGED
@@ -77,6 +77,8 @@ class File
|
|
77
77
|
type :truncate, '(Fixnum) -> 0'
|
78
78
|
|
79
79
|
class Stat
|
80
|
+
rdl_nowrap
|
81
|
+
|
80
82
|
type 'self.new', '(String file) -> File::Stat'
|
81
83
|
type :<=>, '(File::Stat other) -> -1 or 0 or 1 or nil'
|
82
84
|
type :atime, '() -> Time'
|
@@ -89,7 +91,7 @@ class File
|
|
89
91
|
type :dev, '() -> Fixnum'
|
90
92
|
type :dev_major, '() -> Fixnum'
|
91
93
|
type :dev_minor, '() -> Fixnum'
|
92
|
-
type :directory?, '(
|
94
|
+
type :directory?, '() -> %bool'
|
93
95
|
type :executable?, '() -> %bool'
|
94
96
|
type :executable_real?, '() -> %bool'
|
95
97
|
type :file?, '() -> %bool'
|
data/types/ruby-2.x/fileutils.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module FileUtils
|
2
2
|
rdl_nowrap
|
3
3
|
|
4
|
-
type
|
5
|
-
type
|
4
|
+
type 'self.cp_r', '(String or Pathname, String or Pathname, ?Hash<:preserve or :noop or :verbose or :dereference_root or :remove_destination, %bool>) -> Array<String>'
|
5
|
+
type 'self.mkdir_p', '(String or Pathname, ?Hash<:mode or :noop or :verbose, %bool>) -> Array<String>'
|
6
6
|
end
|
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: 1.0.
|
4
|
+
version: 1.0.1.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeffrey S. Foster
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2016-01-01 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: require_all
|
@@ -41,7 +41,8 @@ description: |
|
|
41
41
|
when the method is called and when it returns, respectively.
|
42
42
|
email:
|
43
43
|
- rdl-users@googlegroups.com
|
44
|
-
executables:
|
44
|
+
executables:
|
45
|
+
- rdl_query
|
45
46
|
extensions: []
|
46
47
|
extra_rdoc_files: []
|
47
48
|
files:
|
@@ -50,6 +51,7 @@ files:
|
|
50
51
|
- LICENSE
|
51
52
|
- README.md
|
52
53
|
- Rakefile
|
54
|
+
- bin/rdl_query
|
53
55
|
- gemfiles/Gemfile.travis
|
54
56
|
- lib/rails_types.rb
|
55
57
|
- lib/rdl.rb
|
@@ -59,8 +61,10 @@ files:
|
|
59
61
|
- lib/rdl/contracts/flat.rb
|
60
62
|
- lib/rdl/contracts/or.rb
|
61
63
|
- lib/rdl/contracts/proc.rb
|
64
|
+
- lib/rdl/query.rb
|
62
65
|
- lib/rdl/switch.rb
|
63
66
|
- lib/rdl/types/annotated_arg.rb
|
67
|
+
- lib/rdl/types/dots_query.rb
|
64
68
|
- lib/rdl/types/finitehash.rb
|
65
69
|
- lib/rdl/types/generic.rb
|
66
70
|
- lib/rdl/types/intersection.rb
|
@@ -78,9 +82,11 @@ files:
|
|
78
82
|
- lib/rdl/types/tuple.rb
|
79
83
|
- lib/rdl/types/type.rb
|
80
84
|
- lib/rdl/types/type_inferencer.rb
|
85
|
+
- lib/rdl/types/type_query.rb
|
81
86
|
- lib/rdl/types/union.rb
|
82
87
|
- lib/rdl/types/var.rb
|
83
88
|
- lib/rdl/types/vararg.rb
|
89
|
+
- lib/rdl/types/wild_query.rb
|
84
90
|
- lib/rdl/util.rb
|
85
91
|
- lib/rdl/wrap.rb
|
86
92
|
- lib/rdl_types.rb
|
@@ -96,6 +102,7 @@ files:
|
|
96
102
|
- test/test_lib_types.rb
|
97
103
|
- test/test_member.rb
|
98
104
|
- test/test_parser.rb
|
105
|
+
- test/test_query.rb
|
99
106
|
- test/test_rdl.rb
|
100
107
|
- test/test_rdl_type.rb
|
101
108
|
- test/test_type_contract.rb
|
@@ -166,12 +173,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
166
173
|
version: '0'
|
167
174
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
175
|
requirements:
|
169
|
-
- - "
|
176
|
+
- - ">"
|
170
177
|
- !ruby/object:Gem::Version
|
171
|
-
version:
|
178
|
+
version: 1.3.1
|
172
179
|
requirements: []
|
173
180
|
rubyforge_project:
|
174
|
-
rubygems_version: 2.
|
181
|
+
rubygems_version: 2.5.1
|
175
182
|
signing_key:
|
176
183
|
specification_version: 4
|
177
184
|
summary: Ruby type and contract system
|