|
12 | 12 | // RUN: %target-run-simple-swift
|
13 | 13 | // REQUIRES: executable_test
|
14 | 14 |
|
| 15 | +import StdlibUnittest |
| 16 | + |
15 | 17 | struct PackagingOptions : OptionSet {
|
16 | 18 | let rawValue: Int
|
17 | 19 | init(rawValue: Int) { self.rawValue = rawValue }
|
18 | 20 |
|
19 |
| - static let |
20 |
| - Box = PackagingOptions(rawValue: 1), |
21 |
| - Carton = PackagingOptions(rawValue: 2), |
22 |
| - Bag = PackagingOptions(rawValue: 4), |
23 |
| - Satchel = PackagingOptions(rawValue: 8) |
| 21 | + static let box = PackagingOptions(rawValue: 1) |
| 22 | + static let carton = PackagingOptions(rawValue: 2) |
| 23 | + static let bag = PackagingOptions(rawValue: 4) |
| 24 | + static let satchel = PackagingOptions(rawValue: 8) |
24 | 25 |
|
25 |
| - // FIXME: these must be separate decls because of <rdar://20962990> |
26 |
| - static let BoxOrBag: PackagingOptions = [Box, Bag] |
27 |
| - static let BoxOrCartonOrBag: PackagingOptions = [Box, Carton, Bag] |
28 |
| - static let SatchelOrBag = Satchel.union(Bag) |
| 26 | + static let boxOrBag: PackagingOptions = [box, bag] |
| 27 | + static let boxOrCartonOrBag: PackagingOptions = [box, carton, bag] |
| 28 | + static let satchelOrBag = satchel.union(bag) |
29 | 29 | }
|
30 | 30 |
|
31 |
| -import StdlibUnittest |
32 |
| - |
33 |
| - |
34 | 31 | var tests = TestSuite("OptionSet")
|
| 32 | +defer { runAllTests() } |
35 | 33 |
|
36 | 34 | tests.test("basics") {
|
37 | 35 | typealias P = PackagingOptions
|
38 | 36 |
|
39 |
| - expectNotEqual(P(), .Box) |
40 |
| - expectEqual(P.Box, .Box) |
41 |
| - expectNotEqual(P.Box, .Carton) |
42 |
| - expectNotEqual(P.Box, .BoxOrBag) |
43 |
| - |
44 |
| - expectEqual(.Box, P.Box.intersection(.BoxOrBag)) |
45 |
| - expectEqual(.Bag, P.Bag.intersection(.BoxOrBag)) |
46 |
| - expectEqual(P(), P.Bag.intersection(.Box)) |
47 |
| - expectEqual(P(), P.Box.intersection(.Satchel)) |
48 |
| - expectEqual(.BoxOrBag, P.Bag.union(.Box)) |
49 |
| - expectEqual(.BoxOrBag, P.Box.union(.Bag)) |
50 |
| - expectEqual(.BoxOrCartonOrBag, P.BoxOrBag.union(.Carton)) |
51 |
| - expectEqual([.Satchel, .Box], P.SatchelOrBag.symmetricDifference(.BoxOrBag)) |
52 |
| - |
53 |
| - var p = P.Box |
54 |
| - p.formIntersection(.BoxOrBag) |
55 |
| - expectEqual(.Box, p) |
56 |
| - |
57 |
| - p = .Bag |
58 |
| - p.formIntersection(.BoxOrBag) |
59 |
| - expectEqual(.Bag, p) |
60 |
| - |
61 |
| - p = .Bag |
62 |
| - p.formIntersection(.Box) |
| 37 | + expectNotEqual(P(), .box) |
| 38 | + expectEqual(P.box, .box) |
| 39 | + expectNotEqual(P.box, .carton) |
| 40 | + expectNotEqual(P.box, .boxOrBag) |
| 41 | + |
| 42 | + expectEqual(.box, P.box.intersection(.boxOrBag)) |
| 43 | + expectEqual(.bag, P.bag.intersection(.boxOrBag)) |
| 44 | + expectEqual(P(), P.bag.intersection(.box)) |
| 45 | + expectEqual(P(), P.box.intersection(.satchel)) |
| 46 | + expectEqual(.boxOrBag, P.bag.union(.box)) |
| 47 | + expectEqual(.boxOrBag, P.box.union(.bag)) |
| 48 | + expectEqual(.boxOrCartonOrBag, P.boxOrBag.union(.carton)) |
| 49 | + expectEqual([.satchel, .box], P.satchelOrBag.symmetricDifference(.boxOrBag)) |
| 50 | + |
| 51 | + var p = P.box |
| 52 | + p.formIntersection(.boxOrBag) |
| 53 | + expectEqual(.box, p) |
| 54 | + |
| 55 | + p = .bag |
| 56 | + p.formIntersection(.boxOrBag) |
| 57 | + expectEqual(.bag, p) |
| 58 | + |
| 59 | + p = .bag |
| 60 | + p.formIntersection(.box) |
63 | 61 | expectEqual(P(), p)
|
64 |
| - |
65 |
| - p = .Box |
66 |
| - p.formIntersection(.Satchel) |
| 62 | + |
| 63 | + p = .box |
| 64 | + p.formIntersection(.satchel) |
67 | 65 | expectEqual(P(), p)
|
68 |
| - |
69 |
| - p = .Bag |
70 |
| - p.formUnion(.Box) |
71 |
| - expectEqual(.BoxOrBag, p) |
72 |
| - |
73 |
| - p = .Box |
74 |
| - p.formUnion(.Bag) |
75 |
| - expectEqual(.BoxOrBag, p) |
76 |
| - |
77 |
| - p = .BoxOrBag |
78 |
| - p.formUnion(.Carton) |
79 |
| - expectEqual(.BoxOrCartonOrBag, p) |
80 |
| - |
81 |
| - p = .SatchelOrBag |
82 |
| - p.formSymmetricDifference(.BoxOrBag) |
83 |
| - expectEqual([.Satchel, .Box], p) |
| 66 | + |
| 67 | + p = .bag |
| 68 | + p.formUnion(.box) |
| 69 | + expectEqual(.boxOrBag, p) |
| 70 | + |
| 71 | + p = .box |
| 72 | + p.formUnion(.bag) |
| 73 | + expectEqual(.boxOrBag, p) |
| 74 | + |
| 75 | + p = .boxOrBag |
| 76 | + p.formUnion(.carton) |
| 77 | + expectEqual(.boxOrCartonOrBag, p) |
| 78 | + |
| 79 | + p = .satchelOrBag |
| 80 | + p.formSymmetricDifference(.boxOrBag) |
| 81 | + expectEqual([.satchel, .box], p) |
84 | 82 | }
|
85 | 83 |
|
86 | 84 | tests.test("set algebra") {
|
87 | 85 | typealias P = PackagingOptions
|
88 |
| - |
| 86 | + |
89 | 87 | // remove
|
90 |
| - var p = P.BoxOrBag |
91 |
| - expectNil(p.remove(P.Carton)) |
92 |
| - |
93 |
| - p = P.BoxOrBag |
94 |
| - p.remove(P.BoxOrCartonOrBag) |
| 88 | + var p = P.boxOrBag |
| 89 | + expectNil(p.remove(P.carton)) |
| 90 | + |
| 91 | + p = P.boxOrBag |
| 92 | + p.remove(P.boxOrCartonOrBag) |
95 | 93 | expectEqual(P(), p)
|
96 |
| - |
97 |
| - p = P.BoxOrBag |
| 94 | + |
| 95 | + p = P.boxOrBag |
98 | 96 | if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
|
99 | 97 | // https://github.com/apple/swift/pull/28378
|
100 |
| - expectEqual(P.Bag, p.remove(P.SatchelOrBag)) |
| 98 | + expectEqual(P.bag, p.remove(P.satchelOrBag)) |
101 | 99 | }
|
102 |
| - expectEqual(P.Box, p) |
103 |
| - |
| 100 | + expectEqual(P.box, p) |
| 101 | + |
104 | 102 | // insert
|
105 |
| - p = P.Box |
106 |
| - var insertionResult = p.insert(.Bag) |
| 103 | + p = P.box |
| 104 | + var insertionResult = p.insert(.bag) |
107 | 105 | expectTrue(insertionResult.inserted)
|
108 |
| - expectEqual(P.Bag, insertionResult.memberAfterInsert) |
109 |
| - expectEqual(P.BoxOrBag, p) |
110 |
| - |
111 |
| - insertionResult = p.insert(.Bag) |
| 106 | + expectEqual(P.bag, insertionResult.memberAfterInsert) |
| 107 | + expectEqual(P.boxOrBag, p) |
| 108 | + |
| 109 | + insertionResult = p.insert(.bag) |
112 | 110 | expectFalse(insertionResult.inserted)
|
113 |
| - expectEqual(P.Bag, insertionResult.memberAfterInsert) |
114 |
| - |
| 111 | + expectEqual(P.bag, insertionResult.memberAfterInsert) |
| 112 | + |
115 | 113 | // update
|
116 |
| - p = P.Box |
117 |
| - expectNil(p.update(with: .Bag)) |
118 |
| - expectEqual(P.BoxOrBag, p) |
119 |
| - |
120 |
| - p = P.Box |
121 |
| - expectEqual(P.Box, p.update(with: .BoxOrBag)) |
122 |
| - expectEqual(P.BoxOrBag, p) |
123 |
| -} |
| 114 | + p = P.box |
| 115 | + expectNil(p.update(with: .bag)) |
| 116 | + expectEqual(P.boxOrBag, p) |
124 | 117 |
|
125 |
| -runAllTests() |
| 118 | + p = P.box |
| 119 | + expectEqual(P.box, p.update(with: .boxOrBag)) |
| 120 | + expectEqual(P.boxOrBag, p) |
| 121 | +} |
0 commit comments