mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Implements the minimum specified by the SE-proposal.
* Add the CaseIterable protocol with AllCases associatedtype and
allCases requirement
* Automatic synthesis occurs for "simple" enums
- Caveat: Availability attributes suppress synthesis. This can be
lifted in the future
- Caveat: Conformance must be stated on the original type
declaration (just like synthesizing Equatable/Hashable)
- Caveat: Synthesis generates an [T]. A more efficient collection
- possibly even a lazy one - should be put here.
22 lines
474 B
Swift
22 lines
474 B
Swift
// RUN: %target-run-simple-swift %t
|
|
// REQUIRES: executable_test
|
|
|
|
import StdlibUnittest
|
|
|
|
var CaseIterableTests = TestSuite("CaseIterableTests")
|
|
|
|
CaseIterableTests.test("Simple Enums") {
|
|
enum SimpleEnum: CaseIterable {
|
|
case bar
|
|
case baz
|
|
case quux
|
|
}
|
|
|
|
expectEqual(SimpleEnum.allCases.count, 3)
|
|
expectTrue(SimpleEnum.allCases.contains(.bar))
|
|
expectTrue(SimpleEnum.allCases.contains(.baz))
|
|
expectTrue(SimpleEnum.allCases.contains(.quux))
|
|
}
|
|
|
|
runAllTests()
|