From d6e7866304c8772a48371c8cec504c822f64fdd2 Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Sun, 21 Jan 2024 20:51:25 +0200 Subject: [PATCH] Format FOR-clause in Transact-SQL --- .../transactsql/transactsql.formatter.ts | 1 + test/transactsql.test.ts | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/languages/transactsql/transactsql.formatter.ts b/src/languages/transactsql/transactsql.formatter.ts index a52f0d321f..512f13415f 100644 --- a/src/languages/transactsql/transactsql.formatter.ts +++ b/src/languages/transactsql/transactsql.formatter.ts @@ -18,6 +18,7 @@ const reservedClauses = expandPhrases([ 'ORDER BY', 'OFFSET', 'FETCH {FIRST | NEXT}', + 'FOR {BROWSE | XML | JSON}', 'OPTION', // Data manipulation // - insert: diff --git a/test/transactsql.test.ts b/test/transactsql.test.ts index 9491cd1424..65c2c4ba02 100644 --- a/test/transactsql.test.ts +++ b/test/transactsql.test.ts @@ -148,6 +148,34 @@ describe('TransactSqlFormatter', () => { `); }); + it('formats SELECT ... FOR BROWSE', () => { + expect(format('SELECT col FOR BROWSE')).toBe(dedent` + SELECT + col + FOR BROWSE + `); + }); + + it('formats SELECT ... FOR XML', () => { + expect(format("SELECT col FOR XML PATH('Employee'), ROOT('Employees')")).toBe(dedent` + SELECT + col + FOR XML + PATH ('Employee'), + ROOT ('Employees') + `); + }); + + it('formats SELECT ... FOR JSON', () => { + expect(format('SELECT col FOR JSON PATH, WITHOUT_ARRAY_WRAPPER')).toBe(dedent` + SELECT + col + FOR JSON + PATH, + WITHOUT_ARRAY_WRAPPER + `); + }); + it('formats goto labels', () => { const result = format( `InfiniLoop: