Skip to content

Commit 24870f5

Browse files
authored
Merge pull request #138 from hamishknight/its-the-time-but-not-the-place
2 parents b402e39 + bab974c commit 24870f5

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

Sources/_MatchingEngine/Regex/Parse/SourceLocation.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,11 @@ extension AST {
110110
}
111111
extension AST.Located: Equatable where T: Equatable {}
112112
extension AST.Located: Hashable where T: Hashable {}
113+
114+
extension Source.LocatedError: CustomStringConvertible {
115+
public var description: String {
116+
// Just return the underlying error's description, which is currently how
117+
// we present the message to the compiler.
118+
"\(error)"
119+
}
120+
}

Tests/RegexTests/ParseTests.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,26 @@ func diagnosticTest(
195195
}
196196
}
197197

198+
func libswiftDiagnosticMessageTest(
199+
_ input: String, _ expectedErr: String, file: StaticString = #file,
200+
line: UInt = #line
201+
) {
202+
var errPtr: UnsafePointer<CChar>?
203+
var version: CUnsignedInt = 0
204+
205+
libswiftParseRegexLiteral(
206+
input, &errPtr, &version, /*captureStructure*/ nil,
207+
/*captureStructureSize*/ 0
208+
)
209+
210+
guard let errPtr = errPtr else {
211+
XCTFail("Unexpected test pass", file: file, line: line)
212+
return
213+
}
214+
let err = String(cString: errPtr)
215+
XCTAssertEqual(expectedErr, err, file: file, line: line)
216+
}
217+
198218
extension RegexTests {
199219
func testParse() {
200220
parseTest(
@@ -1855,4 +1875,9 @@ extension RegexTests {
18551875
// TODO: This diagnostic could be better.
18561876
diagnosticTest("(*LIMIT_DEPTH=-1", .expectedNumber("", kind: .decimal))
18571877
}
1878+
1879+
func testlibswiftDiagnostics() {
1880+
libswiftDiagnosticMessageTest(
1881+
"'/[x*/'", "cannot parse regular expression: expected ']'")
1882+
}
18581883
}

0 commit comments

Comments
 (0)