blob: 4d5e5cab4a649c1c52745f6c4316dd883b2e5d42 (
plain)
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
|
##
# Proc ISO Test
assert('Proc', '15.2.17') do
Proc.class == Class
end
assert('Proc superclass', '15.2.17.2') do
Proc.superclass == Object
end
assert('Proc.new', '15.2.17.3.1') do
a = nil
begin
Proc.new
rescue => e
a = e
end
b = Proc.new {}
a.class == ArgumentError and b.class == Proc
end
assert('Proc#[]', '15.2.17.4.1') do
a = 0
b = Proc.new { a += 1 }
b.[]
a2 = 0
b2 = Proc.new { |i| a2 += i }
b2.[](5)
a == 1 and a2 == 5
end
assert('Proc#arity', '15.2.17.4.2') do
a = Proc.new {|x, y|}.arity
b = Proc.new {|x, *y, z|}.arity
c = Proc.new {|x=0, y|}.arity
d = Proc.new {|(x, y), z=0|}.arity
a == 2 and b == -3 and c == 1 and d == 1
end
assert('Proc#call', '15.2.17.4.3') do
a = 0
b = Proc.new { a += 1 }
b.call
a2 = 0
b2 = Proc.new { |i| a2 += i }
b2.call(5)
a == 1 and a2 == 5
end
|