Skip to content

Support xfail #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@ public struct RegexConsumer<Consumed: BidirectionalCollection>
// TODO: consider let, for now lets us toggle tracing
var vm: Executor

// FIXME: Possibility of fatal error isn't user friendly
public init<Capture>(_ regex: Regex<Capture>) {
self.vm = .init(program: try! Compiler(ast: regex.ast).emit())
do {
self.vm = .init(program: try Compiler(ast: regex.ast).emit())
} catch {
fatalError("error: \(error)")
}
}

public init(parsing regex: String) throws {
self.vm = try _compileRegex(regex)
}

func _consuming(
Expand Down
2 changes: 1 addition & 1 deletion Sources/_StringProcessing/Compiler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class Compiler {
(.upToN, _),
(.range, _),
(_, .possessive):
fatalError("Not yet supported")
throw unsupported("\(quant._dumpBase)")
}
}
}
Expand Down
26 changes: 15 additions & 11 deletions Tests/RegexTests/MatchTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@ func matchTest(
dumpAST: Bool = false,
xfail: Bool = false
) {
guard !xfail else {
// XCTExpectFailure {
// XCTFail()
// }
do {
var consumer = try RegexConsumer<String>(parsing: regex)
consumer.vm.engine.enableTracing = enableTracing
guard let range = input.firstRange(of: consumer) else {
throw "expect xfail"
}

if xfail {
XCTAssertNotEqual(String(input[range]), match)
} else {
XCTAssertEqual(String(input[range]), match)
}
} catch {
XCTAssert(xfail)
return
}

let pattern = try! Regex(regex)
var consumer = RegexConsumer<String>(pattern)
consumer.vm.engine.enableTracing = enableTracing
let range = input.firstRange(of: consumer)!
XCTAssertEqual(String(input[range]), match)
}

extension RegexTests {
Expand Down Expand Up @@ -120,7 +124,7 @@ extension RegexTests {
matchTest(
#"a{2,}"#, input: "123aaaxyz", match: "aaa", xfail: true)
matchTest(
#"a{1}"#, input: "123aaaxyz", match: "a", xfail: true)
#"a{1}"#, input: "123aaaxyz", match: "a")
matchTest(
#"a{1,2}?"#, input: "123aaaxyz", match: "a", xfail: true)
matchTest(
Expand Down