Skip to content

Commit

Permalink
Added multi-line test
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeboone02 committed Feb 12, 2021
1 parent a068653 commit 3e9af7e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,23 @@ it('works', () => {
isGroupHeader: true,
},
]);
expect(
parseIngredient(`2/3 cup sugar
1 tsp baking powder`)
).toEqual([
{
quantity: 0.667,
quantity2: null,
unitOfMeasure: 'cup',
description: 'sugar',
isGroupHeader: false,
},
{
quantity: 1,
quantity2: null,
unitOfMeasure: 'tsp',
description: 'baking powder',
isGroupHeader: false,
},
]);
});
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ const parseIngredient = (ingText: string): Ingredient[] => {
if (isNaN(nqResult)) {
oIng.description = arrRaw[i];

// If the line ends in ":" or starts with "For ", then it is assumed to be a group header.
// If the line ends with ":" or starts with "For ", then it is assumed to be a group header.
if (
oIng.description.substring(oIng.description.length - 1) === ':' ||
oIng.description.substring(0, 4).toUpperCase() === 'FOR '
oIng.description.endsWith(':') ||
oIng.description.toUpperCase().startsWith('FOR ')
) {
oIng.isGroupHeader = true;
}
Expand Down

0 comments on commit 3e9af7e

Please sign in to comment.