1
- //===--- HashedCollectionCasts .swift.gyb ----------------------------------===//
1
+ //===--- CollectionCasts .swift.gyb ------ ----------------------------------===//
2
2
//
3
3
// This source file is part of the Swift.org open source project
4
4
//
11
11
//===----------------------------------------------------------------------===//
12
12
// RUN: rm -rf %t
13
13
// RUN: mkdir -p %t
14
- // RUN: %gyb %s -o %t/HashedCollectionCasts .swift
15
- // RUN: %line-directive %t/HashedCollectionCasts .swift -- %target-build-swift -Xfrontend -enable-experimental-collection-casts %t/HashedCollectionCasts .swift -o %t/a.out
16
- // RUN: %line-directive %t/HashedCollectionCasts .swift -- %target-run %t/a.out 2>&1
14
+ // RUN: %gyb %s -o %t/CollectionCasts .swift
15
+ // RUN: %line-directive %t/CollectionCasts .swift -- %target-build-swift -Xfrontend -enable-experimental-collection-casts %t/CollectionCasts .swift -o %t/a.out
16
+ // RUN: %line-directive %t/CollectionCasts .swift -- %target-run %t/a.out 2>&1
17
17
// REQUIRES: executable_test
18
18
19
19
import StdlibUnittest
@@ -39,7 +39,7 @@ protocol AnyFoo {
39
39
}
40
40
extension Int : AnyFoo { }
41
41
42
- var tests = TestSuite("HashedCollectionCasts ")
42
+ var tests = TestSuite("CollectionCasts ")
43
43
44
44
// A wrapper for an as? cast that suppresses warnings when the cast always
45
45
// succeeds.
@@ -60,50 +60,53 @@ nonClassValues = ('Int', 'AnyFoo', 'Any')
60
60
% for ki0, Key0 in enumerate(keys):
61
61
% DynamicKey = keys[0] if Key0.startswith('Any') else Key0
62
62
% for Key1 in keys[ki0:]:
63
+ % for Collection in 'Array', 'Set':
63
64
64
- tests.test("Set /Up/${Key0}=>${Key1}") {
65
+ tests.test("${Collection} /Up/${Key0}=>${Key1}") {
65
66
66
- let source : Set = [
67
+ let source : ${Collection} = [
67
68
${DynamicKey}(42) as ${Key0},
68
69
${DynamicKey}(17) as ${Key0}]
69
70
70
- let upcasted = source as Set <${Key1}>
71
-
71
+ let upcasted = source as ${Collection} <${Key1}>
72
+
72
73
expectEqual(source.count, upcasted.count)
73
74
for x in source {
74
75
expectTrue(upcasted.contains(x))
75
76
}
76
77
}
77
78
78
- % if Key1 != Key0:
79
- % for method in 'Direct', 'Indirect':
80
- tests.test("Set /Down/${method}/${Key1}=>${Key0}") {
79
+ % if Key1 != Key0:
80
+ % for method in 'Direct', 'Indirect':
81
+ tests.test("${Collection} /Down/${method}/${Key1}=>${Key0}") {
81
82
82
- let source : Set = [
83
+ let source : ${Collection} = [
83
84
${DynamicKey}(42) as ${Key1},
84
85
${DynamicKey}(17) as ${Key1}]
85
86
86
- % if method == 'Direct':
87
+ % if method == 'Direct':
87
88
88
- guard let downcasted = expectNotEmpty(source as? Set <${Key0}>)
89
+ guard let downcasted = expectNotEmpty(source as? ${Collection} <${Key0}>)
89
90
else { return }
90
91
91
- % else:
92
+ % else:
92
93
93
94
// FIXME Set<Base> => Set<Derived> fails dynamically, and never even reaches
94
95
// one of my runtime entry points.
95
- guard let downcasted = expectNotEmpty(cast(source, to: Set <${Key0}>.self))
96
+ guard let downcasted = expectNotEmpty(cast(source, to: ${Collection} <${Key0}>.self))
96
97
else { return }
97
98
98
- % end
99
+ % end
99
100
100
101
expectEqual(source.count, downcasted.count)
101
102
for x in downcasted {
102
103
expectTrue(source.contains(x))
103
104
}
104
105
}
105
- % end
106
- % end
106
+ % end
107
+ % end
108
+ % end
109
+
107
110
108
111
% for vi0, Value0 in enumerate(values):
109
112
% DynamicValue = values[0] if Value0.startswith('Any') else Value0
0 commit comments