-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathFilterTests.swift
46 lines (40 loc) · 1.27 KB
/
FilterTests.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
import Parsing
import XCTest
final class FilterTests: XCTestCase {
func testSuccess() {
var input = "42 Hello, world!"[...].utf8
XCTAssertEqual(42, try Int.parser().filter { $0.isMultiple(of: 2) }.parse(&input))
XCTAssertEqual(" Hello, world!", Substring(input))
}
func testFailure() {
var input = "43 Hello, world!"[...].utf8
XCTAssertThrowsError(try Int.parser().filter { $0.isMultiple(of: 2) }.parse(&input)) { error in
XCTAssertEqual(
"""
error: processed value 43 failed to satisfy predicate
--> input:1:1-2
1 | 43 Hello, world!
| ^^ processed input
""",
"\(error)"
)
}
XCTAssertEqual(" Hello, world!", Substring(input))
}
func testOverloadArray() {
let array = [1].filter { _ in true }
XCTAssert(type(of: array) == Array<Int>.self)
}
func testOverloadString() {
let array = "abc".filter { _ in true }
XCTAssert(type(of: array) == String.self)
}
func testOverloadUnicodeScalars() {
let array = "abc".unicodeScalars.filter { _ in true }
XCTAssert(type(of: array) == String.UnicodeScalarView.self)
}
func testOverloadUTF8View() {
let array = "abc".utf8.filter { _ in true }
XCTAssert(type(of: array) == [String.UTF8View.Element].self)
}
}