diff options
Diffstat (limited to 'js/baba-yaga/web/editor/test-integration.html')
-rw-r--r-- | js/baba-yaga/web/editor/test-integration.html | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/js/baba-yaga/web/editor/test-integration.html b/js/baba-yaga/web/editor/test-integration.html new file mode 100644 index 0000000..356b8cd --- /dev/null +++ b/js/baba-yaga/web/editor/test-integration.html @@ -0,0 +1,109 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>Baba Yaga Integration Test</title> +</head> +<body> + <h1>Baba Yaga Integration Test</h1> + + <div id="status">Loading...</div> + + <div id="test-results"></div> + + <!-- Baba Yaga Language Components --> + <script type="module"> + // Import Baba Yaga components and make them globally available + import { createLexer, tokenTypes } from '../../lexer.js'; + import { createParser } from '../../parser.js'; + import { createInterpreter } from '../../interpreter.js'; + + // Make them globally available + window.createLexer = createLexer; + window.createParser = createParser; + window.createInterpreter = createInterpreter; + window.tokenTypes = tokenTypes; + + console.log('Baba Yaga modules loaded and made globally available'); + </script> + + <script type="module"> + // Test the integration + async function testIntegration() { + const statusDiv = document.getElementById('status'); + const resultsDiv = document.getElementById('test-results'); + + try { + // Test 1: Check if modules are loaded + statusDiv.textContent = 'Testing module loading...'; + + if (typeof createLexer === 'undefined') { + throw new Error('createLexer not found'); + } + if (typeof createParser === 'undefined') { + throw new Error('createParser not found'); + } + if (typeof createInterpreter === 'undefined') { + throw new Error('createInterpreter not found'); + } + + resultsDiv.innerHTML += '<p>✅ All modules loaded successfully</p>'; + + // Test 2: Test lexer + statusDiv.textContent = 'Testing lexer...'; + const testCode = 'add : x y -> x + y;'; + const lexer = createLexer(testCode); + const tokens = lexer.allTokens(); + + resultsDiv.innerHTML += `<p>✅ Lexer working: ${tokens.length} tokens generated</p>`; + + // Test 3: Test parser + statusDiv.textContent = 'Testing parser...'; + const parser = createParser(tokens); + const ast = parser.parse(); + + resultsDiv.innerHTML += `<p>✅ Parser working: AST generated with ${ast.body.length} statements</p>`; + + // Test 4: Test interpreter + statusDiv.textContent = 'Testing interpreter...'; + const interpreter = createInterpreter(ast); + const result = interpreter.interpret(); + + resultsDiv.innerHTML += `<p>✅ Interpreter working: Result = ${JSON.stringify(result)}</p>`; + + // Test 5: Test more complex code + statusDiv.textContent = 'Testing complex code...'; + const complexCode = ` +factorial : n -> + when n is + 0 then 1 + _ then n * (factorial (n - 1)); + +result : factorial 5;`; + + const complexLexer = createLexer(complexCode); + const complexTokens = complexLexer.allTokens(); + const complexParser = createParser(complexTokens); + const complexAST = complexParser.parse(); + const complexInterpreter = createInterpreter(complexAST); + const complexResult = complexInterpreter.interpret(); + + resultsDiv.innerHTML += `<p>✅ Complex code working: Result = ${JSON.stringify(complexResult)}</p>`; + + statusDiv.textContent = 'All tests passed! 🎉'; + statusDiv.style.color = 'green'; + + } catch (error) { + statusDiv.textContent = 'Test failed! ❌'; + statusDiv.style.color = 'red'; + resultsDiv.innerHTML += `<p style="color: red;">❌ Error: ${error.message}</p>`; + console.error('Integration test failed:', error); + } + } + + // Run tests when page loads + document.addEventListener('DOMContentLoaded', testIntegration); + </script> +</body> +</html> |