Something went wrong. Try again.
Monorepo for Aesthetic.Computer aesthetic.computer
Something went wrong. Try again.
JavaScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114// Simple test for KidLisp embed functionality// This is not a formal test suite, just a basic verification
import { KidLisp, fetchCachedCode } from '../system/public/aesthetic.computer/lib/kidlisp.mjs';
// Mock API object for testingconst mockApi = { screen: { width: 256, height: 256, pixels: new Uint8ClampedArray(256 * 256 * 4) }, wipe: (color) => console.log(`Mock wipe: ${color}`), ink: (...args) => console.log(`Mock ink: ${args.join(', ')}`), box: (...args) => console.log(`Mock box: ${args.join(', ')}`), paste: (...args) => console.log(`Mock paste: ${args.join(', ')}`), painting: (width, height, callback) => { console.log(`Mock painting: ${width}x${height}`); const buffer = { width, height, pixels: new Uint8ClampedArray(width * height * 4) }; if (callback) callback(mockApi); return buffer; }};
// Test the embed commandasync function testEmbedCommand() { console.log('Testing KidLisp embed command...'); const kidlisp = new KidLisp(); const globalEnv = kidlisp.getGlobalEnv(); // Test that embed command exists if (globalEnv.embed) { console.log('✅ embed command found in global environment'); // Test embed with invalid cache code const result1 = globalEnv.embed(mockApi, ['invalid']); console.log('embed with invalid code:', result1); // Test embed with $-prefixed code format const result2 = globalEnv.embed(mockApi, ['$abc123XY']); console.log('embed with $-prefixed code:', result2); } else { console.log('❌ embed command not found in global environment'); }}
// Test the $-prefixed function resolutionasync function testDollarPrefixedFunctions() { console.log('\nTesting $-prefixed function resolution...'); const kidlisp = new KidLisp(); // Test resolving a $-prefixed function const resolved = kidlisp.resolveFunction('$abc123XY', mockApi, {}); if (resolved && resolved.type === 'cache') { console.log('✅ $-prefixed function correctly resolved as cache type'); // Test calling the resolved function try { const result = resolved.value(mockApi, []); console.log('Cache function call result:', result); } catch (error) { console.log('Cache function call error (expected):', error.message); } } else { console.log('❌ $-prefixed function not resolved correctly'); }}
// Test parsing and evaluating $-prefixed function callsasync function testParsing() { console.log('\nTesting parsing of $-prefixed function calls...'); const kidlisp = new KidLisp(); // Test parsing a simple $-prefixed call try { const parsed = kidlisp.parse('($abc123XY)'); console.log('Parsed ($abc123XY):', JSON.stringify(parsed, null, 2)); // Test parsing with arguments const parsed2 = kidlisp.parse('($abc123XY 64 64)'); console.log('Parsed ($abc123XY 64 64):', JSON.stringify(parsed2, null, 2)); console.log('✅ Parsing works correctly'); } catch (error) { console.log('❌ Parsing error:', error.message); }}
// Run all testsasync function runTests() { console.log('🚀 Running KidLisp embed functionality tests...\n'); await testEmbedCommand(); await testDollarPrefixedFunctions(); await testParsing(); console.log('\n✨ Tests completed!'); console.log('\nNote: Network-dependent tests will show expected errors'); console.log('since we don\'t have actual cached codes to test with.');}
// Export for potential use in other test filesexport { testEmbedCommand, testDollarPrefixedFunctions, testParsing, runTests };
// Run tests if this file is executed directlyif (import.meta.url === `file://${process.argv[1]}`) { runTests().catch(console.error);}