rbs 0.4.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +7 -1
- data/.gitignore +1 -1
- data/CHANGELOG.md +35 -0
- data/Gemfile +14 -0
- data/README.md +86 -47
- data/Rakefile +53 -21
- data/bin/rbs-prof +9 -0
- data/bin/run_in_md.rb +49 -0
- data/docs/stdlib.md +0 -2
- data/docs/syntax.md +6 -3
- data/goodcheck.yml +65 -0
- data/lib/rbs.rb +3 -0
- data/lib/rbs/ast/comment.rb +6 -0
- data/lib/rbs/ast/declarations.rb +106 -13
- data/lib/rbs/ast/members.rb +41 -17
- data/lib/rbs/cli.rb +317 -121
- data/lib/rbs/constant.rb +4 -4
- data/lib/rbs/constant_table.rb +51 -45
- data/lib/rbs/definition.rb +175 -59
- data/lib/rbs/definition_builder.rb +814 -604
- data/lib/rbs/environment.rb +352 -210
- data/lib/rbs/environment_walker.rb +14 -23
- data/lib/rbs/errors.rb +184 -3
- data/lib/rbs/factory.rb +14 -0
- data/lib/rbs/location.rb +15 -0
- data/lib/rbs/parser.y +100 -34
- data/lib/rbs/prototype/rb.rb +101 -113
- data/lib/rbs/prototype/rbi.rb +5 -3
- data/lib/rbs/prototype/runtime.rb +11 -7
- data/lib/rbs/substitution.rb +12 -1
- data/lib/rbs/test.rb +82 -3
- data/lib/rbs/test/errors.rb +5 -1
- data/lib/rbs/test/hook.rb +133 -259
- data/lib/rbs/test/observer.rb +17 -0
- data/lib/rbs/test/setup.rb +35 -19
- data/lib/rbs/test/setup_helper.rb +29 -0
- data/lib/rbs/test/spy.rb +0 -321
- data/lib/rbs/test/tester.rb +116 -0
- data/lib/rbs/test/type_check.rb +43 -7
- data/lib/rbs/type_name_resolver.rb +58 -0
- data/lib/rbs/types.rb +94 -2
- data/lib/rbs/validator.rb +55 -0
- data/lib/rbs/variance_calculator.rb +12 -2
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +127 -91
- data/rbs.gemspec +0 -10
- data/schema/decls.json +36 -10
- data/schema/members.json +3 -0
- data/stdlib/benchmark/benchmark.rbs +151 -151
- data/stdlib/builtin/enumerable.rbs +3 -3
- data/stdlib/builtin/file.rbs +0 -3
- data/stdlib/builtin/io.rbs +4 -4
- data/stdlib/builtin/proc.rbs +1 -2
- data/stdlib/builtin/thread.rbs +2 -2
- data/stdlib/csv/csv.rbs +4 -6
- data/stdlib/fiber/fiber.rbs +1 -1
- data/stdlib/json/json.rbs +7 -1
- 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
- data/stdlib/mutex_m/mutex_m.rbs +77 -0
- data/stdlib/pathname/pathname.rbs +6 -6
- data/stdlib/prime/integer-extension.rbs +1 -1
- data/stdlib/prime/prime.rbs +44 -44
- data/stdlib/pty/pty.rbs +159 -0
- data/stdlib/tmpdir/tmpdir.rbs +1 -1
- metadata +19 -130
- data/lib/rbs/test/test_helper.rb +0 -183
data/lib/rbs/test/test_helper.rb
DELETED
@@ -1,183 +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.new.tap do |env|
|
21
|
-
loader.load(env: env)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def builder
|
27
|
-
@builder ||= DefinitionBuilder.new(env: env)
|
28
|
-
end
|
29
|
-
|
30
|
-
def testing(type_or_string)
|
31
|
-
type = case type_or_string
|
32
|
-
when String
|
33
|
-
RBS::Parser.parse_type(type_or_string, variables: [])
|
34
|
-
else
|
35
|
-
type_or_string
|
36
|
-
end
|
37
|
-
|
38
|
-
definition = case type
|
39
|
-
when Types::ClassInstance
|
40
|
-
builder.build_instance(type.name)
|
41
|
-
when Types::ClassSingleton
|
42
|
-
builder.build_singleton(type.name)
|
43
|
-
else
|
44
|
-
raise "Test target should be class instance or class singleton: #{type}"
|
45
|
-
end
|
46
|
-
|
47
|
-
@target = [type, definition]
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def self.included(base)
|
52
|
-
base.extend ClassMethods
|
53
|
-
end
|
54
|
-
|
55
|
-
def env
|
56
|
-
self.class.env
|
57
|
-
end
|
58
|
-
|
59
|
-
def builder
|
60
|
-
self.class.builder
|
61
|
-
end
|
62
|
-
|
63
|
-
def targets
|
64
|
-
@targets ||= []
|
65
|
-
end
|
66
|
-
|
67
|
-
def target
|
68
|
-
targets.last || self.class.target
|
69
|
-
end
|
70
|
-
|
71
|
-
def testing(type_or_string)
|
72
|
-
type = case type_or_string
|
73
|
-
when String
|
74
|
-
RBS::Parser.parse_type(type_or_string, variables: [])
|
75
|
-
else
|
76
|
-
type_or_string
|
77
|
-
end
|
78
|
-
|
79
|
-
definition = case type
|
80
|
-
when Types::ClassInstance
|
81
|
-
builder.build_instance(type.name)
|
82
|
-
when Types::ClassSingleton
|
83
|
-
builder.build_singleton(type.name)
|
84
|
-
else
|
85
|
-
raise "Test target should be class instance or class singleton: #{type}"
|
86
|
-
end
|
87
|
-
|
88
|
-
targets.push [type, definition]
|
89
|
-
|
90
|
-
if block_given?
|
91
|
-
begin
|
92
|
-
yield
|
93
|
-
ensure
|
94
|
-
targets.pop
|
95
|
-
end
|
96
|
-
else
|
97
|
-
[type, definition]
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
ruby2_keywords def assert_send_type(method_type, receiver, method, *args, &block)
|
102
|
-
trace = []
|
103
|
-
spy = Spy.wrap(receiver, method)
|
104
|
-
spy.callback = -> (result) { trace << result }
|
105
|
-
|
106
|
-
exception = nil
|
107
|
-
|
108
|
-
begin
|
109
|
-
spy.wrapped_object.__send__(method, *args, &block)
|
110
|
-
rescue => exn
|
111
|
-
exception = exn
|
112
|
-
end
|
113
|
-
|
114
|
-
mt = case method_type
|
115
|
-
when String
|
116
|
-
RBS::Parser.parse_method_type(method_type, variables: [])
|
117
|
-
when RBS::MethodType
|
118
|
-
method_type
|
119
|
-
end
|
120
|
-
|
121
|
-
typecheck = TypeCheck.new(self_class: receiver.class, builder: builder)
|
122
|
-
errors = typecheck.method_call(method, mt, trace.last, errors: [])
|
123
|
-
|
124
|
-
assert_empty errors.map {|x| RBS::Test::Errors.to_string(x) }, "Call trace does not match with given method type: #{trace.last.inspect}"
|
125
|
-
|
126
|
-
type, definition = target
|
127
|
-
method_types = case
|
128
|
-
when definition.instance_type?
|
129
|
-
subst = Substitution.build(definition.declaration.type_params.each.map(&:name),
|
130
|
-
type.args)
|
131
|
-
definition.methods[method].method_types.map do |method_type|
|
132
|
-
method_type.sub(subst)
|
133
|
-
end
|
134
|
-
when definition.class_type?
|
135
|
-
definition.methods[method].method_types
|
136
|
-
end
|
137
|
-
|
138
|
-
all_errors = method_types.map {|t| typecheck.method_call(method, t, trace.last, errors: []) }
|
139
|
-
assert all_errors.any? {|es| es.empty? }, "Call trace does not match one of method definitions:\n #{trace.last.inspect}\n #{method_types.join(" | ")}"
|
140
|
-
|
141
|
-
if exception
|
142
|
-
raise exception
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
ruby2_keywords def refute_send_type(method_type, receiver, method, *args, &block)
|
147
|
-
trace = []
|
148
|
-
spy = Spy.wrap(receiver, method)
|
149
|
-
spy.callback = -> (result) { trace << result }
|
150
|
-
|
151
|
-
exception = nil
|
152
|
-
begin
|
153
|
-
spy.wrapped_object.__send__(method, *args, &block)
|
154
|
-
rescue Exception => exn
|
155
|
-
exception = exn
|
156
|
-
end
|
157
|
-
|
158
|
-
mt = case method_type
|
159
|
-
when String
|
160
|
-
RBS::Parser.parse_method_type(method_type, variables: [])
|
161
|
-
when RBS::MethodType
|
162
|
-
method_type
|
163
|
-
end
|
164
|
-
|
165
|
-
mt = mt.update(block: if mt.block
|
166
|
-
MethodType::Block.new(
|
167
|
-
type: mt.block.type.with_return_type(Types::Bases::Any.new(location: nil)),
|
168
|
-
required: mt.block.required
|
169
|
-
)
|
170
|
-
end,
|
171
|
-
type: mt.type.with_return_type(Types::Bases::Any.new(location: nil)))
|
172
|
-
|
173
|
-
typecheck = TypeCheck.new(self_class: receiver.class, builder: builder)
|
174
|
-
errors = typecheck.method_call(method, mt, trace.last, errors: [])
|
175
|
-
|
176
|
-
assert_operator exception, :is_a?, ::Exception
|
177
|
-
assert_empty errors.map {|x| RBS::Test::Errors.to_string(x) }
|
178
|
-
|
179
|
-
exception
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|