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