File tree Expand file tree Collapse file tree 2 files changed +41
-4
lines changed Expand file tree Collapse file tree 2 files changed +41
-4
lines changed Original file line number Diff line number Diff line change @@ -286,9 +286,13 @@ extension OptionSet where Element == Self {
286
286
@inlinable // generic-performance
287
287
@discardableResult
288
288
public mutating func remove( _ member: Element ) -> Element ? {
289
- let r = isSuperset ( of: member) ? Optional ( member) : nil
289
+ let intersectionElements = intersection ( member)
290
+ guard !intersectionElements. isEmpty else {
291
+ return nil
292
+ }
293
+
290
294
self . subtract ( member)
291
- return r
295
+ return intersectionElements
292
296
}
293
297
294
298
/// Inserts the given element into the set.
Original file line number Diff line number Diff line change @@ -83,7 +83,40 @@ tests.test("basics") {
83
83
expectEqual ( [ . Satchel, . Box] , p)
84
84
}
85
85
86
- // FIXME: add tests for all of SetAlgebra, in particular
87
- // insert/remove/replace.
86
+ tests. test ( " set algebra " ) {
87
+ typealias P = PackagingOptions
88
+
89
+ // remove
90
+ var p = P . BoxOrBag
91
+ expectNil ( p. remove ( P . Carton) )
92
+
93
+ p = P . BoxOrBag
94
+ p. remove ( P . BoxOrCartonOrBag)
95
+ expectEqual ( P ( ) , p)
96
+
97
+ p = P . BoxOrBag
98
+ expectEqual ( P . Bag, p. remove ( P . SatchelOrBag) )
99
+ expectEqual ( P . Box, p)
100
+
101
+ // insert
102
+ p = P . Box
103
+ var insertionResult = p. insert ( . Bag)
104
+ expectTrue ( insertionResult. inserted)
105
+ expectEqual ( P . Bag, insertionResult. memberAfterInsert)
106
+ expectEqual ( P . BoxOrBag, p)
107
+
108
+ insertionResult = p. insert ( . Bag)
109
+ expectFalse ( insertionResult. inserted)
110
+ expectEqual ( P . Bag, insertionResult. memberAfterInsert)
111
+
112
+ // update
113
+ p = P . Box
114
+ expectNil ( p. update ( with: . Bag) )
115
+ expectEqual ( P . BoxOrBag, p)
116
+
117
+ p = P . Box
118
+ expectEqual ( P . Box, p. update ( with: . BoxOrBag) )
119
+ expectEqual ( P . BoxOrBag, p)
120
+ }
88
121
89
122
runAllTests ( )
You can’t perform that action at this time.
0 commit comments