Skip to content

Commit 85ee846

Browse files
author
Dave Abrahams
committed
[stdlib] Test array casting on Linux
The other file that exercises these code paths only runs on the Mac because it's intertwined with bridging stuff.
1 parent 7c7fc16 commit 85ee846

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

test/1_stdlib/HashedCollectionCasts.swift.gyb renamed to test/1_stdlib/CollectionCasts.swift.gyb

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- HashedCollectionCasts.swift.gyb ----------------------------------===//
1+
//===--- CollectionCasts.swift.gyb ----------------------------------------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -11,9 +11,9 @@
1111
//===----------------------------------------------------------------------===//
1212
// RUN: rm -rf %t
1313
// 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
1717
// REQUIRES: executable_test
1818

1919
import StdlibUnittest
@@ -39,7 +39,7 @@ protocol AnyFoo {
3939
}
4040
extension Int : AnyFoo { }
4141

42-
var tests = TestSuite("HashedCollectionCasts")
42+
var tests = TestSuite("CollectionCasts")
4343

4444
// A wrapper for an as? cast that suppresses warnings when the cast always
4545
// succeeds.
@@ -60,50 +60,53 @@ nonClassValues = ('Int', 'AnyFoo', 'Any')
6060
% for ki0, Key0 in enumerate(keys):
6161
% DynamicKey = keys[0] if Key0.startswith('Any') else Key0
6262
% for Key1 in keys[ki0:]:
63+
% for Collection in 'Array', 'Set':
6364

64-
tests.test("Set/Up/${Key0}=>${Key1}") {
65+
tests.test("${Collection}/Up/${Key0}=>${Key1}") {
6566

66-
let source : Set = [
67+
let source : ${Collection} = [
6768
${DynamicKey}(42) as ${Key0},
6869
${DynamicKey}(17) as ${Key0}]
6970

70-
let upcasted = source as Set<${Key1}>
71-
71+
let upcasted = source as ${Collection}<${Key1}>
72+
7273
expectEqual(source.count, upcasted.count)
7374
for x in source {
7475
expectTrue(upcasted.contains(x))
7576
}
7677
}
7778

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}") {
8182

82-
let source : Set = [
83+
let source : ${Collection} = [
8384
${DynamicKey}(42) as ${Key1},
8485
${DynamicKey}(17) as ${Key1}]
8586

86-
% if method == 'Direct':
87+
% if method == 'Direct':
8788

88-
guard let downcasted = expectNotEmpty(source as? Set<${Key0}>)
89+
guard let downcasted = expectNotEmpty(source as? ${Collection}<${Key0}>)
8990
else { return }
9091

91-
% else:
92+
% else:
9293

9394
// FIXME Set<Base> => Set<Derived> fails dynamically, and never even reaches
9495
// 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))
9697
else { return }
9798

98-
% end
99+
% end
99100

100101
expectEqual(source.count, downcasted.count)
101102
for x in downcasted {
102103
expectTrue(source.contains(x))
103104
}
104105
}
105-
% end
106-
% end
106+
% end
107+
% end
108+
% end
109+
107110

108111
% for vi0, Value0 in enumerate(values):
109112
% DynamicValue = values[0] if Value0.startswith('Any') else Value0

0 commit comments

Comments
 (0)