Require workouts to have a name
This commit is contained in:
parent
07bb22bcf2
commit
8e813276ad
|
|
@ -1,14 +1,13 @@
|
|||
import { parse } from ".";
|
||||
|
||||
describe("Parser", () => {
|
||||
it("parses empty workout file", () => {
|
||||
expect(parse("")).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"author": "",
|
||||
"description": "",
|
||||
"intervals": Array [],
|
||||
"name": "",
|
||||
}
|
||||
`);
|
||||
it("throws error for empty file", () => {
|
||||
expect(() => parse("")).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Workout is missing a name. Use \`Name:\` to declare one."`
|
||||
);
|
||||
|
||||
expect(() => parse(" \n \n \t")).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Workout is missing a name. Use \`Name:\` to declare one."`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -107,8 +107,13 @@ const parseIntervals = (tokens: Token[]): Interval[] => {
|
|||
|
||||
export const parseTokens = (tokens: Token[]): Workout => {
|
||||
const [header, intervalTokens] = parseHeader(tokens);
|
||||
|
||||
if (header.name === undefined) {
|
||||
throw new Error("Workout is missing a name. Use `Name:` to declare one.");
|
||||
}
|
||||
|
||||
return {
|
||||
name: header.name || "",
|
||||
name: header.name,
|
||||
author: header.author || "",
|
||||
description: header.description || "",
|
||||
intervals: parseIntervals(intervalTokens),
|
||||
|
|
|
|||
Loading…
Reference in New Issue