Allow more whitespace
This commit is contained in:
parent
b18d7ff2a4
commit
a6c5596f02
|
|
@ -137,17 +137,6 @@ Cooldown: 5:30 70%..45%
|
||||||
).toThrowErrorMatchingInlineSnapshot(`"Duration not specified"`);
|
).toThrowErrorMatchingInlineSnapshot(`"Duration not specified"`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("parses correct duration formats", () => {
|
|
||||||
expect(parseInterval("Interval: 0:10 50%").duration).toEqual(10);
|
|
||||||
expect(parseInterval("Interval: 00:10 50%").duration).toEqual(10);
|
|
||||||
expect(parseInterval("Interval: 0:00:10 50%").duration).toEqual(10);
|
|
||||||
expect(parseInterval("Interval: 0:02:05 50%").duration).toEqual(125);
|
|
||||||
expect(parseInterval("Interval: 1:00:00 50%").duration).toEqual(3600);
|
|
||||||
expect(parseInterval("Interval: 1:00:0 50%").duration).toEqual(3600);
|
|
||||||
expect(parseInterval("Interval: 1:0:0 50%").duration).toEqual(3600);
|
|
||||||
expect(parseInterval("Interval: 10:00:00 50%").duration).toEqual(36000);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("allows any order for interval parameters", () => {
|
it("allows any order for interval parameters", () => {
|
||||||
expect(parseInterval("Interval: 50% 00:10")).toMatchInlineSnapshot(`
|
expect(parseInterval("Interval: 50% 00:10")).toMatchInlineSnapshot(`
|
||||||
Object {
|
Object {
|
||||||
|
|
@ -184,6 +173,44 @@ Cooldown: 5:30 70%..45%
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("allows whitespace between interval parameters", () => {
|
||||||
|
expect(parseInterval("Interval: 50% 00:10 100rpm"))
|
||||||
|
.toMatchInlineSnapshot(`
|
||||||
|
Object {
|
||||||
|
"cadence": 100,
|
||||||
|
"duration": 10,
|
||||||
|
"intensity": Object {
|
||||||
|
"from": 0.5,
|
||||||
|
"to": 0.5,
|
||||||
|
},
|
||||||
|
"type": "Interval",
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
expect(parseInterval("Interval: \t 50% \t 00:10 \t\t 100rpm \t"))
|
||||||
|
.toMatchInlineSnapshot(`
|
||||||
|
Object {
|
||||||
|
"cadence": 100,
|
||||||
|
"duration": 10,
|
||||||
|
"intensity": Object {
|
||||||
|
"from": 0.5,
|
||||||
|
"to": 0.5,
|
||||||
|
},
|
||||||
|
"type": "Interval",
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("parses correct duration formats", () => {
|
||||||
|
expect(parseInterval("Interval: 0:10 50%").duration).toEqual(10);
|
||||||
|
expect(parseInterval("Interval: 00:10 50%").duration).toEqual(10);
|
||||||
|
expect(parseInterval("Interval: 0:00:10 50%").duration).toEqual(10);
|
||||||
|
expect(parseInterval("Interval: 0:02:05 50%").duration).toEqual(125);
|
||||||
|
expect(parseInterval("Interval: 1:00:00 50%").duration).toEqual(3600);
|
||||||
|
expect(parseInterval("Interval: 1:00:0 50%").duration).toEqual(3600);
|
||||||
|
expect(parseInterval("Interval: 1:0:0 50%").duration).toEqual(3600);
|
||||||
|
expect(parseInterval("Interval: 10:00:00 50%").duration).toEqual(36000);
|
||||||
|
});
|
||||||
|
|
||||||
it("throws error for incorrect duration formats", () => {
|
it("throws error for incorrect duration formats", () => {
|
||||||
expect(() =>
|
expect(() =>
|
||||||
parseInterval("Interval: 10 50%")
|
parseInterval("Interval: 10 50%")
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ const tokenizeParams = (type: LabelTokenValue, text: string): Token[] => {
|
||||||
case "Rest":
|
case "Rest":
|
||||||
case "Interval":
|
case "Interval":
|
||||||
case "Cooldown":
|
case "Cooldown":
|
||||||
return text.split(" ").map(tokenizeValueParam);
|
return text.split(/\s+/).map(tokenizeValueParam);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue