forked from Quick/Nimble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBeginWithPrefixTest.swift
64 lines (49 loc) · 2.49 KB
/
BeginWithPrefixTest.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import Foundation
import Nimble
import XCTest
final class BeginWithPrefixTest: XCTestCase {
func testBeginWithSequencePrefix() {
failsWithErrorMessageForNil("expected to begin with <nil>, got <nil>") {
expect(nil as [Int]?).to(beginWith(prefix: nil as [Int]?))
}
failsWithErrorMessageForNil("expected to begin with <[1, 2]>, got <nil>") {
expect(nil as [Int]?).to(beginWith(prefix: [1, 2]))
}
failsWithErrorMessageForNil("expected to begin with <nil>, got <[1, 2]>") {
expect([1, 2]).to(beginWith(prefix: nil as [Int]?))
}
let sequence = [1, 2, 3]
expect(sequence).toNot(beginWith(prefix: [1, 2, 3, 4]))
expect(sequence).toNot(beginWith(prefix: [2, 3]))
expect(sequence).to(beginWith(prefix: [1, 2, 3]))
expect(sequence).to(beginWith(prefix: [1, 2]))
expect(sequence).to(beginWith(prefix: []))
expect([]).toNot(beginWith(prefix: [1]))
expect([]).to(beginWith(prefix: [] as [Int]))
}
func testBeginWithSequencePrefixUsingPredicateClosure() {
failsWithErrorMessageForNil("expected to begin with <nil>, got <nil>") {
expect(nil as [Int]?).to(beginWith(prefix: nil as [Int]?, by: { $0 == $1 }))
}
failsWithErrorMessageForNil("expected to begin with <[1, 2]>, got <nil>") {
expect(nil as [Int]?).to(beginWith(prefix: [1, 2], by: { $0 == $1 }))
}
failsWithErrorMessageForNil("expected to begin with <nil>, got <[1, 2]>") {
expect([1, 2]).to(beginWith(prefix: nil as [Int]?, by: { $0 == $1 }))
}
let sequence = [1, 2, 3]
expect(sequence).toNot(beginWith(prefix: [1, 2, 3, 4], by: { $0 == $1 }))
expect(sequence).toNot(beginWith(prefix: [2, 3], by: { $0 == $1 }))
expect(sequence).to(beginWith(prefix: [1, 2, 3], by: { $0 == $1 }))
expect(sequence).to(beginWith(prefix: [1, 2], by: { $0 == $1 }))
expect(sequence).to(beginWith(prefix: [], by: { $0 == $1 }))
expect([]).toNot(beginWith(prefix: [1], by: { $0 == $1 }))
expect([]).to(beginWith(prefix: [] as [Int], by: { $0 == $1 }))
}
func testBeginWithSequencePrefixWithDifferentSequenceTypes() {
expect(1...3).to(beginWith(prefix: [1, 2, 3]))
expect(1...3).toNot(beginWith(prefix: [1, 2, 3, 4, 5]))
expect(1...3).to(beginWith(prefix: [1, 2, 3], by: { $0 == $1 }))
expect(1...3).toNot(beginWith(prefix: [1, 2, 3, 4, 5], by: { $0 == $1 }))
}
}