-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathPrefixThroughTests.swift
60 lines (54 loc) · 1.49 KB
/
PrefixThroughTests.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
import Parsing
import XCTest
final class PrefixThroughTests: XCTestCase {
func testSuccess() {
var input = "Hello,world, 42!"[...]
XCTAssertEqual("Hello,world, ", try PrefixThrough(", ").parse(&input))
XCTAssertEqual("42!", input)
}
func testSuccessIsEmpty() {
var input = "Hello, world!"[...]
XCTAssertEqual("", try PrefixThrough("").parse(&input))
XCTAssertEqual("Hello, world!", input)
}
func testFailureIsEmpty() {
var input = ""[...]
XCTAssertThrowsError(try PrefixThrough(", ").parse(&input)) { error in
XCTAssertEqual(
"""
error: unexpected input
--> input:1:1
1 |
| ^ expected prefix through ", "
""",
"\(error)"
)
}
XCTAssertEqual("", input)
}
func testFailureNoMatch() {
var input = "Hello world!"[...]
XCTAssertThrowsError(try PrefixThrough(", ").parse(&input)) { error in
XCTAssertEqual(
"""
error: unexpected input
--> input:1:1
1 | Hello world!
| ^ expected prefix through ", "
""",
"\(error)"
)
}
XCTAssertEqual("Hello world!", input)
}
func testUTF8() {
var input = "Hello,world, 42!"[...].utf8
XCTAssertEqual("Hello,world, ", Substring(try PrefixThrough(", ".utf8).parse(&input)))
XCTAssertEqual("42!", Substring(input))
}
func testPrint() throws {
var input = ""[...]
try PrefixThrough(",").print("Hello,", into: &input)
XCTAssertEqual("Hello,", input)
}
}