-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathCompactMapTests.swift
51 lines (45 loc) · 1.23 KB
/
CompactMapTests.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
import Parsing
import XCTest
final class CompactMapTests: XCTestCase {
func testSuccess() {
var input = "FF0000"[...]
XCTAssertEqual(
0xFF,
try Prefix(2).compactMap { Int(String($0), radix: 16) }.parse(&input)
)
XCTAssertEqual("0000", Substring(input))
}
func testFailure() {
var input = "GG0000"[...]
XCTAssertThrowsError(
try Prefix(2).compactMap { Int(String($0), radix: 16) }.parse(&input)
) { error in
XCTAssertEqual(
"""
error: failed to process "Int" from "GG"
--> input:1:1-2
1 | GG0000
| ^^
""",
"\(error)"
)
}
XCTAssertEqual("0000", Substring(input))
}
func testOverloadArray() {
let array = [1].compactMap { "\($0)" }
XCTAssert(type(of: array) == Array<String>.self)
}
func testOverloadString() {
let array = "abc".compactMap { "\($0)" }
XCTAssert(type(of: array) == Array<String>.self)
}
func testOverloadUnicodeScalars() {
let array = "abc".unicodeScalars.compactMap { "\($0)" }
XCTAssert(type(of: array) == Array<String>.self)
}
func testOverloadUTF8View() {
let array = "abc".utf8.compactMap { "\($0)" }
XCTAssert(type(of: array) == Array<String>.self)
}
}