-
Notifications
You must be signed in to change notification settings - Fork 235
Expand file tree
/
Copy pathEnumerator_test.rb
More file actions
59 lines (48 loc) · 1.45 KB
/
Enumerator_test.rb
File metadata and controls
59 lines (48 loc) · 1.45 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
require_relative "test_helper"
class EnumeratorTest < Test::Unit::TestCase
include TypeAssertions
testing "::Enumerator[::Integer, Array[::Integer]]"
def test_map
g = [1,2,3].to_enum
assert_send_type "() { (Integer) -> String } -> Array[String]",
g, :map do |x| x.to_s end
assert_send_type "() -> Enumerator[Integer, Array[untyped]]",
g, :map
end
def test_with_object
g = [1,2,3].to_enum
assert_send_type "(String) -> Enumerator[[Integer, String], String]", g, :with_object, ''
assert_send_type "(String) { (Integer, String) -> untyped } -> String", g, :with_object, '' do end
end
end
class EnumeratorYielderTest < Test::Unit::TestCase
include TypeAssertions
testing "::Enumerator::Yielder"
def test_ltlt
Enumerator.new do |y|
assert_send_type "(untyped) -> void",
y, :<<, 1
end.next
end
def test_yield
Enumerator.new do |y|
assert_send_type "() -> void",
y, :yield
end.next
Enumerator.new do |y|
assert_send_type "(untyped) -> void",
y, :yield, 1
end.next
Enumerator.new do |y|
assert_send_type "(untyped, untyped) -> void",
y, :yield, 1, 2
end.next
end
def test_to_proc
Enumerator.new do |y|
assert_send_type "() -> Proc",
y, :to_proc
y << 42 # To avoid StopIteration error
end.next
end
end