about summary refs log tree commit diff stats
path: root/js/baba-yaga/test-debug.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/baba-yaga/test-debug.js')
-rw-r--r--js/baba-yaga/test-debug.js62
1 files changed, 62 insertions, 0 deletions
diff --git a/js/baba-yaga/test-debug.js b/js/baba-yaga/test-debug.js
new file mode 100644
index 0000000..6be12cd
--- /dev/null
+++ b/js/baba-yaga/test-debug.js
@@ -0,0 +1,62 @@
+// test-debug.js - Debug the exact test case
+
+import { createLexer } from './src/core/lexer.js';
+import { createParser } from './src/core/parser.js';
+import { createInterpreter } from './src/core/interpreter.js';
+
+function runBabaCode(code, jsBridgeConfig = {}) {
+  const lexer = createLexer(code);
+  const tokens = lexer.allTokens();
+  const parser = createParser(tokens);
+  const ast = parser.parse();
+  
+  const host = {
+    jsBridgeConfig: {
+      allowedFunctions: new Set([
+        'JSON.parse', 'JSON.stringify',
+        'Math.abs', 'Math.floor', 'Math.ceil', 'Math.round',
+        'Math.min', 'Math.max', 'Math.random',
+        'console.log', 'console.warn', 'console.error',
+        'Date.now', 'performance.now',
+        'testFunction', 'testAsyncFunction', 'testErrorFunction'
+      ]),
+      ...jsBridgeConfig
+    },
+    io: {
+      out: () => {}, // Silent for tests
+      debug: () => {}
+    }
+  };
+  
+  // Add test functions to global scope for testing
+  global.testFunction = (x) => x * 2;
+  global.testAsyncFunction = async (x) => Promise.resolve(x + 10);
+  global.testErrorFunction = () => { throw new Error('Test error'); };
+  
+  // Add test functions to sandbox
+  if (!host.jsBridgeConfig.sandbox) {
+    host.jsBridgeConfig.sandbox = {};
+  }
+  host.jsBridgeConfig.sandbox.testFunction = global.testFunction;
+  host.jsBridgeConfig.sandbox.testAsyncFunction = global.testAsyncFunction;
+  host.jsBridgeConfig.sandbox.testErrorFunction = global.testErrorFunction;
+  
+  const interpreter = createInterpreter(ast, host);
+  interpreter.interpret();
+  return interpreter.scope.get('result');
+}
+
+// Test the exact failing case
+const code = `
+  result : io.callJS "Math.abs" [-5];
+  result;
+`;
+
+const result = runBabaCode(code);
+
+console.log('Result:', result);
+console.log('Type:', result?.type);
+console.log('Properties:', result?.properties);
+console.log('Has Ok?', result?.properties?.has('Ok'));
+console.log('Ok value:', result?.properties?.get('Ok'));
+console.log('Ok value.value:', result?.properties?.get('Ok')?.value);