-
Notifications
You must be signed in to change notification settings - Fork 242
Expand file tree
/
Copy pathProc_test.rb
More file actions
163 lines (130 loc) · 4.08 KB
/
Proc_test.rb
File metadata and controls
163 lines (130 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
require_relative 'test_helper'
class ProcSingletonTest < Test::Unit::TestCase
include TestHelper
testing 'singleton(::Proc)'
class MyProc < Proc
end
def test_new
assert_send_type '() { (?) -> untyped } -> ProcSingletonTest::MyProc',
MyProc, :new do end
end
end
class ProcInstanceTest < Test::Unit::TestCase
include TestHelper
testing '::Proc'
class MyProc < Proc
end
def test_clone
assert_send_type '() -> ProcInstanceTest::MyProc',
MyProc.new{}, :clone
end
def test_dup
assert_send_type '() -> ProcInstanceTest::MyProc',
MyProc.new{}, :dup
end
def test_op_eqq
test_call(method: :===)
end
def test_yield
test_call(method: :yield)
end
def test_op_lsh
# Ensure it returns a Proc regardless of self and other type
assert_send_type '(ProcInstanceTest::MyProc) -> Proc',
MyProc.new{}, :<<, MyProc.new{}
callable = BlankSlate.new
def callable.call(*, **, &b) = 1r
with proc{}, lambda{}, method(:p), callable do |other|
assert_send_type '(Proc::_Callable) -> Proc',
proc{}, :<<, other
end
end
def test_op_rsh
# Ensure it returns a Proc regardless of self and other type
assert_send_type '(ProcInstanceTest::MyProc) -> Proc',
MyProc.new{}, :>>, MyProc.new{}
callable = BlankSlate.new
def callable.call(*, **, &b) = 1r
with proc{}, lambda{}, method(:p), callable do |other|
assert_send_type '(Proc::_Callable) -> Proc',
proc{}, :>>, other
end
end
def test_op_eq(method: :==)
with_untyped.and proc{} do |untyped|
assert_send_type '(untyped) -> bool',
proc{}, method, untyped
end
end
def test_eql?
test_op_eq(method: :eql?)
end
def test_arity
assert_send_type '() -> Integer',
proc{}, :arity
assert_send_type '() -> Integer',
proc{|x|}, :arity
assert_send_type '() -> Integer',
proc{|*x|}, :arity
end
def test_binding
assert_send_type '() -> Binding',
proc{}, :binding
end
def test_call(method: :call)
assert_send_type '(?) -> untyped',
proc{1r}, method, 1, 2i, foo: :three do end
end
def test_op_aref
test_call(method: :[])
end
def test_curry
# Use `MyProc` to ensure it returns `Proc` and not `instance`.
assert_send_type '() -> Proc',
MyProc.new{}, :curry
with_int.and_nil do |arity|
assert_send_type '(int?) -> Proc',
MyProc.new{}, :curry, arity
end
end
def test_hash
assert_send_type '() -> Integer',
proc{}, :hash
end
def test_lambda?
assert_send_type '() -> bool',
proc{}, :lambda?
assert_send_type '() -> bool',
lambda{}, :lambda?
end
def test_parameters
assert_send_type '() -> ::Method::param_types',
proc{|a=3, b=4, c, d: 3| }, :parameters
assert_send_type '() -> ::Method::param_types',
proc{|a, b=3, *c, d: 1, e:, **f, &g| }, :parameters
assert_send_type '() -> ::Method::param_types',
proc{|**nil| }, :parameters
assert_send_type '() -> ::Method::param_types',
proc{|*, **, &b| }, :parameters
end
def test_source_location
if_ruby(..."4.1") do
assert_send_type '() -> [String, Integer]',
proc{}, :source_location
end
if_ruby("4.1"...) do
assert_send_type '() -> [String, Integer, Integer, Integer, Integer]',
proc{}, :source_location
end
assert_send_type '() -> nil',
Proc.new(&Kernel.method(:print)), :source_location
end
def test_to_proc
assert_send_type '() -> ProcInstanceTest::MyProc',
MyProc.new{}, :to_proc
end
def test_to_s(method: :to_s)
assert_send_type '() -> String',
proc{}, method
end
end