Skip to content

Commit b31f43c

Browse files
committed
[test] Modernize test/stdlib/OptionSetTest.swift
1 parent b31c55b commit b31f43c

File tree

1 file changed

+79
-83
lines changed

1 file changed

+79
-83
lines changed

test/stdlib/OptionSetTest.swift

Lines changed: 79 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -12,114 +12,110 @@
1212
// RUN: %target-run-simple-swift
1313
// REQUIRES: executable_test
1414

15+
import StdlibUnittest
16+
1517
struct PackagingOptions : OptionSet {
1618
let rawValue: Int
1719
init(rawValue: Int) { self.rawValue = rawValue }
1820

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

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)
2929
}
3030

31-
import StdlibUnittest
32-
33-
3431
var tests = TestSuite("OptionSet")
32+
defer { runAllTests() }
3533

3634
tests.test("basics") {
3735
typealias P = PackagingOptions
3836

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)
6361
expectEqual(P(), p)
64-
65-
p = .Box
66-
p.formIntersection(.Satchel)
62+
63+
p = .box
64+
p.formIntersection(.satchel)
6765
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)
8482
}
8583

8684
tests.test("set algebra") {
8785
typealias P = PackagingOptions
88-
86+
8987
// 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)
9593
expectEqual(P(), p)
96-
97-
p = P.BoxOrBag
94+
95+
p = P.boxOrBag
9896
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
9997
// https://github.com/apple/swift/pull/28378
100-
expectEqual(P.Bag, p.remove(P.SatchelOrBag))
98+
expectEqual(P.bag, p.remove(P.satchelOrBag))
10199
}
102-
expectEqual(P.Box, p)
103-
100+
expectEqual(P.box, p)
101+
104102
// insert
105-
p = P.Box
106-
var insertionResult = p.insert(.Bag)
103+
p = P.box
104+
var insertionResult = p.insert(.bag)
107105
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)
112110
expectFalse(insertionResult.inserted)
113-
expectEqual(P.Bag, insertionResult.memberAfterInsert)
114-
111+
expectEqual(P.bag, insertionResult.memberAfterInsert)
112+
115113
// 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)
124117

125-
runAllTests()
118+
p = P.box
119+
expectEqual(P.box, p.update(with: .boxOrBag))
120+
expectEqual(P.boxOrBag, p)
121+
}

0 commit comments

Comments
 (0)