Skip to content

Commit

Permalink
chore: add another test and fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
p-spacek committed Oct 13, 2023
1 parent be8ace5 commit 7ca0300
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 13 deletions.
52 changes: 39 additions & 13 deletions test/autoCompletionFix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -882,8 +882,8 @@ objB:
},
},
};
languageService.addSchema(SCHEMA_ID, schema);
const content = 'array:\n - na| | ';
schemaProvider.addSchema(SCHEMA_ID, schema);
const content = 'array:\n - obj| | ';
const completion = await parseCaret(content);

expect(completion.items.length).equal(1);
Expand Down Expand Up @@ -1109,6 +1109,41 @@ objB:
expect(result.items.length).to.be.equal(1);
expect(result.items[0].insertText).to.be.equal('objA:\n itemA: ');
});

it('array completion - should suggest correct indent when extra spaces after cursor followed by with different array item', async () => {
schemaProvider.addSchema(SCHEMA_ID, {
type: 'object',
properties: {
test: {
type: 'array',
items: {
type: 'object',
properties: {
objA: {
type: 'object',
required: ['itemA'],
properties: {
itemA: {
type: 'string',
},
},
},
},
},
},
},
});
const content = `
test:
- | |
- objA:
itemA: test`;
const result = await parseCaret(content);

expect(result.items.length).to.be.equal(1);
expect(result.items[0].insertText).to.be.equal('objA:\n itemA: ');
});

it('array of arrays completion - should suggest correct indent when extra spaces after cursor', async () => {
schemaProvider.addSchema(SCHEMA_ID, {
type: 'object',
Expand Down Expand Up @@ -1207,27 +1242,18 @@ objB:
},
};
it('should get extra space compensation for the 1st prop in array object item', async () => {
languageService.addSchema(SCHEMA_ID, schema);
schemaProvider.addSchema(SCHEMA_ID, schema);
const content = 'array1:\n - |\n| propB: test';
const result = await parseCaret(content);

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

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

expect(result.items.length).to.be.equal(1);
expect(result.items[0].insertText).to.be.equal('objA:\n ');
});
Expand Down
12 changes: 12 additions & 0 deletions test/yaml-documents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,18 @@ objB:
});

describe('Array', () => {
// Problem in `getNodeFromPosition` function. This method doesn't give proper results for arrays
// for example, this yaml return nodes:
// foo:
// - # foo object is returned (should be foo[0])
// # foo object is returned (should be foo[0])
// item1: aaaf
// # foo[0] object is returned (OK)
// - # foo object is returned (should be foo[1])
// # foo[!!0!!] object is returned (should be foo[1])
// item2: bbb
// # foo[1] object is returned (OK)

it('Find closes node: array', () => {
const doc = setupTextDocument('foo:\n - bar: aaa\n ');
const yamlDoc = documents.getYamlDocument(doc);
Expand Down

0 comments on commit 7ca0300

Please sign in to comment.