Monorepo for Aesthetic.Computer aesthetic.computer
4
fork

Configure Feed

Select the types of activity you want to include in your feed.

test: add verification tests for KidLisp Mini parsing and evaluation

+99
+34
oven/test_bundle_parse.mjs
··· 1 + // Verify the bundled source parses correctly 2 + import { parse } from './kidlisp-mini/eval.mjs'; 3 + 4 + const bundledSource = `fade:red-blue-black-blue-red 5 + (ink (? rainbow white 0) (1s... 24 64)) 6 + (line w/2 0 w/2 h) 7 + (spin (2s... -1.125 1.125)) (zoom 1.1) 8 + (0.5s (contrast 1.05)) 9 + (scroll (? -0.1 0 0.1) (? -0.1 0 0.1)) 10 + (ink (? cyan yellow magenta) 8) 11 + (circle w/2 h/2 (? 2 4 8))`; 12 + 13 + const ast = parse(bundledSource); 14 + console.log('=== PARSED AST ==='); 15 + console.log('AST length:', ast.length); 16 + console.log('Top-level expressions:'); 17 + ast.forEach((expr, i) => { 18 + if (Array.isArray(expr)) { 19 + console.log(` [${i}]: (${expr[0]} ...)`); 20 + } else if (typeof expr === 'object' && expr.type === 'fade') { 21 + console.log(` [${i}]: fade:${expr.colors.join('-')}`); 22 + } else { 23 + console.log(` [${i}]: ${expr}`); 24 + } 25 + }); 26 + 27 + console.log('\n=== FUNCTION CALLS ==='); 28 + ast.forEach((expr, i) => { 29 + if (Array.isArray(expr) && typeof expr[0] === 'string') { 30 + const fn = expr[0]; 31 + const args = expr.slice(1).length; 32 + console.log(` ${fn}: ${args} args`); 33 + } 34 + });
+65
oven/test_complete_flow.mjs
··· 1 + // Test complete parsing and evaluation flow 2 + import { KidLispMini, parse } from './kidlisp-mini/eval.mjs'; 3 + import { makeRenderer } from './kidlisp-mini/render.mjs'; 4 + 5 + // Test source (as it should be fixed) 6 + const source = `fade:red-blue-black-blue-red 7 + (ink (? rainbow white 0) (1s... 24 64)) 8 + (line w/2 0 w/2 h) 9 + (spin (2s... -1.125 1.125)) (zoom 1.1) 10 + (0.5s (contrast 1.05)) 11 + (scroll (? -0.1 0 0.1) (? -0.1 0 0.1)) 12 + (ink (? cyan yellow magenta) 8) 13 + (circle w/2 h/2 (? 2 4 8))`; 14 + 15 + console.log('=== FIXED SOURCE PARSING ==='); 16 + const ast = parse(source); 17 + console.log('✓ AST parsed successfully'); 18 + console.log(' AST length:', ast.length, '(expected: 9)'); 19 + 20 + console.log('\n=== TOP-LEVEL EXPRESSIONS ==='); 21 + ast.forEach((expr, i) => { 22 + if (Array.isArray(expr)) { 23 + const fn = expr[0]; 24 + const argCount = expr.length - 1; 25 + console.log(` [${i}] (${fn} ...${argCount > 0 ? ` ${argCount} args` : ''})`); 26 + } else if (typeof expr === 'object' && expr.type === 'fade') { 27 + console.log(` [${i}] fade:${expr.colors.join('-')}`); 28 + } else { 29 + console.log(` [${i}] ${expr}`); 30 + } 31 + }); 32 + 33 + console.log('\n=== MOCK EVALUATION ==='); 34 + // Create a mock renderer to track calls 35 + const W = 1280, H = 800; 36 + const renderer = makeRenderer(W, H); 37 + const api = { 38 + screen: { width: W, height: H }, 39 + wipe: (r, g, b, a = 255) => console.log(` api.wipe(${r},${g},${b},${a})`), 40 + ink: (r, g, b, a = 255) => console.log(` api.ink(${r},${g},${b},${a})`), 41 + line: (x0, y0, x1, y1) => console.log(` api.line(${x0},${y0},${x1},${y1})`), 42 + circle: (cx, cy, r, mode) => console.log(` api.circle(${cx},${cy},${r},${mode})`), 43 + fadeBackground: (colors, frame) => console.log(` api.fadeBackground([...${colors.length} colors],${frame})`), 44 + scroll: (dx, dy) => console.log(` api.scroll(${dx},${dy})`), 45 + spin: (angle) => console.log(` api.spin(${angle})`), 46 + zoom: (factor) => console.log(` api.zoom(${factor})`), 47 + contrast: (factor) => console.log(` api.contrast(${factor})`), 48 + }; 49 + 50 + const kidlisp = new KidLispMini(); 51 + kidlisp.setApi(api); 52 + 53 + console.log('Evaluating frame 0...'); 54 + for (let i = 0; i < Math.min(3, ast.length); i++) { 55 + const expr = ast[i]; 56 + console.log(` expr[${i}]:`); 57 + try { 58 + const result = kidlisp.evalExpr(expr, kidlisp.globalEnv, api, 0); 59 + console.log(` → result: ${typeof result === 'object' ? JSON.stringify(result).substring(0, 50) : result}`); 60 + } catch (e) { 61 + console.log(` → ERROR: ${e.message}`); 62 + } 63 + } 64 + 65 + console.log('\n✅ Flow complete!');