Files
swift-mirror/test/stdlib/CaseIterableTests.swift
Robert Widmann dac06898e9 [SE-0194] Deriving Collections of Enum Cases
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.
2018-03-09 00:22:55 -05:00

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()