Skip to content

Commit

Permalink
Format FOR-clause in Transact-SQL
Browse files Browse the repository at this point in the history
  • Loading branch information
nene committed Jan 21, 2024
1 parent 4cec5e9 commit d6e7866
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/languages/transactsql/transactsql.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const reservedClauses = expandPhrases([
'ORDER BY',
'OFFSET',
'FETCH {FIRST | NEXT}',
'FOR {BROWSE | XML | JSON}',
'OPTION',
// Data manipulation
// - insert:
Expand Down
28 changes: 28 additions & 0 deletions test/transactsql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit d6e7866

Please sign in to comment.