Allow untitled workouts
This commit is contained in:
parent
adebc3d460
commit
0d6f61913c
|
|
@ -1,14 +1,24 @@
|
|||
import { parse } from ".";
|
||||
|
||||
describe("Parser", () => {
|
||||
it("throws error for empty file", () => {
|
||||
expect(() => parse("")).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Workout is missing a name. Use \`Name:\` to declare one. at line 1 char 1"`,
|
||||
);
|
||||
it("creates Untitled workout from empty file", () => {
|
||||
expect(parse("")).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"author": "",
|
||||
"description": "",
|
||||
"intervals": Array [],
|
||||
"name": "Untitled",
|
||||
}
|
||||
`);
|
||||
|
||||
expect(() => parse(" \n \n \t")).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Workout is missing a name. Use \`Name:\` to declare one. at line 1 char 1"`,
|
||||
);
|
||||
expect(parse(" \n \n \t")).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"author": "",
|
||||
"description": "",
|
||||
"intervals": Array [],
|
||||
"name": "Untitled",
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it("parses workout with just Name field", () => {
|
||||
|
|
|
|||
|
|
@ -138,12 +138,8 @@ const parseIntervals = (tokens: Token[]): Interval[] => {
|
|||
export const parseTokens = (tokens: Token[]): Workout => {
|
||||
const [header, intervalTokens] = parseHeader(tokens);
|
||||
|
||||
if (header.name === undefined) {
|
||||
throw new ParseError("Workout is missing a name. Use `Name:` to declare one.", { row: 0, col: 0 });
|
||||
}
|
||||
|
||||
return {
|
||||
name: header.name,
|
||||
name: header.name || "Untitled",
|
||||
author: header.author || "",
|
||||
description: header.description || "",
|
||||
intervals: parseIntervals(intervalTokens),
|
||||
|
|
|
|||
Loading…
Reference in New Issue