|
14 | 14 | import XCTest
|
15 | 15 | @testable import _StringProcessing
|
16 | 16 |
|
17 |
| -func diagnose( |
18 |
| - _ input: String, |
19 |
| - expecting expected: ParseError, |
20 |
| - _ syntax: SyntaxOptions = .traditional, |
21 |
| - _ f: (inout Source) throws -> (), |
22 |
| - file: StaticString = #file, |
23 |
| - line: UInt = #line |
24 |
| -) { |
25 |
| - var src = Source(input) |
26 |
| - do { |
27 |
| - try f(&src) |
28 |
| - XCTFail(""" |
29 |
| - Passed, but expected error: \(expected) |
30 |
| - """, file: file, line: line) |
31 |
| - } catch let e as Source.LocatedError<ParseError> { |
32 |
| - guard e.error == expected else { |
33 |
| - XCTFail(""" |
34 |
| -
|
35 |
| - Expected: \(expected) |
36 |
| - Actual: \(e.error) |
37 |
| - """, file: file, line: line) |
38 |
| - return |
39 |
| - } |
40 |
| - } catch let e { |
41 |
| - fatalError("Should be unreachable: \(e)") |
42 |
| - } |
43 |
| -} |
44 |
| - |
45 | 17 | extension RegexTests {
|
46 |
| - func testLexicalAnalysis() { |
47 |
| - diagnose("a", expecting: .expected("b")) { src in |
48 |
| - try src.expect("b") |
49 |
| - } |
50 |
| - |
51 |
| - diagnose("", expecting: .unexpectedEndOfInput) { src in |
52 |
| - try src.expectNonEmpty() |
53 |
| - } |
54 |
| - diagnose("a", expecting: .unexpectedEndOfInput) { src in |
55 |
| - try src.expect("a") // Ok |
56 |
| - try src.expectNonEmpty() // Error |
57 |
| - } |
58 |
| - |
59 |
| - let bigNum = "12345678901234567890" |
60 |
| - diagnose(bigNum, expecting: .numberOverflow(bigNum)) { src in |
61 |
| - _ = try src.lexNumber() |
62 |
| - } |
63 |
| - |
64 |
| - func diagnoseUniScalarOverflow(_ input: String, base: Character) { |
65 |
| - let scalars = input.first == "{" |
66 |
| - ? String(input.dropFirst().dropLast()) |
67 |
| - : input |
68 |
| - diagnose( |
69 |
| - input, |
70 |
| - expecting: .numberOverflow(scalars) |
71 |
| - ) { src in |
72 |
| - _ = try src.expectUnicodeScalar(escapedCharacter: base) |
73 |
| - } |
74 |
| - } |
75 |
| - func diagnoseUniScalar( |
76 |
| - _ input: String, |
77 |
| - base: Character, |
78 |
| - expectedDigits numDigits: Int |
79 |
| - ) { |
80 |
| - let scalars = input.first == "{" |
81 |
| - ? String(input.dropFirst().dropLast()) |
82 |
| - : input |
83 |
| - diagnose( |
84 |
| - input, |
85 |
| - expecting: .expectedNumDigits(scalars, numDigits) |
86 |
| - ) { src in |
87 |
| - _ = try src.expectUnicodeScalar(escapedCharacter: base) |
88 |
| - } |
89 |
| - _ = scalars |
90 |
| - } |
91 |
| - |
92 |
| - diagnoseUniScalar( |
93 |
| - "12", base: "u", expectedDigits: 4) |
94 |
| - diagnoseUniScalar( |
95 |
| - "12", base: "U", expectedDigits: 8) |
96 |
| - diagnoseUniScalarOverflow("{123456789}", base: "u") |
97 |
| - diagnoseUniScalarOverflow("{123456789}", base: "x") |
98 |
| - |
99 |
| - // TODO: want to dummy print out source ranges, etc, test that. |
100 |
| - } |
101 |
| - |
102 | 18 |
|
103 | 19 | func testCompilerInterface() throws {
|
104 | 20 | func delim(_ kind: Delimiter.Kind, poundCount: Int = 0) -> Delimiter {
|
|
0 commit comments