"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const if_expr_parser_1 = require("../if-expr-parser");
(0, vitest_1.describe)('parseIfExpr', () => {
    (0, vitest_1.it)('字面量 true', () => {
        const ast = (0, if_expr_parser_1.parseIfExpr)('true');
        (0, vitest_1.expect)(ast).toEqual({ kind: 'literal', value: true });
    });
    (0, vitest_1.it)('字面量 false / null', () => {
        (0, vitest_1.expect)((0, if_expr_parser_1.parseIfExpr)('false')).toEqual({ kind: 'literal', value: false });
        (0, vitest_1.expect)((0, if_expr_parser_1.parseIfExpr)('null')).toEqual({ kind: 'literal', value: null });
    });
    (0, vitest_1.it)('字面量整数', () => {
        (0, vitest_1.expect)((0, if_expr_parser_1.parseIfExpr)('42')).toEqual({ kind: 'literal', value: 42 });
    });
    (0, vitest_1.it)('字面量负数', () => {
        (0, vitest_1.expect)((0, if_expr_parser_1.parseIfExpr)('-3')).toEqual({ kind: 'literal', value: -3 });
    });
    (0, vitest_1.it)('字面量字符串', () => {
        (0, vitest_1.expect)((0, if_expr_parser_1.parseIfExpr)('"hello"')).toEqual({ kind: 'literal', value: 'hello' });
    });
    (0, vitest_1.it)('变量引用', () => {
        (0, vitest_1.expect)((0, if_expr_parser_1.parseIfExpr)('has_error')).toEqual({ kind: 'var', name: 'has_error' });
    });
    (0, vitest_1.it)('等号比较', () => {
        const ast = (0, if_expr_parser_1.parseIfExpr)('has_error == true');
        (0, vitest_1.expect)(ast).toEqual({
            kind: 'compare', op: '==',
            left: { kind: 'var', name: 'has_error' },
            right: { kind: 'literal', value: true },
        });
    });
    (0, vitest_1.it)('大于', () => {
        const ast = (0, if_expr_parser_1.parseIfExpr)('count > 5');
        (0, vitest_1.expect)(ast).toEqual({
            kind: 'compare', op: '>',
            left: { kind: 'var', name: 'count' },
            right: { kind: 'literal', value: 5 },
        });
    });
    (0, vitest_1.it)('AND 短路', () => {
        const ast = (0, if_expr_parser_1.parseIfExpr)('a && b');
        (0, vitest_1.expect)(ast).toEqual({
            kind: 'and',
            left: { kind: 'var', name: 'a' },
            right: { kind: 'var', name: 'b' },
        });
    });
    (0, vitest_1.it)('OR 短路', () => {
        const ast = (0, if_expr_parser_1.parseIfExpr)('a || b');
        (0, vitest_1.expect)(ast).toEqual({
            kind: 'or',
            left: { kind: 'var', name: 'a' },
            right: { kind: 'var', name: 'b' },
        });
    });
    (0, vitest_1.it)('括号优先级', () => {
        const ast = (0, if_expr_parser_1.parseIfExpr)('(a == 1) && (b > 2)');
        (0, vitest_1.expect)(ast.kind).toBe('and');
    });
    (0, vitest_1.it)('AND 优先级高于 OR（左结合）', () => {
        // spec §5.4 简化为左结合从左到右，&& 和 || 同优先级
        // a && b || c = ((a && b) || c)
        const ast = (0, if_expr_parser_1.parseIfExpr)('a && b || c');
        (0, vitest_1.expect)(ast.kind).toBe('or');
    });
    (0, vitest_1.it)('非法 token 抛错', () => {
        (0, vitest_1.expect)(() => (0, if_expr_parser_1.parseIfExpr)('a + b')).toThrow(); // 不支持算术
        (0, vitest_1.expect)(() => (0, if_expr_parser_1.parseIfExpr)('foo(1)')).toThrow(); // 不支持函数调用
        (0, vitest_1.expect)(() => (0, if_expr_parser_1.parseIfExpr)('a.b')).toThrow(); // 不支持字段访问
        (0, vitest_1.expect)(() => (0, if_expr_parser_1.parseIfExpr)('')).toThrow();
        (0, vitest_1.expect)(() => (0, if_expr_parser_1.parseIfExpr)('==')).toThrow();
    });
});
//# sourceMappingURL=if-expr-parser.test.js.map