Skip to content

Commit 27c941b

Browse files
authored
Fix Formatted parser (#301)
* Fix `Formatted` parser It should only consume the match range. * wip
1 parent 01ded17 commit 27c941b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Sources/Parsing/ParserPrinters/ParseableFormatStyle.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
at: input
2525
)
2626
}
27-
input.removeFirst(input.distance(from: input.startIndex, to: input.endIndex))
27+
input.removeFirst(input.distance(from: match.range.lowerBound, to: match.range.upperBound))
2828
return match.output
2929
}
3030

Tests/ParsingTests/ParseableFormatTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,15 @@
1919
"TOTAL: $42.42"
2020
)
2121
}
22+
23+
func testFormatted_PartiallyConsumes() throws {
24+
var input = "COORD: 12.34°N"[...]
25+
let p = Parse {
26+
"COORD: "
27+
Formatted(.number)
28+
}
29+
XCTAssertEqual(12.34, try p.parse(&input))
30+
XCTAssertEqual(String(input), "°N")
31+
}
2232
}
2333
#endif

0 commit comments

Comments
 (0)