Skip to content

Commit

Permalink
Maintain quotes for boolean values in defaultSnippets
Browse files Browse the repository at this point in the history
  • Loading branch information
JPinkney committed Feb 5, 2020
1 parent 189621c commit 85a3131
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/languageservice/services/yamlCompletion.ts
Expand Up @@ -495,6 +495,9 @@ export class YAMLCompletion extends JSONCompletion {
if (value[0] === '^') {
return value.substr(1);
}
if (value === 'true' || value === 'false') {
return `\"${value}\"`;
}
}
return value;
};
Expand Down
26 changes: 24 additions & 2 deletions test/defaultSnippets.test.ts
Expand Up @@ -150,7 +150,7 @@ suite('Default Snippet Tests', () => {
const content = 'lon ';
const completion = parseSetup(content, 3);
completion.then(function (result) {
assert.equal(result.items.length, 6); // This is just checking the total number of snippets in the defaultSnippets.json
assert.equal(result.items.length, 8); // This is just checking the total number of snippets in the defaultSnippets.json
assert.equal(result.items[4].label, 'longSnippet');
// tslint:disable-next-line:max-line-length
assert.equal(result.items[4].insertText, 'longSnippet:\n name: $1\n taskRef: \n name: apply-manifests \n resources: \n inputs: \n - name: source\n resource: $3 \n params: \n - name: manifest_dir\n value: $2 ');
Expand All @@ -161,7 +161,7 @@ suite('Default Snippet Tests', () => {
const content = 'arrayArrayS ';
const completion = parseSetup(content, 11);
completion.then(function (result) {
assert.equal(result.items.length, 6); // This is just checking the total number of snippets in the defaultSnippets.json
assert.equal(result.items.length, 8); // This is just checking the total number of snippets in the defaultSnippets.json
assert.equal(result.items[5].label, 'arrayArraySnippet');
// tslint:disable-next-line:max-line-length
assert.equal(result.items[5].insertText, 'arrayArraySnippet:\n apple: \n - - name: source\n resource: $3 ');
Expand Down Expand Up @@ -189,5 +189,27 @@ suite('Default Snippet Tests', () => {
assert.equal(result.items[0].insertText, 'apple: \n - - name: source\n resource: $3');
}).then(done, done);
});

it('Test string with boolean in string should insert string', done => {
const content = 'simpleBooleanString: ';
const completion = parseSetup(content, 21);
completion.then(function (result) {
assert.equal(result.items.length, 1);
assert.equal(result.items[0].label, 'Simple boolean string');
// tslint:disable-next-line:max-line-length
assert.equal(result.items[0].insertText, '\n test: \"true\"');
}).then(done, done);
});

it('Test string with boolean NOT in string should insert boolean', done => {
const content = 'simpleBoolean: ';
const completion = parseSetup(content, 15);
completion.then(function (result) {
assert.equal(result.items.length, 1);
assert.equal(result.items[0].label, 'Simple string');
// tslint:disable-next-line:max-line-length
assert.equal(result.items[0].insertText, '\n test: true');
}).then(done, done);
});
});
});
26 changes: 25 additions & 1 deletion test/fixtures/defaultSnippets.json
Expand Up @@ -96,7 +96,31 @@
]
]
}
}
}
]
},
"simpleBooleanString": {
"type": "object",
"defaultSnippets": [
{
"label": "Simple boolean string",
"description": "Simple boolean string insert",
"body": {
"test": "true"
}
}
]
},
"simpleBoolean": {
"type": "object",
"defaultSnippets": [
{
"label": "Simple string",
"description": "Simple string insert",
"body": {
"test": true
}
}
]
}
}
Expand Down

0 comments on commit 85a3131

Please sign in to comment.