|
5 | 5 | import { setupLanguageService, setupTextDocument } from './utils/testHelper'; |
6 | 6 | import { ServiceSetup } from './utils/serviceSetup'; |
7 | 7 | import * as assert from 'assert'; |
8 | | -import { TextEdit } from 'vscode-languageserver-types'; |
| 8 | +import { FormattingOptions, TextEdit } from 'vscode-languageserver-types'; |
9 | 9 | import { SettingsState, TextDocumentTestManager } from '../src/yamlSettings'; |
10 | 10 | import { LanguageHandlers } from '../src/languageserver/handlers/languageHandlers'; |
| 11 | +import { CustomFormatterOptions } from '../src'; |
11 | 12 |
|
12 | 13 | describe('Formatter Tests', () => { |
13 | 14 | let languageHandler: LanguageHandlers; |
@@ -60,6 +61,42 @@ describe('Formatter Tests', () => { |
60 | 61 | assert.equal(edits[0].newText, 'comments: >\n test test test\n test test test\n test test test\n test test test\n'); |
61 | 62 | }); |
62 | 63 |
|
| 64 | + it('Formatting handles trailing commas (enabled)', async () => { |
| 65 | + const content = `{ |
| 66 | + key: 'value', |
| 67 | + food: 'raisins', |
| 68 | + airport: 'YYZ', |
| 69 | + lightened_bulb: 'illuminating', |
| 70 | +} |
| 71 | +`; |
| 72 | + const edits = await parseSetup(content, { singleQuote: true }); |
| 73 | + assert.equal(edits[0].newText, content); |
| 74 | + }); |
| 75 | + |
| 76 | + it('Formatting handles trailing commas (disabled)', async () => { |
| 77 | + const content = `{ |
| 78 | + key: 'value', |
| 79 | + food: 'raisins', |
| 80 | + airport: 'YYZ', |
| 81 | + lightened_bulb: 'illuminating', |
| 82 | +} |
| 83 | +`; |
| 84 | + const edits = await parseSetup(content, { |
| 85 | + singleQuote: true, |
| 86 | + trailingComma: false, |
| 87 | + }); |
| 88 | + assert.equal( |
| 89 | + edits[0].newText, |
| 90 | + `{ |
| 91 | + key: 'value', |
| 92 | + food: 'raisins', |
| 93 | + airport: 'YYZ', |
| 94 | + lightened_bulb: 'illuminating' |
| 95 | +} |
| 96 | +` |
| 97 | + ); |
| 98 | + }); |
| 99 | + |
63 | 100 | it('Formatting uses tabSize', async () => { |
64 | 101 | const content = `map: |
65 | 102 | k1: v1 |
|
0 commit comments