@@ -3,12 +3,12 @@ import XCTest
33import Nimble
44
55final class ContainTest : XCTestCase , XCTestCaseProvider {
6- func testContain ( ) {
6+ func testContainSequence ( ) {
77 expect ( [ 1 , 2 , 3 ] ) . to ( contain ( 1 ) )
8+ expect ( [ 1 , 2 , 3 ] ) . toNot ( contain ( 4 ) )
89 expect ( [ 1 , 2 , 3 ] as [ CInt ] ) . to ( contain ( 1 as CInt ) )
910 expect ( [ 1 , 2 , 3 ] as [ CInt ] ) . toNot ( contain ( 4 as CInt ) )
1011 expect ( [ " foo " , " bar " , " baz " ] ) . to ( contain ( " baz " ) )
11- expect ( [ 1 , 2 , 3 ] ) . toNot ( contain ( 4 ) )
1212 expect ( [ " foo " , " bar " , " baz " ] ) . toNot ( contain ( " ba " ) )
1313#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
1414 expect ( NSArray ( array: [ " a " ] ) ) . to ( contain ( NSString ( string: " a " ) ) )
@@ -31,6 +31,25 @@ final class ContainTest: XCTestCase, XCTestCaseProvider {
3131 }
3232 }
3333
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+
3453 func testContainSubstring( ) {
3554 expect ( " foo " ) . to ( contain ( " o " ) )
3655 expect ( " foo " ) . to ( contain ( " oo " ) )
@@ -83,3 +102,23 @@ final class ContainTest: XCTestCase, XCTestCaseProvider {
83102 }
84103 }
85104}
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