Skip to content

Commit

Permalink
Fix Formatted parser (#301)
Browse files Browse the repository at this point in the history
* Fix `Formatted` parser

It should only consume the match range.

* wip
  • Loading branch information
stephencelis authored May 26, 2023
1 parent 01ded17 commit 27c941b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/Parsing/ParserPrinters/ParseableFormatStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
at: input
)
}
input.removeFirst(input.distance(from: input.startIndex, to: input.endIndex))
input.removeFirst(input.distance(from: match.range.lowerBound, to: match.range.upperBound))
return match.output
}

Expand Down
10 changes: 10 additions & 0 deletions Tests/ParsingTests/ParseableFormatTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,15 @@
"TOTAL: $42.42"
)
}

func testFormatted_PartiallyConsumes() throws {
var input = "COORD: 12.34°N"[...]
let p = Parse {
"COORD: "
Formatted(.number)
}
XCTAssertEqual(12.34, try p.parse(&input))
XCTAssertEqual(String(input), "°N")
}
}
#endif

0 comments on commit 27c941b

Please sign in to comment.