@@ -3,12 +3,12 @@ import XCTest
3
3
import Nimble
4
4
5
5
final class ContainTest : XCTestCase , XCTestCaseProvider {
6
- func testContain ( ) {
6
+ func testContainSequence ( ) {
7
7
expect ( [ 1 , 2 , 3 ] ) . to ( contain ( 1 ) )
8
+ expect ( [ 1 , 2 , 3 ] ) . toNot ( contain ( 4 ) )
8
9
expect ( [ 1 , 2 , 3 ] as [ CInt ] ) . to ( contain ( 1 as CInt ) )
9
10
expect ( [ 1 , 2 , 3 ] as [ CInt ] ) . toNot ( contain ( 4 as CInt ) )
10
11
expect ( [ " foo " , " bar " , " baz " ] ) . to ( contain ( " baz " ) )
11
- expect ( [ 1 , 2 , 3 ] ) . toNot ( contain ( 4 ) )
12
12
expect ( [ " foo " , " bar " , " baz " ] ) . toNot ( contain ( " ba " ) )
13
13
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
14
14
expect ( NSArray ( array: [ " a " ] ) ) . to ( contain ( NSString ( string: " a " ) ) )
@@ -31,6 +31,25 @@ final class ContainTest: XCTestCase, XCTestCaseProvider {
31
31
}
32
32
}
33
33
34
+ func testContainSetAlgebra( ) {
35
+ expect ( [ . a, . b, . c] as TestOptionSet ) . to ( contain ( . a) )
36
+ expect ( [ . a, . b, . c] as TestOptionSet ) . toNot ( contain ( . d) )
37
+
38
+ failsWithErrorMessage ( " expected to contain <8>, got <7> " ) {
39
+ expect ( [ . a, . b, . c] as TestOptionSet ) . to ( contain ( . d) )
40
+ }
41
+ failsWithErrorMessage ( " expected to not contain <2>, got <7> " ) {
42
+ expect ( [ . a, . b, . c] as TestOptionSet ) . toNot ( contain ( . b) )
43
+ }
44
+
45
+ failsWithErrorMessageForNil ( " expected to contain <1>, got <nil> " ) {
46
+ expect ( nil as TestOptionSet ? ) . to ( contain ( . a) )
47
+ }
48
+ failsWithErrorMessageForNil ( " expected to not contain <1>, got <nil> " ) {
49
+ expect ( nil as TestOptionSet ? ) . toNot ( contain ( . a) )
50
+ }
51
+ }
52
+
34
53
func testContainSubstring( ) {
35
54
expect ( " foo " ) . to ( contain ( " o " ) )
36
55
expect ( " foo " ) . to ( contain ( " oo " ) )
@@ -83,3 +102,23 @@ final class ContainTest: XCTestCase, XCTestCaseProvider {
83
102
}
84
103
}
85
104
}
105
+
106
+ private struct TestOptionSet : OptionSet , CustomStringConvertible {
107
+ let rawValue : Int
108
+
109
+ // swiftlint:disable identifier_name
110
+ static let a = TestOptionSet ( rawValue: 1 << 0 )
111
+ static let b = TestOptionSet ( rawValue: 1 << 1 )
112
+ static let c = TestOptionSet ( rawValue: 1 << 2 )
113
+ static let d = TestOptionSet ( rawValue: 1 << 3 )
114
+ static let e = TestOptionSet ( rawValue: 1 << 4 )
115
+ // swiftlint:enable identifier_name
116
+
117
+ init ( rawValue: Int ) {
118
+ self . rawValue = rawValue
119
+ }
120
+
121
+ var description : String {
122
+ return " \( rawValue) "
123
+ }
124
+ }
0 commit comments