gram/examples/torture.gram

149 lines
No EOL
4.6 KiB
Text

---
title: 'The Ultimate GRAM Torture Test'
originalTitle: 'Unit Test from Hell'
date: '2025-12-17'
lastUpdated: '2025-12-18'
description: 'A comprehensive recipe designed to break parsers and test every single feature of the GRAM specification, including edge cases, logic combinations, and syntax stressors.'
category: 'System Test'
size: '∞ servings'
author: ['DeepMind Agent', 'The Parsers Nightmare']
source: ['https://gram-lang.org/specs', 'https://localhost:3000/torture']
tags: ['test', 'benchmark', 'syntax-heavy', 'edge-cases']
---
## 1. Basic Ingredients & Quantities
// Sanity check for standard parsing
Mix @flour{500g} with @water{300ml}.
Add @salt{10g}, @sugar{1tbsp}, and @yeast{7g}.
Use different number formats: @milk{1.5L} (decimal), @butter{1/2cup} (fraction), @oil{1-2tbsp} (range), @pepper{0.5-1tsp} (decimal range).
Test no units: @egg{1} and @apple{2-3}.
Test implicit quantity: @nutmeg{} (should be "to taste").
## 2. Modifiers Extravaganza
// Testing ?, -, &, *, = and their combinations
Essential: @salt{=5g} (Explicit fixed quantity).
Optional: @?cinnamon{1tsp} (Optional).
Hidden: @-secret spice{1pinch} (Hidden from list).
Reference: @&flour{50g} (Adding MORE flour to the sum).
Reference No-Qty: @&water{} (Using previously defined water).
Baker's Percentage: @*starter{100g} (The reference for 100%).
// Combinations
Optional Reference: @?&sugar{}(add more if needed).
Hidden Fixed: @-love{=1lot}.
Reference with Alias: @&flour[dusting flour]{20g}.
## 3. Aliases & Display Names
// Renaming ingredients for clarity
Use @white sugar[Counter Sugar]{100g}.
Mix with @brown sugar[Fancy Sugar]{50g}.
Even references: @&white sugar[The same sugar]{}.
## 4. Composites & Sources (The MAX Logic)
// Testing parent/child relationships
Zest logic:
Need @lemon zest{1}<@lemon{1}(driver) and @lemon juice{10 ml}<@lemon{}(passenger).
Result should be MAX(1, 0) = 1 Lemon.
Complex logic:
@orange zest{1}<@orange{2}(driver 1).
@orange pulp{100g}<@orange{}(passenger).
@orange slices{2}<@orange{3}(driver 2 - MAX wins).
Result should be MAX(2, 0, 3) = 3 Oranges.
Composite with alias:
@lime zest[Green Dust]{1}<@lime{1}.
## 5. Alternatives (The Pipe Dreams)
// Testing choice logic
Simple choice: @milk{100ml}|@water{100ml}.
Choice with modifiers: @?chili flakes{1tsp}|@paprika{1tsp}.
Choice with alias: @honey[Sweetener A]{}|@maple syrup[Sweetener B]{}.
Choice with quantity variation: @cream{100ml}|@milk{150ml}.
## 6. Cookware Logic
// Testing scaling rules
Implicit Fixed: #bowl{} (Should be fixed: true).
Implicit Scalable: #ramekins{4} (Should be fixed: false, scales with servings).
Explicit Fixed: #frying pan{=1} (Fixed: true, even if I make 100 servings).
Explicit Scalable?: #forks{4} (Standard scalable).
Alternatives in cookware:
Use a #whisk{}|#fork{} to mix.
Cook in #oven{}|#air fryer{}.
Cookware with modifiers:
Use a #?thermometer{}(optional).
Store in #&bowl{} (reference to previous bowl).
## 7. Timers & Temperatures
// Testing non-ingredient values
Bake for ~{30min} at !{180°C}.
Named timer: ~rise{1-2h}.
Named temp: !oven{200°C} or !fan oven{180°C}.
Ranges: ~{10-15minutes}.
Decimals: ~{1.5h}.
## 8. Intermediate Preparations (The Flow)
// Testing step results
[Mix] @flour{100g} and @water{50ml} in a #bowl{}. ->&slurry{}
[Rest] Let the &slurry{} sit for ~{5min}.
## Section 2 ->&filling{}
// Section-level intermediate prep
Mix @cheese{200g} and @herbs{}.
This entire section produces &filling{}.
## 9. Final Assembly (The Usage)
// Referencing everything
Take the &slurry{} and the &filling{}.
Combine in #pan{}.
Cook for ~final cook{10min} at !stove{low heat}.
Serve on #plate{=4}(fixed count).
## 10. Relative Quantities (New Engine) ->&relative_result{}
// Testing percentages, unit inheritance, mass normalization
// Prepare Base
@base flour{100g} and @base water{50ml}. ->&base{}
// Mass: 100g + 50g = 150g
// Add Relative
@salt{2% @base flour} (Expect: 2g).
@sugar{10% &base} (Expect: 15g).
@oil{20ml}.
// Test 0 Mass
Mix &base{} and @egg{2}. ->&enriched base{}
// Mass: 150g (base) + 2 + 15 + 20 = 187g (eggs ignored for mass)
// Test Partial
@yeast{1% &enriched base} (Expect: 1.87g + Warning because eggs were 0 mass/partial).
// Test Inheritance
@spice{1% @base water}. (Should inherit generic mass unit 'g' or specific? Logic says 'g' for mass calc).
## 11. Syntax Stress & Comments
// Breaking the parser
// Single line comment
/* Block
comment */
Test inline comments: @garlic{1} // pungent!
Test adjacent punctuation: Add @pepper{}, then salt.
Test parenthesis: (@tomato{1}(ripe)).
Test weird spacing: @ olive oil { 2 tbsp } .
Test special chars in names: @M&M's{100g} (if supported), or @cocoa-powder{}.