From 54392306bff42311e099dc73ee8e57133b1196df Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Thu, 24 Sep 2020 11:04:02 +0300 Subject: [PATCH] Correct parsing of intervals after description --- src/parser/parser.test.ts | 67 +++++++++++++++++++++++++++++++++++++++ src/parser/tokenizer.ts | 5 +-- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/src/parser/parser.test.ts b/src/parser/parser.test.ts index c84fda6..8da3c2d 100644 --- a/src/parser/parser.test.ts +++ b/src/parser/parser.test.ts @@ -108,6 +108,73 @@ Rest: 5:00 45% `); }); + it("parses intervals after multi-line description", () => { + expect( + parse(` +Name: My Workout +Author: John Doe +Description: + It's a great workout. + + Do it when you dare, + it'll cause lots of pain. + +Interval: 5:00 50% + +Interval: 10:00 100% + +Interval: 5:00 50% +`), + ).toMatchInlineSnapshot(` + Object { + "author": "John Doe", + "description": "It's a great workout. + + Do it when you dare, + it'll cause lots of pain.", + "intervals": Array [ + Object { + "cadence": undefined, + "comments": Array [], + "duration": Seconds { + "value": 300, + }, + "intensity": Object { + "from": 0.5, + "to": 0.5, + }, + "type": "Interval", + }, + Object { + "cadence": undefined, + "comments": Array [], + "duration": Seconds { + "value": 600, + }, + "intensity": Object { + "from": 1, + "to": 1, + }, + "type": "Interval", + }, + Object { + "cadence": undefined, + "comments": Array [], + "duration": Seconds { + "value": 300, + }, + "intensity": Object { + "from": 0.5, + "to": 0.5, + }, + "type": "Interval", + }, + ], + "name": "My Workout", + } + `); + }); + it("parses power-range intervals", () => { expect( parse(` diff --git a/src/parser/tokenizer.ts b/src/parser/tokenizer.ts index bc4a17e..0dcab21 100644 --- a/src/parser/tokenizer.ts +++ b/src/parser/tokenizer.ts @@ -169,9 +169,10 @@ const isAfterDescription = (tokens: Token[]): boolean => { const token = tokens[i]; if (token.type === "text") { // skip - } - if (token.type === "header" && token.value === "Description") { + } else if (token.type === "header" && token.value === "Description") { return true; + } else { + return false; } } return false;