fix(parser): end a preparation at the end of its line #170

Merged
abiwab merged 1 commit from fix/preparation-single-line into main 2026-11-16 23:50:13 +01:00
8 changed files with 1539 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
"@gram-lang/parser": patch
---
**Parser**: Fixed an unclosed parenthesis after an ingredient, a composite parent or cookware (`@flour{200g}(sifted and`) that silently swallowed the rest of the recipe up to the next `)`, steps and sections included. A preparation now ends on its line: an unclosed parenthesis stays in the text of the step, and what follows is read as usual. A preparation spread over two lines of the same step is now read as text too.

View file

@ -0,0 +1,595 @@
{
"title": "Preparation Single Line",
"slug": "preparation-single-line",
"meta": {
"title": "Preparation Single Line"
},
"registry": {
"ingredients": {
"flour": {
"id": "flour",
"name": "flour",
"default_unit": "g"
},
"water": {
"id": "water",
"name": "water",
"default_unit": "ml"
},
"butter": {
"id": "butter",
"name": "butter",
"default_unit": "g"
},
"salt": {
"id": "salt",
"name": "salt"
},
"zest": {
"id": "zest",
"name": "zest",
"is_composite": true,
"parent": "lemon"
},
"lemon": {
"id": "lemon",
"name": "lemon",
"is_composite": true
}
},
"cookware": {
"pan": {
"id": "pan",
"name": "pan"
}
}
},
"shopping_list": [
{
"id": "flour",
"name": "flour",
"_usageIds": [
"1"
],
"qty": 200,
"unit": "g",
"normalizedMass": 200,
"isEstimate": false,
"conversionMethod": "physical"
},
{
"id": "water",
"name": "water",
"_usageIds": [
"2"
],
"qty": 120,
"unit": "ml"
},
{
"id": "butter",
"name": "butter",
"_usageIds": [
"4"
],
"qty": 20,
"unit": "g",
"normalizedMass": 20,
"isEstimate": false,
"conversionMethod": "physical"
},
{
"id": "salt",
"name": "salt",
"_usageIds": [
"5"
]
},
{
"type": "composite",
"id": "lemon",
"name": "lemon",
"qty": 1,
"usage": [
{
"id": "zest",
"qty": 1
}
]
}
],
"cookware": [
{
"id": "pan",
"_usageId": "3",
"qty": 1,
"fixed": false
}
],
"sections": [
{
"title": "Dough",
"ingredients": [
{
"id": "flour",
"_usageId": "1",
"qty": 200,
"unit": "g",
"conversionMethod": "physical",
"isEstimate": false,
"normalizedMass": 200
},
{
"id": "water",
"_usageId": "2",
"qty": 120,
"unit": "ml"
},
{
"id": "butter",
"_usageId": "4",
"qty": 20,
"unit": "g",
"preparation": "soft, cubed",
"conversionMethod": "physical",
"isEstimate": false,
"normalizedMass": 20
}
],
"cookware": [
{
"id": "pan",
"_usageId": "3",
"qty": 1,
"fixed": false
}
],
"steps": [
{
"type": "step",
"content": [
"Mix ",
{
"id": "flour",
"_usageId": "1",
"qty": 200,
"unit": "g",
"normalizedMass": 200,
"conversionMethod": "physical",
"isEstimate": false
},
"(sifted and ",
{
"id": "water",
"_usageId": "2",
"qty": 120,
"unit": "ml"
},
"."
],
"timings": {
"start": 0,
"end": 2,
"activeDuration": 2
}
},
{
"type": "step",
"content": [
"Heat a ",
{
"id": "pan",
"_usageId": "3",
"qty": 1,
"fixed": false
},
"(large over ",
{
"type": "temperature",
"quantity": {
"type": "single",
"value": 180,
"text": "180"
},
"unit": "°C"
},
"."
],
"timings": {
"start": 2,
"end": 4,
"activeDuration": 2
}
},
{
"type": "step",
"content": [
"Knead ",
{
"id": "butter",
"_usageId": "4",
"qty": 20,
"unit": "g",
"preparation": "soft, cubed",
"normalizedMass": 20,
"conversionMethod": "physical",
"isEstimate": false
},
"."
],
"timings": {
"start": 4,
"end": 6,
"activeDuration": 2
}
}
],
"metrics": {
"totalMass": 220,
"massStatus": "incomplete",
"missingMassIngredients": [
"water"
]
}
},
{
"title": "Serve",
"ingredients": [
{
"id": "salt",
"_usageId": "5"
},
{
"id": "zest",
"_usageId": "6",
"qty": 1,
"composite": {
"parent": "lemon",
"quantity": 1
}
}
],
"cookware": [],
"steps": [
{
"type": "step",
"content": [
"Serve with ",
{
"id": "salt",
"_usageId": "5"
},
"(flaky and ",
{
"id": "zest",
"_usageId": "6",
"qty": 1,
"composite": {
"parent": "lemon",
"quantity": 1
}
},
"(organic."
],
"timings": {
"start": 6,
"end": 8,
"activeDuration": 2
}
}
],
"metrics": {
"totalMass": 0,
"massStatus": "incomplete",
"missingMassIngredients": [
"salt",
"zest"
]
}
}
],
"warnings": [
{
"code": "MISSING_INGREDIENT",
"message": "Ingredient \"flour\" not found in database — nutritional metrics and density conversions unavailable."
},
{
"code": "UNKNOWN_MASS",
"message": "Cannot calculate mass for \"water\" — omitted from nutritional totals."
},
{
"code": "MISSING_INGREDIENT",
"message": "Ingredient \"butter\" not found in database — nutritional metrics and density conversions unavailable."
},
{
"code": "UNKNOWN_MASS",
"message": "Cannot calculate mass for \"zest\" — omitted from nutritional totals."
}
],
"metrics": {
"totalTime": 17,
"totalBreakdown": [
{
"label": "section_active:Dough",
"duration": 6
},
{
"label": "section_active:Serve",
"duration": 2
}
],
"idleTime": 0,
"activeTime": 8,
"activeBreakdown": [
{
"label": "section_active:Dough",
"duration": 6
},
{
"label": "section_active:Serve",
"duration": 2
}
],
"preparationTime": 9,
"prepBreakdown": [
{
"label": "ingredients_overhead",
"duration": 6
},
{
"label": "cookware_overhead",
"duration": 1
},
{
"label": "prep_butter",
"duration": 2
}
],
"totalMass": 220,
"massStatus": "incomplete",
"missingMassIngredients": [
"water",
"salt",
"zest"
],
"nutrition": {
"total": {
"calories": 0,
"fat": 0,
"carbs": 0,
"protein": 0
},
"isEstimate": false,
"coverage": 0,
"warnings": [
{
"code": "MISSING_INGREDIENT",
"message": "Ingredient \"flour\" not found in database — nutritional metrics and density conversions unavailable."
},
{
"code": "UNKNOWN_MASS",
"message": "Cannot calculate mass for \"water\" — omitted from nutritional totals."
},
{
"code": "MISSING_INGREDIENT",
"message": "Ingredient \"butter\" not found in database — nutritional metrics and density conversions unavailable."
},
{
"code": "UNKNOWN_MASS",
"message": "Cannot calculate mass for \"zest\" — omitted from nutritional totals."
}
]
}
},
"miseEnPlace": [
{
"section": 0,
"duration": 6,
"items": [
{
"kind": "gather",
"target": "ingredient",
"count": 3,
"duration": 3
},
{
"kind": "gather",
"target": "cookware",
"count": 1,
"duration": 1
},
{
"kind": "prepare",
"ref": {
"type": "ingredient",
"id": "butter"
},
"duration": 2
}
]
},
{
"section": 1,
"duration": 3,
"items": [
{
"kind": "gather",
"target": "ingredient",
"count": 3,
"duration": 3
}
]
}
],
"tasks": {
"tasks": [
{
"id": "s0.prep",
"kind": "prep",
"section": 0,
"duration": {
"nominal": 6
},
"items": [
{
"kind": "gather",
"target": "ingredient",
"count": 3,
"duration": 3
},
{
"kind": "gather",
"target": "cookware",
"count": 1,
"duration": 1
},
{
"kind": "prepare",
"ref": {
"type": "ingredient",
"id": "butter"
},
"duration": 2
}
],
"after": []
},
{
"id": "s0.0",
"kind": "step",
"section": 0,
"step": 0,
"duration": {
"nominal": 2
},
"after": []
},
{
"id": "s0.1",
"kind": "step",
"section": 0,
"step": 1,
"duration": {
"nominal": 2
},
"after": [
"s0.0"
]
},
{
"id": "s0.2",
"kind": "step",
"section": 0,
"step": 2,
"duration": {
"nominal": 2
},
"after": [
"s0.1"
]
},
{
"id": "s1.prep",
"kind": "prep",
"section": 1,
"duration": {
"nominal": 3
},
"items": [
{
"kind": "gather",
"target": "ingredient",
"count": 3,
"duration": 3
}
],
"after": []
},
{
"id": "s1.0",
"kind": "step",
"section": 1,
"step": 0,
"duration": {
"nominal": 2
},
"after": []
}
],
"sections": [
{
"day": 0
},
{
"day": 0
}
]
},
"schedule": {
"miseEnPlace": "perSection",
"rests": "shortest",
"totalTime": 17,
"activeTime": 8,
"preparationTime": 9,
"idleTime": 0,
"blocks": [
{
"kind": "prep",
"task": "s0.prep",
"section": 0,
"start": 0,
"end": 6
},
{
"kind": "step",
"task": "s0.0",
"section": 0,
"step": 0,
"start": 6,
"end": 8
},
{
"kind": "step",
"task": "s0.1",
"section": 0,
"step": 1,
"start": 8,
"end": 10
},
{
"kind": "step",
"task": "s0.2",
"section": 0,
"step": 2,
"start": 10,
"end": 12
},
{
"kind": "prep",
"task": "s1.prep",
"section": 1,
"start": 12,
"end": 15
},
{
"kind": "step",
"task": "s1.0",
"section": 1,
"step": 0,
"start": 15,
"end": 17
}
],
"days": [
{
"day": 0,
"start": 0,
"end": 17,
"sections": [
0,
1
]
}
]
}
}

View file

@ -0,0 +1,339 @@
{
"type": "Recipe",
"meta": {
"title": "Preparation Single Line"
},
"imports": [],
"children": [
{
"type": "Section",
"title": "Dough",
"retroPlanning": null,
"intermediateDecl": null,
"children": [
{
"type": "Step",
"action": null,
"children": [
{
"type": "Text",
"value": "Mix ",
"loc": {
"start": 50,
"end": 54
}
},
{
"type": "Ingredient",
"name": "flour",
"modifiers": [],
"quantity": {
"type": "Quantity",
"value": {
"type": "single",
"value": 200,
"text": "200"
},
"unit": "g",
"fixed": false,
"loc": {
"start": 61,
"end": 65
}
},
"alias": null,
"preparation": null,
"composite": null,
"loc": {
"start": 54,
"end": 66
}
},
{
"type": "Text",
"value": "(sifted and ",
"loc": {
"start": 66,
"end": 78
}
},
{
"type": "Ingredient",
"name": "water",
"modifiers": [],
"quantity": {
"type": "Quantity",
"value": {
"type": "single",
"value": 120,
"text": "120"
},
"unit": "ml",
"fixed": false,
"loc": {
"start": 85,
"end": 90
}
},
"alias": null,
"preparation": null,
"composite": null,
"loc": {
"start": 78,
"end": 91
}
},
{
"type": "Text",
"value": ".",
"loc": {
"start": 91,
"end": 92
}
}
],
"loc": {
"start": 50,
"end": 94
}
},
{
"type": "Step",
"action": null,
"children": [
{
"type": "Text",
"value": "Heat a ",
"loc": {
"start": 94,
"end": 101
}
},
{
"type": "Cookware",
"name": "pan",
"modifiers": [],
"alias": null,
"quantity": {
"type": "Quantity",
"value": {
"type": "single",
"value": 1,
"text": "1"
},
"unit": null,
"fixed": false,
"loc": {
"start": 105,
"end": 108
}
},
"preparation": null,
"loc": {
"start": 101,
"end": 108
}
},
{
"type": "Text",
"value": "(large over ",
"loc": {
"start": 108,
"end": 120
}
},
{
"type": "Temperature",
"name": null,
"loc": {
"start": 120,
"end": 128
},
"value": {
"type": "single",
"value": 180,
"text": "180"
},
"unit": "°C"
},
{
"type": "Text",
"value": ".",
"loc": {
"start": 128,
"end": 129
}
}
],
"loc": {
"start": 94,
"end": 131
}
},
{
"type": "Step",
"action": null,
"children": [
{
"type": "Text",
"value": "Knead ",
"loc": {
"start": 131,
"end": 137
}
},
{
"type": "Ingredient",
"name": "butter",
"modifiers": [],
"quantity": {
"type": "Quantity",
"value": {
"type": "single",
"value": 20,
"text": "20"
},
"unit": "g",
"fixed": false,
"loc": {
"start": 145,
"end": 148
}
},
"alias": null,
"preparation": "soft, cubed",
"composite": null,
"loc": {
"start": 137,
"end": 162
}
},
{
"type": "Text",
"value": ".",
"loc": {
"start": 162,
"end": 163
}
}
],
"loc": {
"start": 131,
"end": 165
}
}
],
"loc": {
"start": 40,
"end": 165
}
},
{
"type": "Section",
"title": "Serve",
"retroPlanning": null,
"intermediateDecl": null,
"children": [
{
"type": "Step",
"action": null,
"children": [
{
"type": "Text",
"value": "Serve with ",
"loc": {
"start": 175,
"end": 186
}
},
{
"type": "Ingredient",
"name": "salt",
"modifiers": [],
"quantity": null,
"alias": null,
"preparation": null,
"composite": null,
"loc": {
"start": 186,
"end": 191
}
},
{
"type": "Text",
"value": "(flaky and ",
"loc": {
"start": 191,
"end": 202
}
},
{
"type": "Ingredient",
"name": "zest",
"modifiers": [],
"quantity": {
"type": "Quantity",
"value": {
"type": "single",
"value": 1,
"text": "1"
},
"unit": null,
"fixed": false,
"loc": {
"start": 208,
"end": 209
}
},
"alias": null,
"preparation": null,
"composite": {
"type": "Composite",
"parent": "lemon",
"quantity": {
"type": "Quantity",
"value": {
"type": "single",
"value": 1,
"text": "1"
},
"unit": null,
"fixed": false,
"loc": {
"start": 218,
"end": 219
}
},
"preparation": null,
"loc": {
"start": 210,
"end": 220
}
},
"loc": {
"start": 202,
"end": 220
}
},
{
"type": "Text",
"value": "(organic.",
"loc": {
"start": 220,
"end": 229
}
}
],
"loc": {
"start": 175,
"end": 230
}
}
],
"loc": {
"start": 165,
"end": 230
}
}
]
}

View file

@ -0,0 +1,510 @@
{
"title": "Preparation Single Line",
"slug": "preparation-single-line",
"meta": {
"title": "Preparation Single Line"
},
"registry": {
"ingredients": {
"flour": {
"id": "flour",
"name": "flour",
"default_unit": "g"
},
"water": {
"id": "water",
"name": "water",
"default_unit": "ml"
},
"butter": {
"id": "butter",
"name": "butter",
"default_unit": "g"
},
"salt": {
"id": "salt",
"name": "salt"
},
"zest": {
"id": "zest",
"name": "zest",
"is_composite": true,
"parent": "lemon"
},
"lemon": {
"id": "lemon",
"name": "lemon",
"is_composite": true
}
},
"cookware": {
"pan": {
"id": "pan",
"name": "pan"
}
}
},
"shopping_list": [
{
"id": "flour",
"name": "flour",
"_usageIds": [
"1"
],
"qty": 200,
"unit": "g"
},
{
"id": "water",
"name": "water",
"_usageIds": [
"2"
],
"qty": 120,
"unit": "ml"
},
{
"id": "butter",
"name": "butter",
"_usageIds": [
"4"
],
"qty": 20,
"unit": "g"
},
{
"id": "salt",
"name": "salt",
"_usageIds": [
"5"
]
},
{
"type": "composite",
"id": "lemon",
"name": "lemon",
"qty": 1,
"usage": [
{
"id": "zest",
"qty": 1
}
]
}
],
"cookware": [
{
"id": "pan",
"_usageId": "3",
"qty": 1,
"fixed": false
}
],
"sections": [
{
"title": "Dough",
"ingredients": [
{
"id": "flour",
"_usageId": "1",
"qty": 200,
"unit": "g"
},
{
"id": "water",
"_usageId": "2",
"qty": 120,
"unit": "ml"
},
{
"id": "butter",
"_usageId": "4",
"qty": 20,
"unit": "g",
"preparation": "soft, cubed"
}
],
"cookware": [
{
"id": "pan",
"_usageId": "3",
"qty": 1,
"fixed": false
}
],
"steps": [
{
"type": "step",
"content": [
"Mix ",
{
"id": "flour",
"_usageId": "1",
"qty": 200,
"unit": "g"
},
"(sifted and ",
{
"id": "water",
"_usageId": "2",
"qty": 120,
"unit": "ml"
},
"."
],
"timings": {
"start": 0,
"end": 2,
"activeDuration": 2
}
},
{
"type": "step",
"content": [
"Heat a ",
{
"id": "pan",
"_usageId": "3",
"qty": 1,
"fixed": false
},
"(large over ",
{
"type": "temperature",
"quantity": {
"type": "single",
"value": 180,
"text": "180"
},
"unit": "°C"
},
"."
],
"timings": {
"start": 2,
"end": 4,
"activeDuration": 2
}
},
{
"type": "step",
"content": [
"Knead ",
{
"id": "butter",
"_usageId": "4",
"qty": 20,
"unit": "g",
"preparation": "soft, cubed"
},
"."
],
"timings": {
"start": 4,
"end": 6,
"activeDuration": 2
}
}
]
},
{
"title": "Serve",
"ingredients": [
{
"id": "salt",
"_usageId": "5"
},
{
"id": "zest",
"_usageId": "6",
"qty": 1,
"composite": {
"parent": "lemon",
"quantity": 1
}
}
],
"cookware": [],
"steps": [
{
"type": "step",
"content": [
"Serve with ",
{
"id": "salt",
"_usageId": "5"
},
"(flaky and ",
{
"id": "zest",
"_usageId": "6",
"qty": 1,
"composite": {
"parent": "lemon",
"quantity": 1
}
},
"(organic."
],
"timings": {
"start": 6,
"end": 8,
"activeDuration": 2
}
}
]
}
],
"warnings": [],
"metrics": {
"totalTime": 17,
"totalBreakdown": [
{
"label": "section_active:Dough",
"duration": 6
},
{
"label": "section_active:Serve",
"duration": 2
}
],
"idleTime": 0,
"activeTime": 8,
"activeBreakdown": [
{
"label": "section_active:Dough",
"duration": 6
},
{
"label": "section_active:Serve",
"duration": 2
}
],
"preparationTime": 9,
"prepBreakdown": [
{
"label": "ingredients_overhead",
"duration": 6
},
{
"label": "cookware_overhead",
"duration": 1
},
{
"label": "prep_butter",
"duration": 2
}
]
},
"miseEnPlace": [
{
"section": 0,
"duration": 6,
"items": [
{
"kind": "gather",
"target": "ingredient",
"count": 3,
"duration": 3
},
{
"kind": "gather",
"target": "cookware",
"count": 1,
"duration": 1
},
{
"kind": "prepare",
"ref": {
"type": "ingredient",
"id": "butter"
},
"duration": 2
}
]
},
{
"section": 1,
"duration": 3,
"items": [
{
"kind": "gather",
"target": "ingredient",
"count": 3,
"duration": 3
}
]
}
],
"tasks": {
"tasks": [
{
"id": "s0.prep",
"kind": "prep",
"section": 0,
"duration": {
"nominal": 6
},
"items": [
{
"kind": "gather",
"target": "ingredient",
"count": 3,
"duration": 3
},
{
"kind": "gather",
"target": "cookware",
"count": 1,
"duration": 1
},
{
"kind": "prepare",
"ref": {
"type": "ingredient",
"id": "butter"
},
"duration": 2
}
],
"after": []
},
{
"id": "s0.0",
"kind": "step",
"section": 0,
"step": 0,
"duration": {
"nominal": 2
},
"after": []
},
{
"id": "s0.1",
"kind": "step",
"section": 0,
"step": 1,
"duration": {
"nominal": 2
},
"after": [
"s0.0"
]
},
{
"id": "s0.2",
"kind": "step",
"section": 0,
"step": 2,
"duration": {
"nominal": 2
},
"after": [
"s0.1"
]
},
{
"id": "s1.prep",
"kind": "prep",
"section": 1,
"duration": {
"nominal": 3
},
"items": [
{
"kind": "gather",
"target": "ingredient",
"count": 3,
"duration": 3
}
],
"after": []
},
{
"id": "s1.0",
"kind": "step",
"section": 1,
"step": 0,
"duration": {
"nominal": 2
},
"after": []
}
],
"sections": [
{
"day": 0
},
{
"day": 0
}
]
},
"schedule": {
"miseEnPlace": "perSection",
"rests": "shortest",
"totalTime": 17,
"activeTime": 8,
"preparationTime": 9,
"idleTime": 0,
"blocks": [
{
"kind": "prep",
"task": "s0.prep",
"section": 0,
"start": 0,
"end": 6
},
{
"kind": "step",
"task": "s0.0",
"section": 0,
"step": 0,
"start": 6,
"end": 8
},
{
"kind": "step",
"task": "s0.1",
"section": 0,
"step": 1,
"start": 8,
"end": 10
},
{
"kind": "step",
"task": "s0.2",
"section": 0,
"step": 2,
"start": 10,
"end": 12
},
{
"kind": "prep",
"task": "s1.prep",
"section": 1,
"start": 12,
"end": 15
},
{
"kind": "step",
"task": "s1.0",
"section": 1,
"step": 0,
"start": 15,
"end": 17
}
],
"days": [
{
"day": 0,
"start": 0,
"end": 17,
"sections": [
0,
1
]
}
]
}
}

View file

@ -0,0 +1,15 @@
---
title: Preparation Single Line
---
## Dough
Mix @flour{200g}(sifted and @water{120ml}.
Heat a #pan{1}(large over ^{180°C}.
Knead @butter{20g}(soft, cubed).
## Serve
Serve with @salt(flaky and @zest{1}<@lemon{1}(organic.

View file

@ -142,7 +142,10 @@ GRAM {
// first word) and the braces leaked into prose -- merging distinct ingredients. // first word) and the braces leaked into prose -- merging distinct ingredients.
// Each "-- malformed" branch below turns that into a readable error instead. // Each "-- malformed" branch below turns that into a readable error instead.
malformedBraces = "{" (~("}" | nl) any)* ("}" | &nl | end) malformedBraces = "{" (~("}" | nl) any)* ("}" | &nl | end)
preparation = "(" (~")" any)* ")" // On one line: an unclosed `(` is prose, never the start of a preparation
// that would run to the next `)` further down the recipe, over blank lines
// and section headers.
preparation = "(" (~(")" | nl) any)* ")"
// `modifier*` mirrors simpleIngredient: a composite parent is an ingredient // `modifier*` mirrors simpleIngredient: a composite parent is an ingredient
// reference like any other, and authors (and AI importers) write `<@&parent` // reference like any other, and authors (and AI importers) write `<@&parent`
// to mark a parent already introduced earlier. Without it, `refName` rejected // to mark a parent already introduced earlier. Without it, `refName` rejected

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,70 @@
import { describe, expect, it } from "bun:test";
import { ASTNodeType, getAST } from "../src/index";
// A preparation ends on its line: an unclosed `(` used to run to the next `)`
// of the recipe, over blank lines and section headers, and swallowed them.
// biome-ignore lint/suspicious/noExplicitAny: walking a parsed AST in tests.
const sections = (src: string): any[] => getAST(src).children as any[];
// The elements of the only step of a one-step recipe.
// biome-ignore lint/suspicious/noExplicitAny: walking a parsed AST in tests.
const elements = (src: string): any[] =>
sections(`## T\n\n${src}\n`)[0].children[0].children;
// biome-ignore lint/suspicious/noExplicitAny: walking a parsed AST in tests.
const text = (nodes: any[]): string =>
nodes
.filter((c) => c.type === ASTNodeType.Text)
.map((c) => c.value)
.join("");
describe("a preparation stays on its line", () => {
it("keeps the steps and sections after an unclosed parenthesis", () => {
const src =
"## A\n\nMix @flour{200g}(sifted and\n\nBake at ^{180°C}.\n\n## B\n\nServe (hot).\n";
const [a, b] = sections(src);
expect(a.children).toHaveLength(2);
const flour = a.children[0].children.find(
// biome-ignore lint/suspicious/noExplicitAny: walking a parsed AST in tests.
(c: any) => c.type === ASTNodeType.Ingredient,
);
expect(flour.name).toBe("flour");
expect(flour.preparation).toBeNull();
expect(text(a.children[0].children)).toContain("(sifted and");
expect(b.title).toBe("B");
expect(text(b.children[0].children)).toBe("Serve (hot).");
});
it("leaves the unclosed parenthesis of a bare ingredient in the text", () => {
const nodes = elements("Add @salt(fine");
const salt = nodes.find((c) => c.type === ASTNodeType.Ingredient);
expect(salt.name).toBe("salt");
expect(salt.preparation).toBeNull();
expect(text(nodes)).toContain("(fine");
});
it("does the same for cookware and a composite parent", () => {
const pan = elements("Heat a #pan{1}(large").find(
(c) => c.type === ASTNodeType.Cookware,
);
expect(pan.preparation).toBeNull();
const zest = elements("Grate @zest{1}<@lemon{1}(organic").find(
(c) => c.type === ASTNodeType.Ingredient,
);
expect(zest.composite.parent).toBe("lemon");
expect(text(elements("Grate @zest{1}<@lemon{1}(organic"))).toContain(
"(organic",
);
expect(zest.composite.preparation).toBeNull();
});
it("reads a preparation closed on its line as before", () => {
const [flour] = elements("@flour{200g}(sifted, twice)");
expect(flour.preparation).toBe("sifted, twice");
const [pan] = elements("#pan{1}(20 cm)");
expect(pan.preparation).toBe("20 cm");
const [zest] = elements("@zest{1}<@lemon{1}(organic)");
expect(zest.composite.preparation).toBe("organic");
});
});