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