Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import { FixtureTestUtils } from '../../test-utils';

const fixtures = new FixtureTestUtils();

it('misc-launchql-ext-types', async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/deparser/src/deparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 13 additions & 6 deletions packages/deparser/test-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -135,7 +141,7 @@ export class TestUtils {
throw createParseError('AST_MISMATCH', testName, sql, outSql, originalClean, reparsedClean);
}
}
});
}
}
} catch (err) {
const errorMessages: string[] = [];
Expand Down Expand Up @@ -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)}`);
Expand Down Expand Up @@ -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;
}
});
}
}
}