-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathRestTests.swift
63 lines (53 loc) · 1.54 KB
/
RestTests.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
import Parsing
import XCTest
final class RestTests: XCTestCase {
func testParseRest() {
var input = "Hello, world!"[...]
XCTAssertEqual("Hello, world!", try Rest().parse(&input))
XCTAssertEqual("", input)
}
func testParseRestFailsOnEmpty() {
var input = ""[...]
XCTAssertThrowsError(try Rest().parse(&input)) { error in
XCTAssertEqual(
"""
error: unexpected input
--> input:1:1
1 |
| ^ expected a non-empty input
""",
"\(error)"
)
}
XCTAssertEqual("", input)
}
func testPrintRest() {
XCTAssertEqual(try Rest().print("Hello"[...]), "Hello")
}
func testPrintRestFailsOnUpcoming() throws {
var input = ", World!"[...]
XCTAssertThrowsError(try Rest().print("Hello", into: &input)) { error in
XCTAssertEqual(
"""
error: round-trip expectation failed
A "Rest" parser-printer expected to have printed all remaining input, but more was printed.
", World!"
During a round-trip, the "Rest" parser-printer would have parsed this remaining input.
""",
"\(error)"
)
}
}
func testPrintRestFailsOnEmpty() throws {
XCTAssertThrowsError(try Rest().print(""[...])) { error in
XCTAssertEqual(
"""
error: round-trip expectation failed
A "Rest" parser-printer attempted to print an empty Substring.
During a round-trip, the "Rest" parser-printer would have failed to parse an empty input.
""",
"\(error)"
)
}
}
}