-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayBuilderTests.swift
More file actions
112 lines (99 loc) · 1.3 KB
/
ArrayBuilderTests.swift
File metadata and controls
112 lines (99 loc) · 1.3 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
import Testing
@testable import ArrayBuilder
@Suite
struct ArrayBuilderTests {
func build<T>(
with range: ClosedRange<Int>,
@ArrayBuilder<T> _ f: (Int) -> [T]
) -> [T] {
return range.flatMap(f)
}
@Test
func buildEmpty() async throws {
#expect(
Array<Int> { }
== []
)
#expect(
Array<Int> { [] }
== []
)
}
@Test
func buildSimple() async throws {
#expect(
Array {
1
2
3
}
== [1,2,3]
)
}
@Test
func buildNested() async throws {
#expect(
Array<Int> {
1
[2, 3, 4]
Array {
5
[[6], [7, 8]] // double nesting
9
[]
}
}
== [1,2,3,4,5,6,7,8,9]
)
}
@Test
func buildIf() async throws {
#expect(
Array {
1
if true {
2
}
if false {
3
}
if false {
4
} else {
5
}
if true {} else { 6 }
if false {} else if true { 7 }
}
== [1,2,5,7]
)
}
@Test
func buildSwitch() async throws {
#expect(
build(with: 1...5) { i in
switch i {
case 1: "one"
case 2: "two"
case 3: "three"
case 4: "four"
case 5: [] // ignore 5
default: "unexpected"
}
}
== ["one","two","three","four"]
)
}
@Test
func buildOptional() async throws {
#expect(
Array {
1
Int?.some(2)
Int?.none
4
}
== [1,2,4]
)
}
}