Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintain quotes for boolean values in defaultSnippets #234

Merged
merged 1 commit into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/languageservice/services/yamlCompletion.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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