Skip to content

Commit 59c78ff

Browse files
authored
Merge pull request #30 from launchql/feat/fix-test-fm
Feat/fix test fm
2 parents 067d75e + 3bf8aef commit 59c78ff

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

packages/deparser/__tests__/kitchen-sink/misc-launchql-ext-types.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
import { FixtureTestUtils } from '../../test-utils';
3+
34
const fixtures = new FixtureTestUtils();
45

56
it('misc-launchql-ext-types', async () => {

packages/deparser/src/deparser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -979,10 +979,10 @@ export class Deparser implements DeparserVisitor {
979979
switch (boolop) {
980980
case 'AND_EXPR':
981981
const andArgs = args.map(arg => this.visit(arg, boolContext)).join(' AND ');
982-
return formatStr.replace('%s', andArgs);
982+
return formatStr.replace('%s', () => andArgs);
983983
case 'OR_EXPR':
984984
const orArgs = args.map(arg => this.visit(arg, boolContext)).join(' OR ');
985-
return formatStr.replace('%s', orArgs);
985+
return formatStr.replace('%s', () => orArgs);
986986
case 'NOT_EXPR':
987987
return `NOT (${this.visit(args[0], context)})`;
988988
default:

packages/deparser/test-utils/index.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,17 @@ export class TestUtils {
9595
async expectAstMatch(testName: string, sql: string) {
9696
let tree: any;
9797
try {
98-
tree = this.tryParse(sql);
98+
tree = await this.tryParse(sql);
9999
if (tree.stmts) {
100-
tree.stmts.forEach(async (stmt: any) => {
100+
for (const stmt of tree.stmts) {
101101
if (stmt.stmt) {
102102
const outSql = deparse(stmt.stmt);
103+
104+
// console.log(`\n🔍 DEBUGGING SQL COMPARISON for test: ${testName}`);
105+
// console.log(`📥 INPUT SQL: ${sql}`);
106+
// console.log(`📤 DEPARSED SQL: ${outSql}`);
107+
// console.log(`🔄 SQL MATCH: ${sql.trim() === outSql.trim() ? '✅ EXACT MATCH' : '❌ DIFFERENT'}`);
108+
103109
let reparsed;
104110
try {
105111
reparsed = await parse(outSql);
@@ -135,7 +141,7 @@ export class TestUtils {
135141
throw createParseError('AST_MISMATCH', testName, sql, outSql, originalClean, reparsedClean);
136142
}
137143
}
138-
});
144+
}
139145
}
140146
} catch (err) {
141147
const errorMessages: string[] = [];
@@ -164,7 +170,7 @@ export class TestUtils {
164170
`\nACTUAL AST:`,
165171
JSON.stringify(parseError.reparsedAst, null, 2),
166172
`\nDIFF (what's missing from actual vs expected):`,
167-
diff(parseError.originalAst, parseError.reparsedAst)
173+
diff(parseError.originalAst, parseError.reparsedAst) || 'No diff available'
168174
);
169175
} else if (parseError.originalAst) {
170176
errorMessages.push(`❌ AST: ${JSON.stringify(parseError.originalAst, null, 2)}`);
@@ -210,12 +216,13 @@ export class FixtureTestUtils extends TestUtils {
210216
console.log('no filters provided, skipping tests.');
211217
return;
212218
}
213-
this.getTestEntries(filters).forEach(async ([relativePath, sql]) => {
219+
const entries = this.getTestEntries(filters);
220+
for (const [relativePath, sql] of entries) {
214221
try {
215222
await this.expectAstMatch(relativePath, sql);
216223
} catch (err) {
217224
throw err;
218225
}
219-
});
226+
}
220227
}
221228
}

0 commit comments

Comments
 (0)