File tree Expand file tree Collapse file tree 2 files changed +36
-4
lines changed
Tests/NimbleTests/Matchers Expand file tree Collapse file tree 2 files changed +36
-4
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,21 @@ public func beNil<T>() -> Predicate<T> {
6
6
}
7
7
}
8
8
9
+ extension Expectation {
10
+ /// Represents `nil` value to be used with the operator overloads for `beNil`.
11
+ public struct Nil : ExpressibleByNilLiteral {
12
+ public init ( nilLiteral: ( ) ) { }
13
+ }
14
+
15
+ public static func == ( lhs: Expectation , rhs: Expectation . Nil ) {
16
+ lhs. to ( beNil ( ) )
17
+ }
18
+
19
+ public static func != ( lhs: Expectation , rhs: Expectation . Nil ) {
20
+ lhs. toNot ( beNil ( ) )
21
+ }
22
+ }
23
+
9
24
#if canImport(Darwin)
10
25
import Foundation
11
26
Original file line number Diff line number Diff line change @@ -8,15 +8,32 @@ final class BeNilTest: XCTestCase {
8
8
9
9
func testBeNil( ) {
10
10
expect ( nil as Int ? ) . to ( beNil ( ) )
11
+ expect ( nil as Int ? ) == nil
12
+
11
13
expect ( 1 as Int ? ) . toNot ( beNil ( ) )
14
+ expect ( 1 as Int ? ) != nil
15
+
12
16
expect ( self . producesNil ( ) ) . to ( beNil ( ) )
17
+ expect ( self . producesNil ( ) ) == nil
13
18
14
- failsWithErrorMessage ( " expected to not be nil, got <nil> " ) {
15
- expect ( nil as Int ? ) . toNot ( beNil ( ) )
19
+ do {
20
+ let message = " expected to not be nil, got <nil> "
21
+ failsWithErrorMessage ( message) {
22
+ expect ( nil as Int ? ) . toNot ( beNil ( ) )
23
+ }
24
+ failsWithErrorMessage ( message) {
25
+ expect ( nil as Int ? ) != nil
26
+ }
16
27
}
17
28
18
- failsWithErrorMessage ( " expected to be nil, got <1> " ) {
19
- expect ( 1 as Int ? ) . to ( beNil ( ) )
29
+ do {
30
+ let message = " expected to be nil, got <1> "
31
+ failsWithErrorMessage ( message) {
32
+ expect ( 1 as Int ? ) . to ( beNil ( ) )
33
+ }
34
+ failsWithErrorMessage ( message) {
35
+ expect ( 1 as Int ? ) == nil
36
+ }
20
37
}
21
38
}
22
39
}
You can’t perform that action at this time.
0 commit comments