rbs 0.2.0 → 0.6.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/COPYING +1 -1
- data/Gemfile +16 -2
- data/README.md +87 -48
- data/Rakefile +54 -22
- data/bin/rbs-prof +9 -0
- data/bin/run_in_md.rb +49 -0
- data/bin/test_runner.rb +0 -2
- data/docs/sigs.md +6 -6
- data/docs/stdlib.md +3 -5
- data/docs/syntax.md +6 -3
- data/goodcheck.yml +65 -0
- data/lib/rbs.rb +3 -0
- data/lib/rbs/ast/declarations.rb +115 -14
- data/lib/rbs/ast/members.rb +41 -17
- data/lib/rbs/cli.rb +301 -123
- data/lib/rbs/constant.rb +4 -4
- data/lib/rbs/constant_table.rb +64 -53
- data/lib/rbs/definition.rb +175 -59
- data/lib/rbs/definition_builder.rb +646 -603
- data/lib/rbs/environment.rb +352 -210
- data/lib/rbs/environment_walker.rb +14 -23
- data/lib/rbs/errors.rb +159 -3
- data/lib/rbs/factory.rb +14 -0
- data/lib/rbs/namespace.rb +18 -0
- data/lib/rbs/parser.y +75 -21
- data/lib/rbs/prototype/rb.rb +119 -117
- data/lib/rbs/prototype/rbi.rb +5 -3
- data/lib/rbs/prototype/runtime.rb +34 -7
- data/lib/rbs/substitution.rb +8 -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 +13 -14
- data/lib/rbs/test/spy.rb +0 -321
- data/lib/rbs/test/tester.rb +116 -0
- data/lib/rbs/test/type_check.rb +44 -7
- data/lib/rbs/type_name_resolver.rb +58 -0
- data/lib/rbs/types.rb +94 -2
- data/lib/rbs/validator.rb +51 -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 -9
- data/schema/annotation.json +14 -0
- data/schema/comment.json +26 -0
- data/schema/decls.json +353 -0
- data/schema/function.json +87 -0
- data/schema/location.json +56 -0
- data/schema/members.json +248 -0
- data/schema/methodType.json +44 -0
- data/schema/types.json +299 -0
- data/stdlib/benchmark/benchmark.rbs +151 -151
- data/stdlib/builtin/encoding.rbs +2 -0
- data/stdlib/builtin/enumerable.rbs +2 -2
- data/stdlib/builtin/enumerator.rbs +3 -1
- data/stdlib/builtin/fiber.rbs +5 -1
- data/stdlib/builtin/file.rbs +0 -3
- data/stdlib/builtin/io.rbs +4 -4
- data/stdlib/builtin/proc.rbs +1 -2
- data/stdlib/builtin/symbol.rbs +1 -1
- data/stdlib/builtin/thread.rbs +2 -2
- data/stdlib/csv/csv.rbs +4 -6
- data/stdlib/fiber/fiber.rbs +117 -0
- data/stdlib/json/json.rbs +1 -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/tmpdir/tmpdir.rbs +1 -1
- metadata +26 -116
- data/lib/rbs/test/test_helper.rb +0 -183
@@ -0,0 +1,77 @@
|
|
1
|
+
# # mutex_m.rb
|
2
|
+
#
|
3
|
+
# When 'mutex_m' is required, any object that extends or includes Mutex_m will
|
4
|
+
# be treated like a Mutex.
|
5
|
+
#
|
6
|
+
# Start by requiring the standard library Mutex_m:
|
7
|
+
#
|
8
|
+
# require "mutex_m.rb"
|
9
|
+
#
|
10
|
+
# From here you can extend an object with Mutex instance methods:
|
11
|
+
#
|
12
|
+
# obj = Object.new
|
13
|
+
# obj.extend Mutex_m
|
14
|
+
#
|
15
|
+
# Or mixin Mutex_m into your module to your class inherit Mutex instance methods
|
16
|
+
# --- remember to call super() in your class initialize method.
|
17
|
+
#
|
18
|
+
# class Foo
|
19
|
+
# include Mutex_m
|
20
|
+
# def initialize
|
21
|
+
# # ...
|
22
|
+
# super()
|
23
|
+
# end
|
24
|
+
# # ...
|
25
|
+
# end
|
26
|
+
# obj = Foo.new
|
27
|
+
# # this obj can be handled like Mutex
|
28
|
+
#
|
29
|
+
module Mutex_m
|
30
|
+
def self.append_features: (Module cl) -> untyped
|
31
|
+
|
32
|
+
def self.define_aliases: (Module cl) -> untyped
|
33
|
+
|
34
|
+
def self.extend_object: (Object obj) -> untyped
|
35
|
+
|
36
|
+
public
|
37
|
+
|
38
|
+
def mu_extended: () -> untyped
|
39
|
+
|
40
|
+
# See Mutex#lock
|
41
|
+
#
|
42
|
+
def mu_lock: () -> Thread::Mutex
|
43
|
+
|
44
|
+
# See Mutex#locked?
|
45
|
+
#
|
46
|
+
def mu_locked?: () -> bool
|
47
|
+
|
48
|
+
# See Mutex#synchronize
|
49
|
+
#
|
50
|
+
def mu_synchronize: [T] () { () -> T } -> T
|
51
|
+
|
52
|
+
# See Mutex#try_lock
|
53
|
+
#
|
54
|
+
def mu_try_lock: () -> bool
|
55
|
+
|
56
|
+
# See Mutex#unlock
|
57
|
+
#
|
58
|
+
def mu_unlock: () -> Thread::Mutex
|
59
|
+
|
60
|
+
# See Mutex#sleep
|
61
|
+
#
|
62
|
+
def sleep: (?Numeric timeout) -> Integer
|
63
|
+
|
64
|
+
alias locked? mu_locked?
|
65
|
+
alias lock mu_lock
|
66
|
+
alias unlock mu_unlock
|
67
|
+
alias try_lock mu_try_lock
|
68
|
+
alias synchronize mu_synchronize
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def initialize: (*untyped args) -> untyped
|
73
|
+
|
74
|
+
def mu_initialize: () -> untyped
|
75
|
+
end
|
76
|
+
|
77
|
+
Mutex_m::VERSION: String
|
@@ -1066,17 +1066,17 @@ class Pathname
|
|
1066
1066
|
def prepend_prefix: (untyped prefix, untyped relpath) -> untyped
|
1067
1067
|
|
1068
1068
|
def split_names: (untyped path) -> untyped
|
1069
|
-
end
|
1070
1069
|
|
1071
|
-
|
1070
|
+
SAME_PATHS: Proc
|
1072
1071
|
|
1073
|
-
|
1072
|
+
SEPARATOR_LIST: String
|
1074
1073
|
|
1075
|
-
|
1074
|
+
SEPARATOR_PAT: Regexp
|
1076
1075
|
|
1077
|
-
|
1076
|
+
TO_PATH: Symbol
|
1077
|
+
end
|
1078
1078
|
|
1079
|
-
|
1079
|
+
module Kernel
|
1080
1080
|
# Creates a new Pathname object from the given string, `path`, and returns
|
1081
1081
|
# pathname object.
|
1082
1082
|
#
|
data/stdlib/prime/prime.rbs
CHANGED
@@ -129,60 +129,60 @@ class Prime
|
|
129
129
|
# Returns the singleton instance.
|
130
130
|
#
|
131
131
|
def self.instance: () -> Prime
|
132
|
-
end
|
133
132
|
|
134
|
-
# An abstract class for enumerating pseudo-prime numbers.
|
135
|
-
#
|
136
|
-
# Concrete subclasses should override succ, next, rewind.
|
137
|
-
#
|
138
|
-
class
|
139
|
-
|
133
|
+
# An abstract class for enumerating pseudo-prime numbers.
|
134
|
+
#
|
135
|
+
# Concrete subclasses should override succ, next, rewind.
|
136
|
+
#
|
137
|
+
class PseudoPrimeGenerator
|
138
|
+
def initialize: (?Integer?) -> void
|
140
139
|
|
141
|
-
|
140
|
+
include Enumerable[Integer, void]
|
142
141
|
|
143
|
-
|
142
|
+
attr_accessor upper_bound (): Integer?
|
144
143
|
|
145
|
-
|
146
|
-
|
147
|
-
|
144
|
+
# Iterates the given block for each prime number.
|
145
|
+
#
|
146
|
+
def each: () { (Integer) -> void } -> void
|
148
147
|
|
149
|
-
|
150
|
-
|
151
|
-
|
148
|
+
# alias of `succ`.
|
149
|
+
#
|
150
|
+
def next: () -> Integer
|
152
151
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
152
|
+
# Rewinds the internal position for enumeration.
|
153
|
+
#
|
154
|
+
# See `Enumerator`#rewind.
|
155
|
+
#
|
156
|
+
def rewind: () -> void
|
158
157
|
|
159
|
-
|
158
|
+
def size: () -> Float
|
160
159
|
|
161
|
-
|
160
|
+
# returns the next pseudo-prime number, and move the internal position forward.
|
161
|
+
#
|
162
|
+
# `PseudoPrimeGenerator`#succ raises `NotImplementedError`.
|
163
|
+
#
|
164
|
+
def succ: () -> Integer
|
165
|
+
end
|
166
|
+
|
167
|
+
# An implementation of `PseudoPrimeGenerator`.
|
162
168
|
#
|
163
|
-
#
|
169
|
+
# Uses `EratosthenesSieve`.
|
164
170
|
#
|
165
|
-
|
166
|
-
end
|
167
|
-
|
168
|
-
# An implementation of `PseudoPrimeGenerator`.
|
169
|
-
#
|
170
|
-
# Uses `EratosthenesSieve`.
|
171
|
-
#
|
172
|
-
class Prime::EratosthenesGenerator < PseudoPrimeGenerator
|
173
|
-
end
|
171
|
+
class EratosthenesGenerator < PseudoPrimeGenerator
|
172
|
+
end
|
174
173
|
|
175
|
-
# An implementation of `PseudoPrimeGenerator` which uses a prime table generated
|
176
|
-
# by trial division.
|
177
|
-
#
|
178
|
-
class
|
179
|
-
end
|
174
|
+
# An implementation of `PseudoPrimeGenerator` which uses a prime table generated
|
175
|
+
# by trial division.
|
176
|
+
#
|
177
|
+
class TrialDivisionGenerator < PseudoPrimeGenerator
|
178
|
+
end
|
180
179
|
|
181
|
-
# Generates all integers which are greater than 2 and are not divisible by
|
182
|
-
# either 2 or 3.
|
183
|
-
#
|
184
|
-
# This is a pseudo-prime generator, suitable on checking primality of an integer
|
185
|
-
# by brute force method.
|
186
|
-
#
|
187
|
-
class
|
180
|
+
# Generates all integers which are greater than 2 and are not divisible by
|
181
|
+
# either 2 or 3.
|
182
|
+
#
|
183
|
+
# This is a pseudo-prime generator, suitable on checking primality of an integer
|
184
|
+
# by brute force method.
|
185
|
+
#
|
186
|
+
class Generator23 < PseudoPrimeGenerator
|
187
|
+
end
|
188
188
|
end
|
data/stdlib/tmpdir/tmpdir.rbs
CHANGED
metadata
CHANGED
@@ -1,127 +1,15 @@
|
|
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-
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '13.0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '13.0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: minitest
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '5.0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '5.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: racc
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 1.4.16
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 1.4.16
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rubocop
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rubocop-rubycw
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: minitest-reporters
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - "~>"
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: 1.3.6
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - "~>"
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: 1.3.6
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: json
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - "~>"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: 2.3.0
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - "~>"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: 2.3.0
|
11
|
+
date: 2020-07-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
125
13
|
description: RBS is the language for type signatures for Ruby and standard library
|
126
14
|
definitions.
|
127
15
|
email:
|
@@ -143,6 +31,8 @@ files:
|
|
143
31
|
- bin/annotate-with-rdoc
|
144
32
|
- bin/console
|
145
33
|
- bin/query-rdoc
|
34
|
+
- bin/rbs-prof
|
35
|
+
- bin/run_in_md.rb
|
146
36
|
- bin/setup
|
147
37
|
- bin/sort
|
148
38
|
- bin/test_runner.rb
|
@@ -151,6 +41,7 @@ files:
|
|
151
41
|
- docs/stdlib.md
|
152
42
|
- docs/syntax.md
|
153
43
|
- exe/rbs
|
44
|
+
- goodcheck.yml
|
154
45
|
- lib/rbs.rb
|
155
46
|
- lib/rbs/ast/annotation.rb
|
156
47
|
- lib/rbs/ast/comment.rb
|
@@ -167,6 +58,7 @@ files:
|
|
167
58
|
- lib/rbs/environment_loader.rb
|
168
59
|
- lib/rbs/environment_walker.rb
|
169
60
|
- lib/rbs/errors.rb
|
61
|
+
- lib/rbs/factory.rb
|
170
62
|
- lib/rbs/location.rb
|
171
63
|
- lib/rbs/method_type.rb
|
172
64
|
- lib/rbs/namespace.rb
|
@@ -179,18 +71,29 @@ files:
|
|
179
71
|
- lib/rbs/test.rb
|
180
72
|
- lib/rbs/test/errors.rb
|
181
73
|
- lib/rbs/test/hook.rb
|
74
|
+
- lib/rbs/test/observer.rb
|
182
75
|
- lib/rbs/test/setup.rb
|
183
76
|
- lib/rbs/test/spy.rb
|
184
|
-
- lib/rbs/test/
|
77
|
+
- lib/rbs/test/tester.rb
|
185
78
|
- lib/rbs/test/type_check.rb
|
186
79
|
- lib/rbs/type_name.rb
|
80
|
+
- lib/rbs/type_name_resolver.rb
|
187
81
|
- lib/rbs/types.rb
|
82
|
+
- lib/rbs/validator.rb
|
188
83
|
- lib/rbs/variance_calculator.rb
|
189
84
|
- lib/rbs/vendorer.rb
|
190
85
|
- lib/rbs/version.rb
|
191
86
|
- lib/rbs/writer.rb
|
192
87
|
- lib/ruby/signature.rb
|
193
88
|
- rbs.gemspec
|
89
|
+
- schema/annotation.json
|
90
|
+
- schema/comment.json
|
91
|
+
- schema/decls.json
|
92
|
+
- schema/function.json
|
93
|
+
- schema/location.json
|
94
|
+
- schema/members.json
|
95
|
+
- schema/methodType.json
|
96
|
+
- schema/types.json
|
194
97
|
- stdlib/abbrev/abbrev.rbs
|
195
98
|
- stdlib/base64/base64.rbs
|
196
99
|
- stdlib/benchmark/benchmark.rbs
|
@@ -253,9 +156,16 @@ files:
|
|
253
156
|
- stdlib/coverage/coverage.rbs
|
254
157
|
- stdlib/csv/csv.rbs
|
255
158
|
- stdlib/erb/erb.rbs
|
159
|
+
- stdlib/fiber/fiber.rbs
|
256
160
|
- stdlib/find/find.rbs
|
257
161
|
- stdlib/ipaddr/ipaddr.rbs
|
258
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
|
168
|
+
- stdlib/mutex_m/mutex_m.rbs
|
259
169
|
- stdlib/pathname/pathname.rbs
|
260
170
|
- stdlib/prime/integer-extension.rbs
|
261
171
|
- stdlib/prime/prime.rbs
|
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
|