Skip to content

Commit 4799fcc

Browse files
committed
fix: range quantities incorrectly parsed as text
1 parent 10cc9cd commit 4799fcc

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/regex.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ export const rangeRegex = createRegex()
191191
.digit().oneOrMore()
192192
.endGroup().optional()
193193
.literal("-")
194+
.digit().oneOrMore()
194195
.startGroup()
195196
.anyOf(".,/").exactly(1)
196197
.digit().oneOrMore()

test/parser_helpers.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,3 +439,29 @@ describe("parseFixedValue", () => {
439439
expect(parseFixedValue("1")).toEqual({ type: "decimal", value: 1 });
440440
});
441441
});
442+
443+
describe("parseQuantityInput", () => {
444+
it("correctly parses ranges", () => {
445+
expect(parseQuantityInput("1-2")).toEqual({
446+
type: "range",
447+
min: { type: "decimal", value: 1 },
448+
max: { type: "decimal", value: 2 },
449+
});
450+
expect(parseQuantityInput("1/2-1")).toEqual({
451+
type: "range",
452+
min: { type: "fraction", num: 1, den: 2 },
453+
max: { type: "decimal", value: 1 },
454+
});
455+
});
456+
457+
it("correctly parses fixed values", () => {
458+
expect(parseQuantityInput("1")).toEqual({
459+
type: "fixed",
460+
value: { type: "decimal", value: 1 },
461+
});
462+
expect(parseQuantityInput("1.2")).toEqual({
463+
type: "fixed",
464+
value: { type: "decimal", value: 1.2 },
465+
});
466+
});
467+
});

0 commit comments

Comments
 (0)