rbs 0.5.0 → 0.6.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/Gemfile +2 -0
- data/Rakefile +2 -3
- data/docs/stdlib.md +0 -2
- data/docs/syntax.md +6 -3
- data/goodcheck.yml +65 -0
- data/lib/rbs.rb +1 -0
- data/lib/rbs/ast/declarations.rb +44 -6
- data/lib/rbs/definition_builder.rb +33 -34
- data/lib/rbs/environment.rb +49 -36
- data/lib/rbs/errors.rb +43 -25
- data/lib/rbs/factory.rb +14 -0
- data/lib/rbs/parser.y +60 -11
- data/lib/rbs/prototype/rb.rb +1 -1
- data/lib/rbs/prototype/rbi.rb +1 -1
- data/lib/rbs/prototype/runtime.rb +1 -1
- data/lib/rbs/test.rb +81 -3
- data/lib/rbs/test/errors.rb +1 -1
- data/lib/rbs/test/hook.rb +133 -259
- data/lib/rbs/test/observer.rb +17 -0
- data/lib/rbs/test/setup.rb +12 -15
- data/lib/rbs/test/spy.rb +0 -321
- data/lib/rbs/test/tester.rb +116 -0
- data/lib/rbs/test/type_check.rb +43 -5
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +2 -2
- data/schema/decls.json +21 -10
- data/stdlib/builtin/proc.rbs +1 -2
- data/stdlib/logger/formatter.rbs +23 -0
- data/stdlib/logger/log_device.rbs +39 -0
- data/stdlib/logger/logger.rbs +507 -0
- data/stdlib/logger/period.rbs +7 -0
- data/stdlib/logger/severity.rbs +8 -0
- metadata +11 -3
- data/lib/rbs/test/test_helper.rb +0 -180
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Soutaro Matsumoto
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: RBS is the language for type signatures for Ruby and standard library
|
14
14
|
definitions.
|
@@ -41,6 +41,7 @@ files:
|
|
41
41
|
- docs/stdlib.md
|
42
42
|
- docs/syntax.md
|
43
43
|
- exe/rbs
|
44
|
+
- goodcheck.yml
|
44
45
|
- lib/rbs.rb
|
45
46
|
- lib/rbs/ast/annotation.rb
|
46
47
|
- lib/rbs/ast/comment.rb
|
@@ -57,6 +58,7 @@ files:
|
|
57
58
|
- lib/rbs/environment_loader.rb
|
58
59
|
- lib/rbs/environment_walker.rb
|
59
60
|
- lib/rbs/errors.rb
|
61
|
+
- lib/rbs/factory.rb
|
60
62
|
- lib/rbs/location.rb
|
61
63
|
- lib/rbs/method_type.rb
|
62
64
|
- lib/rbs/namespace.rb
|
@@ -69,9 +71,10 @@ files:
|
|
69
71
|
- lib/rbs/test.rb
|
70
72
|
- lib/rbs/test/errors.rb
|
71
73
|
- lib/rbs/test/hook.rb
|
74
|
+
- lib/rbs/test/observer.rb
|
72
75
|
- lib/rbs/test/setup.rb
|
73
76
|
- lib/rbs/test/spy.rb
|
74
|
-
- lib/rbs/test/
|
77
|
+
- lib/rbs/test/tester.rb
|
75
78
|
- lib/rbs/test/type_check.rb
|
76
79
|
- lib/rbs/type_name.rb
|
77
80
|
- lib/rbs/type_name_resolver.rb
|
@@ -157,6 +160,11 @@ files:
|
|
157
160
|
- stdlib/find/find.rbs
|
158
161
|
- stdlib/ipaddr/ipaddr.rbs
|
159
162
|
- stdlib/json/json.rbs
|
163
|
+
- stdlib/logger/formatter.rbs
|
164
|
+
- stdlib/logger/log_device.rbs
|
165
|
+
- stdlib/logger/logger.rbs
|
166
|
+
- stdlib/logger/period.rbs
|
167
|
+
- stdlib/logger/severity.rbs
|
160
168
|
- stdlib/mutex_m/mutex_m.rbs
|
161
169
|
- stdlib/pathname/pathname.rbs
|
162
170
|
- stdlib/prime/integer-extension.rbs
|
data/lib/rbs/test/test_helper.rb
DELETED
@@ -1,180 +0,0 @@
|
|
1
|
-
module RBS
|
2
|
-
module Test
|
3
|
-
module TypeAssertions
|
4
|
-
module ClassMethods
|
5
|
-
attr_reader :target
|
6
|
-
|
7
|
-
def library(*libs)
|
8
|
-
@libs = libs
|
9
|
-
@env = nil
|
10
|
-
@target = nil
|
11
|
-
end
|
12
|
-
|
13
|
-
def env
|
14
|
-
@env ||= begin
|
15
|
-
loader = RBS::EnvironmentLoader.new
|
16
|
-
(@libs || []).each do |lib|
|
17
|
-
loader.add library: lib
|
18
|
-
end
|
19
|
-
|
20
|
-
RBS::Environment.from_loader(loader).resolve_type_names
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def builder
|
25
|
-
@builder ||= DefinitionBuilder.new(env: env)
|
26
|
-
end
|
27
|
-
|
28
|
-
def testing(type_or_string)
|
29
|
-
type = case type_or_string
|
30
|
-
when String
|
31
|
-
RBS::Parser.parse_type(type_or_string, variables: [])
|
32
|
-
else
|
33
|
-
type_or_string
|
34
|
-
end
|
35
|
-
|
36
|
-
definition = case type
|
37
|
-
when Types::ClassInstance
|
38
|
-
builder.build_instance(type.name)
|
39
|
-
when Types::ClassSingleton
|
40
|
-
builder.build_singleton(type.name)
|
41
|
-
else
|
42
|
-
raise "Test target should be class instance or class singleton: #{type}"
|
43
|
-
end
|
44
|
-
|
45
|
-
@target = [type, definition]
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.included(base)
|
50
|
-
base.extend ClassMethods
|
51
|
-
end
|
52
|
-
|
53
|
-
def env
|
54
|
-
self.class.env
|
55
|
-
end
|
56
|
-
|
57
|
-
def builder
|
58
|
-
self.class.builder
|
59
|
-
end
|
60
|
-
|
61
|
-
def targets
|
62
|
-
@targets ||= []
|
63
|
-
end
|
64
|
-
|
65
|
-
def target
|
66
|
-
targets.last || self.class.target
|
67
|
-
end
|
68
|
-
|
69
|
-
def testing(type_or_string)
|
70
|
-
type = case type_or_string
|
71
|
-
when String
|
72
|
-
RBS::Parser.parse_type(type_or_string, variables: [])
|
73
|
-
else
|
74
|
-
type_or_string
|
75
|
-
end
|
76
|
-
|
77
|
-
definition = case type
|
78
|
-
when Types::ClassInstance
|
79
|
-
builder.build_instance(type.name)
|
80
|
-
when Types::ClassSingleton
|
81
|
-
builder.build_singleton(type.name)
|
82
|
-
else
|
83
|
-
raise "Test target should be class instance or class singleton: #{type}"
|
84
|
-
end
|
85
|
-
|
86
|
-
targets.push [type, definition]
|
87
|
-
|
88
|
-
if block_given?
|
89
|
-
begin
|
90
|
-
yield
|
91
|
-
ensure
|
92
|
-
targets.pop
|
93
|
-
end
|
94
|
-
else
|
95
|
-
[type, definition]
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
ruby2_keywords def assert_send_type(method_type, receiver, method, *args, &block)
|
100
|
-
trace = []
|
101
|
-
spy = Spy.wrap(receiver, method)
|
102
|
-
spy.callback = -> (result) { trace << result }
|
103
|
-
|
104
|
-
exception = nil
|
105
|
-
|
106
|
-
begin
|
107
|
-
spy.wrapped_object.__send__(method, *args, &block)
|
108
|
-
rescue => exn
|
109
|
-
exception = exn
|
110
|
-
end
|
111
|
-
|
112
|
-
mt = case method_type
|
113
|
-
when String
|
114
|
-
RBS::Parser.parse_method_type(method_type, variables: [])
|
115
|
-
when RBS::MethodType
|
116
|
-
method_type
|
117
|
-
end
|
118
|
-
|
119
|
-
typecheck = TypeCheck.new(self_class: receiver.class, builder: builder)
|
120
|
-
errors = typecheck.method_call(method, mt, trace.last, errors: [])
|
121
|
-
|
122
|
-
assert_empty errors.map {|x| RBS::Test::Errors.to_string(x) }, "Call trace does not match with given method type: #{trace.last.inspect}"
|
123
|
-
|
124
|
-
type, definition = target
|
125
|
-
method_types = case
|
126
|
-
when definition.instance_type?
|
127
|
-
subst = Substitution.build(definition.type_params, type.args)
|
128
|
-
definition.methods[method].method_types.map do |method_type|
|
129
|
-
method_type.sub(subst)
|
130
|
-
end
|
131
|
-
when definition.class_type?
|
132
|
-
definition.methods[method].method_types
|
133
|
-
end
|
134
|
-
|
135
|
-
all_errors = method_types.map {|t| typecheck.method_call(method, t, trace.last, errors: []) }
|
136
|
-
assert all_errors.any? {|es| es.empty? }, "Call trace does not match one of method definitions:\n #{trace.last.inspect}\n #{method_types.join(" | ")}"
|
137
|
-
|
138
|
-
if exception
|
139
|
-
raise exception
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
ruby2_keywords def refute_send_type(method_type, receiver, method, *args, &block)
|
144
|
-
trace = []
|
145
|
-
spy = Spy.wrap(receiver, method)
|
146
|
-
spy.callback = -> (result) { trace << result }
|
147
|
-
|
148
|
-
exception = nil
|
149
|
-
begin
|
150
|
-
spy.wrapped_object.__send__(method, *args, &block)
|
151
|
-
rescue Exception => exn
|
152
|
-
exception = exn
|
153
|
-
end
|
154
|
-
|
155
|
-
mt = case method_type
|
156
|
-
when String
|
157
|
-
RBS::Parser.parse_method_type(method_type, variables: [])
|
158
|
-
when RBS::MethodType
|
159
|
-
method_type
|
160
|
-
end
|
161
|
-
|
162
|
-
mt = mt.update(block: if mt.block
|
163
|
-
MethodType::Block.new(
|
164
|
-
type: mt.block.type.with_return_type(Types::Bases::Any.new(location: nil)),
|
165
|
-
required: mt.block.required
|
166
|
-
)
|
167
|
-
end,
|
168
|
-
type: mt.type.with_return_type(Types::Bases::Any.new(location: nil)))
|
169
|
-
|
170
|
-
typecheck = TypeCheck.new(self_class: receiver.class, builder: builder)
|
171
|
-
errors = typecheck.method_call(method, mt, trace.last, errors: [])
|
172
|
-
|
173
|
-
assert_operator exception, :is_a?, ::Exception
|
174
|
-
assert_empty errors.map {|x| RBS::Test::Errors.to_string(x) }
|
175
|
-
|
176
|
-
exception
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|