Skip to content

Commit 7ca0300

Browse files
committed
chore: add another test and fix failing tests
1 parent be8ace5 commit 7ca0300

2 files changed

Lines changed: 51 additions & 13 deletions

File tree

test/autoCompletionFix.test.ts

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -882,8 +882,8 @@ objB:
882882
},
883883
},
884884
};
885-
languageService.addSchema(SCHEMA_ID, schema);
886-
const content = 'array:\n - na| | ';
885+
schemaProvider.addSchema(SCHEMA_ID, schema);
886+
const content = 'array:\n - obj| | ';
887887
const completion = await parseCaret(content);
888888

889889
expect(completion.items.length).equal(1);
@@ -1109,6 +1109,41 @@ objB:
11091109
expect(result.items.length).to.be.equal(1);
11101110
expect(result.items[0].insertText).to.be.equal('objA:\n itemA: ');
11111111
});
1112+
1113+
it('array completion - should suggest correct indent when extra spaces after cursor followed by with different array item', async () => {
1114+
schemaProvider.addSchema(SCHEMA_ID, {
1115+
type: 'object',
1116+
properties: {
1117+
test: {
1118+
type: 'array',
1119+
items: {
1120+
type: 'object',
1121+
properties: {
1122+
objA: {
1123+
type: 'object',
1124+
required: ['itemA'],
1125+
properties: {
1126+
itemA: {
1127+
type: 'string',
1128+
},
1129+
},
1130+
},
1131+
},
1132+
},
1133+
},
1134+
},
1135+
});
1136+
const content = `
1137+
test:
1138+
- | |
1139+
- objA:
1140+
itemA: test`;
1141+
const result = await parseCaret(content);
1142+
1143+
expect(result.items.length).to.be.equal(1);
1144+
expect(result.items[0].insertText).to.be.equal('objA:\n itemA: ');
1145+
});
1146+
11121147
it('array of arrays completion - should suggest correct indent when extra spaces after cursor', async () => {
11131148
schemaProvider.addSchema(SCHEMA_ID, {
11141149
type: 'object',
@@ -1207,27 +1242,18 @@ objB:
12071242
},
12081243
};
12091244
it('should get extra space compensation for the 1st prop in array object item', async () => {
1210-
languageService.addSchema(SCHEMA_ID, schema);
1245+
schemaProvider.addSchema(SCHEMA_ID, schema);
12111246
const content = 'array1:\n - |\n| propB: test';
12121247
const result = await parseCaret(content);
12131248

12141249
expect(result.items.length).to.be.equal(1);
12151250
expect(result.items[0].insertText).to.be.equal('objA:\n ');
12161251
});
12171252
it('should get extra space compensation for the 1st prop in array object item - extra spaces', async () => {
1218-
languageService.addSchema(SCHEMA_ID, schema);
1253+
schemaProvider.addSchema(SCHEMA_ID, schema);
12191254
const content = 'array1:\n - | | \n propB: test';
12201255
const result = await parseCaret(content);
12211256

1222-
expect(result.items.length).to.be.equal(1);
1223-
expect(result.items[0].insertText).to.be.equal('objA:\n ');
1224-
});
1225-
// previous PR doesn't fix this
1226-
it.skip('should get extra space compensation for the 1st prop in array object item - extra lines', async () => {
1227-
languageService.addSchema(SCHEMA_ID, schema);
1228-
const content = 'array1:\n - \n |\n| propB: test';
1229-
const result = await parseCaret(content);
1230-
12311257
expect(result.items.length).to.be.equal(1);
12321258
expect(result.items[0].insertText).to.be.equal('objA:\n ');
12331259
});

test/yaml-documents.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,18 @@ objB:
212212
});
213213

214214
describe('Array', () => {
215+
// Problem in `getNodeFromPosition` function. This method doesn't give proper results for arrays
216+
// for example, this yaml return nodes:
217+
// foo:
218+
// - # foo object is returned (should be foo[0])
219+
// # foo object is returned (should be foo[0])
220+
// item1: aaaf
221+
// # foo[0] object is returned (OK)
222+
// - # foo object is returned (should be foo[1])
223+
// # foo[!!0!!] object is returned (should be foo[1])
224+
// item2: bbb
225+
// # foo[1] object is returned (OK)
226+
215227
it('Find closes node: array', () => {
216228
const doc = setupTextDocument('foo:\n - bar: aaa\n ');
217229
const yamlDoc = documents.getYamlDocument(doc);

0 commit comments

Comments
 (0)