diff --git a/src/formatter/ExpressionFormatter.ts b/src/formatter/ExpressionFormatter.ts index 4a917db031..98d00d0b0e 100644 --- a/src/formatter/ExpressionFormatter.ts +++ b/src/formatter/ExpressionFormatter.ts @@ -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) { diff --git a/test/features/between.ts b/test/features/between.ts index 88075c9e21..c8a68e3440 100644 --- a/test/features/between.ts +++ b/test/features/between.ts @@ -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', () => { @@ -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` diff --git a/test/features/case.ts b/test/features/case.ts index c710cdb3b6..03cea8c088 100644 --- a/test/features/case.ts +++ b/test/features/case.ts @@ -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; `); });