-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathFlattenCollection.swift.gyb
91 lines (82 loc) · 3.32 KB
/
FlattenCollection.swift.gyb
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
// -*- swift -*-
// RUN: %target-run-simple-swiftgyb
// REQUIRES: executable_test
// FIXME: the test is too slow when the standard library is not optimized.
// rdar://problem/46878013
// REQUIRES: optimized_stdlib
// REQUIRES: long_test
import SwiftPrivate
import StdlibUnittest
import StdlibCollectionUnittest
var tests = TestSuite("FlattenCollection")
%{
variations = [('', 'Sequence'), ('', 'Collection'), ('Bidirectional', 'Collection')]
}%
// Test collections using value types as elements.
% for (traversal, kind) in variations:
tests.add${traversal}${kind}Tests(
make${kind}: { (elements: [OpaqueValue<Int>]) -> Flatten${kind}<Minimal${traversal}${kind}<Minimal${traversal}${kind}<OpaqueValue<Int>>>> in
Minimal${traversal}${kind}(elements: elements.map { Minimal${traversal}${kind}(elements: [$0]) }).joined()
},
wrapValue: identity,
extractValue: identity,
make${kind}OfEquatable: { (elements: [MinimalEquatableValue]) -> Flatten${kind}<Minimal${traversal}${kind}<Minimal${traversal}${kind}<MinimalEquatableValue>>> in
Minimal${traversal}${kind}(elements: elements.map { Minimal${traversal}${kind}(elements: [$0]) }).joined()
},
wrapValueIntoEquatable: identityEq,
extractValueFromEquatable: identityEq
)
% end
// Test collections using reference types as elements.
% for (traversal, kind) in variations:
tests.add${traversal}${kind}Tests(
make${kind}: { (elements: [LifetimeTracked]) -> Flatten${kind}<Minimal${traversal}${kind}<Minimal${traversal}${kind}<LifetimeTracked>>> in
Minimal${traversal}${kind}(elements: elements.map { Minimal${traversal}${kind}(elements: [$0]) }).joined()
},
wrapValue: { (element: OpaqueValue<Int>) in
LifetimeTracked(element.value, identity: element.identity)
},
extractValue: { (element: LifetimeTracked) in
OpaqueValue(element.value, identity: element.identity)
},
make${kind}OfEquatable: { (elements: [LifetimeTracked]) -> Flatten${kind}<Minimal${traversal}${kind}<Minimal${traversal}${kind}<LifetimeTracked>>> in
Minimal${traversal}${kind}(elements: elements.map { Minimal${traversal}${kind}(elements: [$0]) }).joined()
},
wrapValueIntoEquatable: { (element: MinimalEquatableValue) in
LifetimeTracked(element.value, identity: element.identity)
},
extractValueFromEquatable: { (element: LifetimeTracked) in
MinimalEquatableValue(element.value, identity: element.identity)
}
)
% end
var rdar45956357: Bool
// Test collection instances and iterators.
% for (traversal, kind) in variations:
if #available(macOS 10.14, iOS 12.0, watchOS 5.0, tvOS 12.0, *) {
tests.test("FlattenCollection instances (${traversal}${kind})") {
do {
let expected : [String] = []
let base: [[String]] = [[], [], []]
check${traversal}${kind}(
expected,
Minimal${traversal}${kind}(elements: base).joined(),
sameValue: { $0 == $1 })
}
do {
let expected = ["apple", "orange", "banana", "grapefruit", "lychee"]
let base = [["apple", "orange"], ["banana", "grapefruit"], ["lychee"]]
let flattened = Minimal${traversal}${kind}(elements: base).joined()
check${traversal}${kind}(
expected,
Minimal${traversal}${kind}(elements: base).joined(),
sameValue: { $0 == $1 })
checkSequence(
expected,
flattened.makeIterator(),
sameValue: { $0 == $1 })
}
}
}
% end
runAllTests()