Skip to content

Commit 050b459

Browse files
arpitkuriyaljdesrosiers
authored andcommitted
added test for configuration settings
1 parent cf43733 commit 050b459

File tree

1 file changed

+60
-21
lines changed

1 file changed

+60
-21
lines changed

language-server/src/features/codeAction/extractSubschema.test.ts

Lines changed: 60 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ describe("Feature - CodeAction: Extract subSchema to $defs", () => {
4545
{
4646
newText: `{ "$ref": "#/$defs/def1" }`,
4747
range: {
48-
end: { character: 5, line: 7 },
49-
start: { character: 13, line: 4 }
48+
start: { line: 4, character: 13 },
49+
end: { line: 7, character: 5 }
5050
}
5151
},
5252
{
@@ -58,8 +58,8 @@ describe("Feature - CodeAction: Extract subSchema to $defs", () => {
5858
}
5959
}`,
6060
range: {
61-
end: { character: 3, line: 8 },
62-
start: { character: 3, line: 8 }
61+
start: { line: 8, character: 3 },
62+
end: { line: 8, character: 3 }
6363
}
6464
}
6565
],
@@ -109,8 +109,8 @@ describe("Feature - CodeAction: Extract subSchema to $defs", () => {
109109
{
110110
newText: `{ "$ref": "#/definitions/def2" }`,
111111
range: {
112-
end: { line: 8, character: 5 },
113-
start: { line: 5, character: 11 }
112+
start: { line: 5, character: 11 },
113+
end: { line: 8, character: 5 }
114114
}
115115
},
116116
{
@@ -120,8 +120,8 @@ describe("Feature - CodeAction: Extract subSchema to $defs", () => {
120120
"minimum": 0
121121
}`,
122122
range: {
123-
end: { character: 5, line: 13 },
124-
start: { character: 5, line: 13 }
123+
start: { line: 13, character: 5 },
124+
end: { line: 13, character: 5 }
125125
}
126126
}
127127
],
@@ -214,8 +214,8 @@ describe("Feature - CodeAction: Extract subSchema to $defs", () => {
214214
{
215215
newText: `{ "$ref": "#/definitions/def1" }`,
216216
range: {
217-
end: { line: 7, character: 5 },
218-
start: { line: 4, character: 11 }
217+
start: { line: 4, character: 11 },
218+
end: { line: 7, character: 5 }
219219
}
220220
},
221221
{
@@ -225,8 +225,8 @@ describe("Feature - CodeAction: Extract subSchema to $defs", () => {
225225
"minimum": 0
226226
}`,
227227
range: {
228-
end: { character: 18, line: 9 },
229-
start: { character: 18, line: 9 }
228+
start: { line: 9, character: 18 },
229+
end: { line: 9, character: 18 }
230230
}
231231
}
232232
],
@@ -319,8 +319,8 @@ describe("Feature - CodeAction: Extract subSchema to $defs", () => {
319319
newText: `,
320320
"def1": { "type": "string" }`,
321321
range: {
322-
end: { character: 56, line: 23 },
323-
start: { character: 56, line: 23 }
322+
start: { line: 23, character: 56 },
323+
end: { line: 23, character: 56 }
324324
}
325325
}
326326
],
@@ -361,17 +361,15 @@ describe("Feature - CodeAction: Extract subSchema to $defs", () => {
361361
expect(edits?.[1]?.range?.end).to.eql({ line: 8, character: 3 });
362362
});
363363

364-
describe("should maintain indentation as per used in the schema", () => {
365-
test("checking for the indentation: 2 spaces", async () => {
364+
describe("Handling configuration settings", () => {
365+
test("uses detected indentation when detectIndentation is true and applies default EOL behavior when eol is 'auto' - checking for 2 spaces", async () => {
366366
await client.changeConfiguration(
367367
undefined,
368368
{
369-
tabSize: 2,
370-
insertSpaces: true,
371-
detectIndentation: false
369+
detectIndentation: true
372370
},
373371
{
374-
eol: "\n"
372+
eol: "auto"
375373
}
376374
);
377375
await client.writeDocument("subject.schema.json", `{
@@ -404,7 +402,7 @@ describe("Feature - CodeAction: Extract subSchema to $defs", () => {
404402
}`);
405403
});
406404

407-
test("checking for the indentation: 4 spaces", async () => {
405+
test("uses provided tabSize and insertSpaces when detectIndentation is false and respects specified EOL when settings.eol is not 'auto' - checking for 4 spaces", async () => {
408406
await client.changeConfiguration(
409407
undefined,
410408
{
@@ -445,5 +443,46 @@ describe("Feature - CodeAction: Extract subSchema to $defs", () => {
445443
}
446444
}`);
447445
});
446+
447+
test("indentation.type is 'tab' when insertSpaces is false and it works correctly with the schema", async () => {
448+
await client.changeConfiguration(
449+
undefined,
450+
{
451+
tabSize: 2,
452+
insertSpaces: false,
453+
detectIndentation: false
454+
}
455+
);
456+
await client.writeDocument("subject.schema.json", `{
457+
"$schema": "https://json-schema.org/draft/2020-12/schema",
458+
"type": "object",
459+
"properties": {
460+
"name": {
461+
"type": "string"
462+
}
463+
}
464+
}`);
465+
documentUri = await client.openDocument("subject.schema.json");
466+
467+
const codeActions = await client.sendRequest(CodeActionRequest.type, {
468+
textDocument: { uri: documentUri },
469+
range: {
470+
start: { line: 4, character: 12 },
471+
end: { line: 6, character: 5 }
472+
},
473+
context: { diagnostics: [] }
474+
});
475+
const firstAction = codeActions?.[0] as CodeAction;
476+
const documentChange = firstAction.edit?.documentChanges?.[0] as TextDocumentEdit;
477+
const edits = documentChange.edits;
478+
/* eslint-disable @stylistic/no-tabs */
479+
expect(edits?.[1].newText).to.eql(`,
480+
"$defs": {
481+
"def1": {
482+
"type": "string"
483+
}
484+
}`);
485+
/* eslint-enable @stylistic/no-tabs */
486+
});
448487
});
449488
});

0 commit comments

Comments
 (0)