Skip to content

Commit d6bf934

Browse files
committed
[test][stdlib] Spin tests for Optional generalizations off into a separate file
1 parent 4db7b7c commit d6bf934

File tree

2 files changed

+67
-56
lines changed

2 files changed

+67
-56
lines changed

test/stdlib/Optional.swift

-56
Original file line numberDiff line numberDiff line change
@@ -426,60 +426,4 @@ OptionalTests.test("unsafelyUnwrapped nil")
426426
}
427427
#endif
428428

429-
func isCopyable<T: ~Copyable & ~Escapable>(_: T.Type) -> Bool { false }
430-
func isCopyable<T: ~Escapable>(_: T.Type) -> Bool { true }
431-
432-
func isBitwiseCopyable<T: ~Copyable & ~Escapable>(_: T.Type) -> Bool { false }
433-
func isBitwiseCopyable<T: BitwiseCopyable & ~Escapable>(_: T.Type) -> Bool { true }
434-
435-
#if $NonescapableTypes
436-
func isEscapable<T: ~Escapable & ~Copyable>(_: T.Type) -> Bool { false }
437-
func isEscapable<T: ~Copyable>(_: T.Type) -> Bool { true }
438-
#endif
439-
440-
struct TrivialStruct {}
441-
struct NoncopyableStruct: ~Copyable {}
442-
class RegularClass {}
443-
444-
#if $NonescapableTypes
445-
struct NonescapableStruct: ~Escapable, BitwiseCopyable {}
446-
struct NoncopyableNonescapableStruct: ~Copyable, ~Escapable {}
447-
struct NonescapableNontrivialStruct: ~Escapable {
448-
let foo: RegularClass? = nil
449-
}
450-
#endif
451-
452-
OptionalTests.test("Copyability") {
453-
expectTrue(isCopyable(Optional<TrivialStruct>.self))
454-
expectFalse(isCopyable(Optional<NoncopyableStruct>.self))
455-
expectTrue(isCopyable(Optional<RegularClass>.self))
456-
#if $NonescapableTypes
457-
expectTrue(isCopyable(Optional<NonescapableStruct>.self))
458-
expectFalse(isCopyable(Optional<NoncopyableNonescapableStruct>.self))
459-
expectTrue(isCopyable(Optional<NonescapableNontrivialStruct>.self))
460-
#endif
461-
}
462-
463-
OptionalTests.test("BitwiseCopyability") {
464-
expectTrue(isBitwiseCopyable(Optional<TrivialStruct>.self))
465-
expectFalse(isBitwiseCopyable(Optional<NoncopyableStruct>.self))
466-
expectFalse(isBitwiseCopyable(Optional<RegularClass>.self))
467-
#if $NonescapableTypes
468-
expectTrue(isBitwiseCopyable(Optional<NonescapableStruct>.self))
469-
expectFalse(isBitwiseCopyable(Optional<NoncopyableNonescapableStruct>.self))
470-
expectFalse(isBitwiseCopyable(Optional<NonescapableNontrivialStruct>.self))
471-
#endif
472-
}
473-
474-
#if $NonescapableTypes
475-
OptionalTests.test("Escapability") {
476-
expectTrue(isEscapable(Optional<TrivialStruct>.self))
477-
expectTrue(isEscapable(Optional<NoncopyableStruct>.self))
478-
expectTrue(isEscapable(Optional<RegularClass>.self))
479-
expectFalse(isEscapable(Optional<NonescapableStruct>.self))
480-
expectFalse(isEscapable(Optional<NoncopyableNonescapableStruct>.self))
481-
expectFalse(isEscapable(Optional<NonescapableNontrivialStruct>.self))
482-
}
483-
#endif
484-
485429
runAllTests()
+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// RUN: %target-run-simple-swift(-enable-experimental-feature NonescapableTypes)
2+
// REQUIRES: executable_test
3+
// REQUIRES: reflection
4+
// REQUIRES: swift_feature_NonescapableTypes
5+
6+
import StdlibUnittest
7+
import Swift
8+
9+
let suite = TestSuite("Optional")
10+
11+
defer { runAllTests() }
12+
13+
func isCopyable<T: ~Copyable & ~Escapable>(_: T.Type) -> Bool { false }
14+
func isCopyable<T: ~Escapable>(_: T.Type) -> Bool { true }
15+
16+
func isBitwiseCopyable<T: ~Copyable & ~Escapable>(_: T.Type) -> Bool { false }
17+
func isBitwiseCopyable<T: BitwiseCopyable & ~Escapable>(_: T.Type) -> Bool { true }
18+
19+
#if $NonescapableTypes
20+
func isEscapable<T: ~Escapable & ~Copyable>(_: T.Type) -> Bool { false }
21+
func isEscapable<T: ~Copyable>(_: T.Type) -> Bool { true }
22+
#endif
23+
24+
struct TrivialStruct {}
25+
struct NoncopyableStruct: ~Copyable {}
26+
class RegularClass {}
27+
28+
#if $NonescapableTypes
29+
struct NonescapableStruct: ~Escapable, BitwiseCopyable {}
30+
struct NoncopyableNonescapableStruct: ~Copyable, ~Escapable {}
31+
struct NonescapableNontrivialStruct: ~Escapable {
32+
let foo: RegularClass? = nil
33+
}
34+
#endif
35+
36+
suite.test("Copyability") {
37+
expectTrue(isCopyable(Optional<TrivialStruct>.self))
38+
expectFalse(isCopyable(Optional<NoncopyableStruct>.self))
39+
expectTrue(isCopyable(Optional<RegularClass>.self))
40+
#if $NonescapableTypes
41+
expectTrue(isCopyable(Optional<NonescapableStruct>.self))
42+
expectFalse(isCopyable(Optional<NoncopyableNonescapableStruct>.self))
43+
expectTrue(isCopyable(Optional<NonescapableNontrivialStruct>.self))
44+
#endif
45+
}
46+
47+
suite.test("BitwiseCopyability") {
48+
expectTrue(isBitwiseCopyable(Optional<TrivialStruct>.self))
49+
expectFalse(isBitwiseCopyable(Optional<NoncopyableStruct>.self))
50+
expectFalse(isBitwiseCopyable(Optional<RegularClass>.self))
51+
#if $NonescapableTypes
52+
expectTrue(isBitwiseCopyable(Optional<NonescapableStruct>.self))
53+
expectFalse(isBitwiseCopyable(Optional<NoncopyableNonescapableStruct>.self))
54+
expectFalse(isBitwiseCopyable(Optional<NonescapableNontrivialStruct>.self))
55+
#endif
56+
}
57+
58+
#if $NonescapableTypes
59+
suite.test("Escapability") {
60+
expectTrue(isEscapable(Optional<TrivialStruct>.self))
61+
expectTrue(isEscapable(Optional<NoncopyableStruct>.self))
62+
expectTrue(isEscapable(Optional<RegularClass>.self))
63+
expectFalse(isEscapable(Optional<NonescapableStruct>.self))
64+
expectFalse(isEscapable(Optional<NoncopyableNonescapableStruct>.self))
65+
expectFalse(isEscapable(Optional<NonescapableNontrivialStruct>.self))
66+
}
67+
#endif

0 commit comments

Comments
 (0)