Skip to content

Commit 6620c78

Browse files
committed
test: Fix ci format newlines
1 parent 79e3bc8 commit 6620c78

5 files changed

Lines changed: 15 additions & 11 deletions

File tree

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
"search.exclude": {
77
"out": true // set this to false to include "out" folder in search results
88
},
9+
"json.schemaDownload.trustedDomains": {
10+
"https://raw.githubusercontent.com/RedCMD/TmLanguage-Syntax-Highlighter/main/vscode.tmLanguage.schema.json": true
11+
},
12+
"js/ts.format.semicolons": "insert",
913
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
1014
"typescript.tsc.autoDetect": "off",
11-
"typescript.format.semicolons": "insert",
1215
"files.trimFinalNewlines": true,
1316
"C_Cpp.errorSquiggles": "enabled",
1417
"[typescript][json][jsonc][snippets]": {

src/test/fixtures/DocumentFormattingEditProvider-3spaces.tmLanguage.json renamed to src/test/baselines/DocumentFormattingEditProvider-3spaces.tmLanguage.json

File renamed without changes.

src/test/fixtures/DocumentFormattingEditProvider-tabs.tmLanguage.json renamed to src/test/baselines/DocumentFormattingEditProvider-tabs.tmLanguage.json

File renamed without changes.

src/test/baselines/FileTypes.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
"json-textmate": [
1212
"fixtures/DefinitionReferenceProvider.tmLanguage.json",
1313
"fixtures/DiagnosticCollection.tmLanguage.json",
14-
"fixtures/DocumentFormattingEditProvider-3spaces.tmLanguage.json",
15-
"fixtures/DocumentFormattingEditProvider-tabs.tmLanguage.json",
1614
"fixtures/JSON.tmLanguage.json",
1715
"fixtures/fileTypes/JSON.JSON-tmLanguage",
1816
"fixtures/fileTypes/firstLineJSON",

src/test/suite/extension.test.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,16 +270,16 @@ suite('Extension Tests', async () => {
270270
});
271271

272272
test('FormatDocumentProvider', async () => {
273-
const editorTabs = await vscode.window.showTextDocument(vscode.Uri.joinPath(fixturesUri, 'DocumentFormattingEditProvider-tabs.tmLanguage.json'), showTextDocumentOptions);
274-
const editorSpaces = await vscode.window.showTextDocument(vscode.Uri.joinPath(fixturesUri, 'DocumentFormattingEditProvider-3spaces.tmLanguage.json'), showTextDocumentOptions);
273+
const editorTabs = await vscode.window.showTextDocument(vscode.Uri.joinPath(baselinesUri, 'DocumentFormattingEditProvider-tabs.tmLanguage.json'), showTextDocumentOptions);
274+
const editorSpaces = await vscode.window.showTextDocument(vscode.Uri.joinPath(baselinesUri, 'DocumentFormattingEditProvider-3spaces.tmLanguage.json'), showTextDocumentOptions);
275275
const editorUnformatted = await vscode.window.showTextDocument(vscode.Uri.joinPath(fixturesUri, 'JSON.tmLanguage.json'), showTextDocumentOptions);
276276

277277
const documentFormatted = await vscode.workspace.openTextDocument({ content: editorUnformatted.document.getText(), language: 'json-textmate', encoding: '\r\n' });
278-
const editorFormatted = await vscode.window.showTextDocument(documentFormatted);
278+
const editorFormatted = await vscode.window.showTextDocument(documentFormatted, showTextDocumentOptions);
279279

280280
const formatActual: vscode.TextEdit[][] = [];
281281

282-
async function testFormatFile(editor: vscode.TextEditor, options: vscode.FormattingOptions = { tabSize: 4, insertSpaces: false, }) {
282+
async function assertFormatFile(editor: vscode.TextEditor, options: vscode.FormattingOptions = { tabSize: 4, insertSpaces: false, }) {
283283
const edits: vscode.TextEdit[] = await vscode.commands.executeCommand(
284284
'_executeFormatDocumentProvider',
285285
editorFormatted.document.uri,
@@ -297,10 +297,13 @@ suite('Extension Tests', async () => {
297297
await vscode.commands.executeCommand('editor.action.formatDocument');
298298
await vscode.commands.executeCommand('editor.action.formatDocument');
299299

300+
await editorSettings.update('insertSpaces', false);
301+
await editorSettings.update('tabSize', 4);
302+
300303
formatActual.push(edits);
301304

302305
if (runTests) {
303-
assert.equal(editorFormatted.document.getText(), editor.document.getText());
306+
assert.equal(editorFormatted.document.getText().replaceAll(/[\r\n]+/gm, '\r\n'), editor.document.getText().replaceAll(/[\r\n]+/gm, '\r\n'));
304307
}
305308
else {
306309
const uint8Array = new TextEncoder().encode(editorFormatted.document.getText());
@@ -326,7 +329,7 @@ suite('Extension Tests', async () => {
326329
formatActual.push(edits);
327330
}
328331

329-
await testFormatFile(editorTabs);
332+
await assertFormatFile(editorTabs);
330333
// Partially minify document;
331334
await editorFormatted.edit(
332335
editBuilder => {
@@ -336,8 +339,8 @@ suite('Extension Tests', async () => {
336339
}
337340
);
338341
// TODO: TreeSitter broken. can't handle partially minified JSON
339-
await testFormatFile(editorSpaces, { tabSize: 3, insertSpaces: true });
340-
await testFormatFile(editorTabs);
342+
await assertFormatFile(editorSpaces, { tabSize: 3, insertSpaces: true });
343+
await assertFormatFile(editorTabs);
341344

342345
await assertFormatRange(editorUnformatted, 12, 8, 19, 18);
343346
await assertFormatRange(editorUnformatted, 31, 37, 36, 37);

0 commit comments

Comments
 (0)