Allow any interval type to be without power target

This commit is contained in:
Rene Saarsoo 2020-10-06 13:19:35 +03:00
parent 3efb8b0c88
commit 265ae5db1b
3 changed files with 24 additions and 10 deletions

View File

@ -113,7 +113,6 @@ console.log(stats(workout));
- Unsupported params: message duration & y-position - Unsupported params: message duration & y-position
- More restricted syntax for text (with quotes) - More restricted syntax for text (with quotes)
- Support for tags - Support for tags
- Allow skipping power target of any interval, switching it to FreeIntensity.
[zwift]: https://zwift.com/ [zwift]: https://zwift.com/
[zwofactory]: https://zwofactory.com/ [zwofactory]: https://zwofactory.com/

View File

@ -239,15 +239,34 @@ FreeRide: 5:00
`); `);
}); });
it("Treats any interval without intensity as a free-ride interval", () => {
expect(
parse(`
Name: My Workout
Interval: 5:00
`).intervals,
).toMatchInlineSnapshot(`
Array [
Object {
"cadence": undefined,
"comments": Array [],
"duration": Duration {
"seconds": 300,
},
"intensity": FreeIntensity {},
"type": "Interval",
},
]
`);
});
const parseInterval = (interval: string) => parse(`Name: My Workout\n${interval}`).intervals[0]; const parseInterval = (interval: string) => parse(`Name: My Workout\n${interval}`).intervals[0];
it("requires duration and power parameters to be specified", () => { it("requires duration parameter to be specified", () => {
expect(() => parseInterval("Interval: 50%")).toThrowErrorMatchingInlineSnapshot( expect(() => parseInterval("Interval: 50%")).toThrowErrorMatchingInlineSnapshot(
`"Duration not specified at line 2 char 1"`, `"Duration not specified at line 2 char 1"`,
); );
expect(() => parseInterval("Interval: 30:00")).toThrowErrorMatchingInlineSnapshot(
`"Power not specified at line 2 char 1"`,
);
expect(() => parseInterval("Interval: 10rpm")).toThrowErrorMatchingInlineSnapshot( expect(() => parseInterval("Interval: 10rpm")).toThrowErrorMatchingInlineSnapshot(
`"Duration not specified at line 2 char 1"`, `"Duration not specified at line 2 char 1"`,
); );

View File

@ -106,11 +106,7 @@ const parseIntervalParams = (type: IntervalType, tokens: Token[], loc: SourceLoc
throw new ParseError("Duration not specified", loc); throw new ParseError("Duration not specified", loc);
} }
if (!intensity) { if (!intensity) {
if (type === "FreeRide") { intensity = new FreeIntensity();
intensity = new FreeIntensity();
} else {
throw new ParseError("Power not specified", loc);
}
} }
const [comments, rest] = parseIntervalComments(tokens); const [comments, rest] = parseIntervalComments(tokens);