Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/formatter/ExpressionFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export default class ExpressionFormatter {
this.layout = this.formatSubExpression(node.expr1);
this.layout.add(WS.NO_SPACE, WS.SPACE, this.showNonTabularKw(node.andKw), WS.SPACE);
this.layout = this.formatSubExpression(node.expr2);
this.layout.add(WS.SPACE);
this.layout.add(WS.NO_SPACE, WS.SPACE);
}

private formatCaseExpression(node: CaseExpressionNode) {
Expand Down
11 changes: 10 additions & 1 deletion test/features/between.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function supportsBetween(format: FormatFn) {

it('supports complex expressions inside BETWEEN', () => {
// Not ideal, but better than crashing
expect(format('foo BETWEEN 1+2 AND 3+4')).toBe('foo BETWEEN 1 + 2 AND 3 + 4');
expect(format('foo BETWEEN 1+2 AND 3+4')).toBe('foo BETWEEN 1 + 2 AND 3 + 4');
});

it('supports CASE inside BETWEEN', () => {
Expand All @@ -30,6 +30,15 @@ export default function supportsBetween(format: FormatFn) {
`);
});

it('does not add extra space after the BETWEEN expression', () => {
expect(format('SELECT CASE WHEN foo BETWEEN 1 AND 2 THEN 3 END')).toBe(dedent`
SELECT
CASE
WHEN foo BETWEEN 1 AND 2 THEN 3
END
`);
});

// Regression test for #534
it('supports AND after BETWEEN', () => {
expect(format('SELECT foo BETWEEN 1 AND 2 AND x > 10')).toBe(dedent`
Expand Down
2 changes: 1 addition & 1 deletion test/features/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export default function supportsCase(format: FormatFn) {
expect(result).toBe(dedent`
SELECT
CASE
WHEN x1 BETWEEN 1 AND 12 THEN ''
WHEN x1 BETWEEN 1 AND 12 THEN ''
END c1;
`);
});
Expand Down
Loading