"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const ast_differ_1 = require("../ast-differ");
(0, vitest_1.describe)('AstDiffer', () => {
    const differ = new ast_differ_1.AstDiffer();
    (0, vitest_1.it)('detects let → const change', () => {
        const patterns = differ.extract('let x = 1;', 'const x = 1;');
        (0, vitest_1.expect)(patterns.some((p) => p.category === 'variable_declaration' && p.from === 'let' && p.to === 'const')).toBe(true);
    });
    (0, vitest_1.it)('detects type annotation addition', () => {
        const patterns = differ.extract('function foo(x) { return x; }', 'function foo(x: string): string { return x; }');
        (0, vitest_1.expect)(patterns.some((p) => p.category === 'type_annotation' && p.from === 'no_type')).toBe(true);
    });
    (0, vitest_1.it)('detects type annotation change', () => {
        const patterns = differ.extract('function foo(x: number) { return x; }', 'function foo(x: string) { return x; }');
        (0, vitest_1.expect)(patterns.some((p) => p.category === 'type_annotation')).toBe(true);
    });
    (0, vitest_1.it)('detects modifier addition', () => {
        const patterns = differ.extract('function foo() {}', 'export async function foo() {}');
        (0, vitest_1.expect)(patterns.some((p) => p.category === 'modifier_change')).toBe(true);
    });
    (0, vitest_1.it)('detects try/catch wrapping', () => {
        const patterns = differ.extract('return JSON.parse(data);', 'try { return JSON.parse(data); } catch { return null; }');
        (0, vitest_1.expect)(patterns.some((p) => p.category === 'error_handling')).toBe(true);
    });
    (0, vitest_1.it)('returns empty for identical code', () => {
        const patterns = differ.extract('const x = 1;', 'const x = 1;');
        (0, vitest_1.expect)(patterns.length).toBe(0);
    });
    (0, vitest_1.it)('returns empty for empty input', () => {
        (0, vitest_1.expect)(differ.extract('', '').length).toBe(0);
        (0, vitest_1.expect)(differ.extract('', 'const x = 1;').length).toBeGreaterThanOrEqual(0);
    });
    (0, vitest_1.it)('detects try/catch removal', () => {
        const patterns = differ.extract('try { return JSON.parse(data); } catch { return null; }', 'return JSON.parse(data);');
        (0, vitest_1.expect)(patterns.some((p) => p.category === 'error_handling' && p.from === 'try_catch')).toBe(true);
    });
    (0, vitest_1.it)('detects function → arrow function conversion', () => {
        const patterns = differ.extract('function add(a: number, b: number) { return a + b; }', 'const add = (a: number, b: number): number => a + b;');
        (0, vitest_1.expect)(patterns.some((p) => p.category === 'function_style' && p.to === 'arrow_function')).toBe(true);
    });
    (0, vitest_1.it)('detects arrow → function conversion', () => {
        const patterns = differ.extract('const add = (a: number, b: number): number => a + b;', 'function add(a: number, b: number): number { return a + b; }');
        (0, vitest_1.expect)(patterns.some((p) => p.category === 'function_style' && p.to === 'function_declaration')).toBe(true);
    });
    (0, vitest_1.it)('detects string concatenation → template literal', () => {
        const patterns = differ.extract('const msg = "Hello, " + name + "!";', 'const msg = `Hello, ${name}!`;');
        (0, vitest_1.expect)(patterns.some((p) => p.category === 'string_style')).toBe(true);
    });
    (0, vitest_1.it)('detects optional chaining addition', () => {
        const patterns = differ.extract('const name = user && user.name;', 'const name = user?.name;');
        (0, vitest_1.expect)(patterns.some((p) => p.category === 'null_safety')).toBe(true);
    });
    (0, vitest_1.it)('detects destructuring addition', () => {
        const patterns = differ.extract('const name = obj.name; const age = obj.age;', 'const { name, age } = obj;');
        (0, vitest_1.expect)(patterns.some((p) => p.category === 'destructuring')).toBe(true);
    });
    (0, vitest_1.it)('detects promise to async/await conversion', () => {
        const patterns = differ.extract('fetch(url).then(r => r.json()).then(d => console.log(d));', 'async function getData() { const r = await fetch(url); const d = await r.json(); console.log(d); }');
        (0, vitest_1.expect)(patterns.some((p) => p.category === 'async_await')).toBe(true);
    });
    (0, vitest_1.it)('detects async keyword addition', () => {
        const patterns = differ.extract('function foo() { return bar(); }', 'async function foo() { return await bar(); }');
        (0, vitest_1.expect)(patterns.some((p) => p.category === 'async_await' && p.from === 'synchronous')).toBe(true);
    });
});
//# sourceMappingURL=ast-differ.test.js.map