diff --git a/packages/deparser/__tests__/kitchen-sink/misc-launchql-ext-types.test.ts b/packages/deparser/__tests__/kitchen-sink/misc-launchql-ext-types.test.ts index 7f0c7304..4484933e 100644 --- a/packages/deparser/__tests__/kitchen-sink/misc-launchql-ext-types.test.ts +++ b/packages/deparser/__tests__/kitchen-sink/misc-launchql-ext-types.test.ts @@ -1,5 +1,6 @@ import { FixtureTestUtils } from '../../test-utils'; + const fixtures = new FixtureTestUtils(); it('misc-launchql-ext-types', async () => { diff --git a/packages/deparser/src/deparser.ts b/packages/deparser/src/deparser.ts index ae337416..5e3ce882 100644 --- a/packages/deparser/src/deparser.ts +++ b/packages/deparser/src/deparser.ts @@ -979,10 +979,10 @@ export class Deparser implements DeparserVisitor { switch (boolop) { case 'AND_EXPR': const andArgs = args.map(arg => this.visit(arg, boolContext)).join(' AND '); - return formatStr.replace('%s', andArgs); + return formatStr.replace('%s', () => andArgs); case 'OR_EXPR': const orArgs = args.map(arg => this.visit(arg, boolContext)).join(' OR '); - return formatStr.replace('%s', orArgs); + return formatStr.replace('%s', () => orArgs); case 'NOT_EXPR': return `NOT (${this.visit(args[0], context)})`; default: diff --git a/packages/deparser/test-utils/index.ts b/packages/deparser/test-utils/index.ts index 28a070fa..9c9392e0 100644 --- a/packages/deparser/test-utils/index.ts +++ b/packages/deparser/test-utils/index.ts @@ -95,11 +95,17 @@ export class TestUtils { async expectAstMatch(testName: string, sql: string) { let tree: any; try { - tree = this.tryParse(sql); + tree = await this.tryParse(sql); if (tree.stmts) { - tree.stmts.forEach(async (stmt: any) => { + for (const stmt of tree.stmts) { if (stmt.stmt) { const outSql = deparse(stmt.stmt); + + // console.log(`\nšŸ” DEBUGGING SQL COMPARISON for test: ${testName}`); + // console.log(`šŸ“„ INPUT SQL: ${sql}`); + // console.log(`šŸ“¤ DEPARSED SQL: ${outSql}`); + // console.log(`šŸ”„ SQL MATCH: ${sql.trim() === outSql.trim() ? 'āœ… EXACT MATCH' : 'āŒ DIFFERENT'}`); + let reparsed; try { reparsed = await parse(outSql); @@ -135,7 +141,7 @@ export class TestUtils { throw createParseError('AST_MISMATCH', testName, sql, outSql, originalClean, reparsedClean); } } - }); + } } } catch (err) { const errorMessages: string[] = []; @@ -164,7 +170,7 @@ export class TestUtils { `\nACTUAL AST:`, JSON.stringify(parseError.reparsedAst, null, 2), `\nDIFF (what's missing from actual vs expected):`, - diff(parseError.originalAst, parseError.reparsedAst) + diff(parseError.originalAst, parseError.reparsedAst) || 'No diff available' ); } else if (parseError.originalAst) { errorMessages.push(`āŒ AST: ${JSON.stringify(parseError.originalAst, null, 2)}`); @@ -210,12 +216,13 @@ export class FixtureTestUtils extends TestUtils { console.log('no filters provided, skipping tests.'); return; } - this.getTestEntries(filters).forEach(async ([relativePath, sql]) => { + const entries = this.getTestEntries(filters); + for (const [relativePath, sql] of entries) { try { await this.expectAstMatch(relativePath, sql); } catch (err) { throw err; } - }); + } } }