#!/usr/bin/env node

// 测试语法错误检测功能
const { hasSyntaxErrors } = require('./optimized-processor.js');

// 测试代码
const testCases = [
    {
        name: 'Normal code',
        code: 'function test() { console.log("hello"); return "world"; }',
        shouldError: false
    },
    {
        name: 'Runtime.js syntax error',
        code: 'p[s][0]', // 缺少分号的情况
        shouldError: true
    },
    {
        name: 'Bracket mismatch',
        code: 'function test() { return [1, 2, 3; }', // 缺少右括号
        shouldError: true
    },
    {
        name: 'Valid bracket code',
        code: 'function test() { return [1, 2, 3]; }',
        shouldError: false
    }
];

console.log('🧪 Testing Syntax Error Detection');
console.log('==================================');

testCases.forEach((testCase, index) => {
    console.log(`\n${index + 1}. ${testCase.name}`);
    console.log(`   Code: ${testCase.code}`);
    
    const hasError = hasSyntaxErrors(testCase.code);
    console.log(`   Expected: ${testCase.shouldError ? 'Error' : 'No Error'}`);
    console.log(`   Detected: ${hasError ? 'Error' : 'No Error'}`);
    console.log(`   Result: ${hasError === testCase.shouldError ? '✅ Pass' : '❌ Fail'}`);
});

console.log('\n🎉 Syntax error detection test completed!');