import assert from 'assert'; import { createLexer } from '../src/core/lexer.js'; import { createParser } from '../src/core/parser.js'; function parse(code) { const lexer = createLexer(code); const tokens = lexer.allTokens(); const parser = createParser(tokens); return parser.parse(); } describe('parser: with header', () => { it('parses basic with header', () => { const ast = parse('f : x -> with (a : x + 1; b : a * 2;) -> a + b;'); const fn = ast.body[0]; assert.strictEqual(fn.type, 'FunctionDeclaration'); assert.strictEqual(fn.body.type, 'WithHeader'); assert.strictEqual(fn.body.entries.length, 2); assert.strictEqual(fn.body.entries[0].type, 'WithAssign'); }); it('parses typed locals in header', () => { const ast = parse('g : (x: Int) -> Int -> with (a Int; a : x;) -> a;'); const fn = ast.body[0]; assert.strictEqual(fn.body.entries[0].type, 'WithTypeDecl'); assert.strictEqual(fn.body.entries[1].type, 'WithAssign'); }); it('parses with rec variant', () => { const ast = parse('h : -> with rec (f : x -> x; g : y -> y;) -> 0;'); const fn = ast.body[0]; assert.strictEqual(fn.body.recursive, true); }); });