Skip to content

Commit

Permalink
Fixed tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
phlegmaticprogrammer committed Mar 30, 2021
1 parent 2a3008b commit 36fb63f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/phlegmaticprogrammer/EarleyLocalLexing",
"state": {
"branch": null,
"revision": "755d4aa035572deb5245a09ad87570419cce00e9",
"version": "0.6.7"
"revision": "10ea39cd8dc051b2cd1de0d8fde36740facd3ebc",
"version": "0.6.9"
}
},
{
Expand Down
22 changes: 18 additions & 4 deletions Tests/ParsingKitTests/ParsingKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ final class ParsingKitTests: XCTestCase {
XCTAssertEqual("\(s1)", "S[1]")
}

func convertResult<C>(_ p : ParseResult<C>) -> (length: Int, results: [C : ParseTree?])? {
switch p {
case .failed: return nil
case let .success(results: results):
guard results.count == 1 else { return nil }
let (length, rs) = results.first!
return (length: length, results: rs)
}
}

func testUTF8CharLexer() {
let scalars: [UInt8] = [
0xF0, 0x9F, 0x91, 0xA8, // man
Expand All @@ -34,7 +44,8 @@ final class ParsingKitTests: XCTestCase {
var indices = [Int]()
var position = 0
repeat {
guard let result = UTF8CharLexer().lex(input: s, position: position, in: UNIT.singleton) else { break }
let _result = UTF8CharLexer().lex(input: s, position: position, in: UNIT.singleton)
guard let result = convertResult(_result) else { break }
indices.append(result.length)
position += result.length
} while true
Expand All @@ -49,7 +60,8 @@ final class ParsingKitTests: XCTestCase {
let parseResult = parser.parse(input: input, start: calculator.Expr)
switch parseResult {
case .failed: XCTAssert(results.isEmpty)
case let .success(length: length, results: parseResults):
case .success:
let (length, parseResults) = convertResult(parseResult)!
XCTAssertEqual(length, input.count)
XCTAssertEqual(Set(parseResults.keys), Set(results))
}
Expand Down Expand Up @@ -99,7 +111,8 @@ final class ParsingKitTests: XCTestCase {
let parseResult = parser.parse(input: input, start: S)
switch parseResult {
case .failed: XCTAssertFalse(matches)
case let .success(length: length, results: parseResults):
case .success:
let (length, parseResults) = convertResult(parseResult)!
XCTAssertEqual(parseResults.count, 1)
XCTAssertTrue(matches)
XCTAssertEqual(length, input.count)
Expand All @@ -119,7 +132,8 @@ final class ParsingKitTests: XCTestCase {
let parseResult = parser.parse(input: input, start: S)
switch parseResult {
case .failed: XCTAssertFalse(matches)
case let .success(length: length, results: parseResults):
case .success:
let (length, parseResults) = convertResult(parseResult)!
if matches {
XCTAssertEqual(length, input.count)
XCTAssertEqual(parseResults.count, 1)
Expand Down

0 comments on commit 36fb63f

Please sign in to comment.