Skip to content

Commit 62fa41c

Browse files
authored
Merge pull request #241 from timo-klarshift/issue-118-null-literals
Issue 118 null literals
2 parents 0b6739e + 003e8fc commit 62fa41c

File tree

3 files changed

+54
-12
lines changed

3 files changed

+54
-12
lines changed

src/languageservice/parser/yamlParser07.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function recursivelyBuildAst(parent: ASTNode, node: Yaml.YAMLNode): ASTNode {
117117

118118
switch (type) {
119119
case Yaml.ScalarType.null: {
120-
return new StringASTNodeImpl(parent, instance.startPosition, instance.endPosition - instance.startPosition);
120+
return new NullASTNodeImpl(parent, node.startPosition, node.endPosition - node.startPosition);
121121
}
122122
case Yaml.ScalarType.bool: {
123123
return new BooleanASTNodeImpl(parent, Yaml.parseYamlBoolean(value), node.startPosition, node.endPosition - node.startPosition);

test/documentSymbols.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ suite('Document Symbols Tests', () => {
8080
assert.equal(symbols.length, 1);
8181
assert.deepEqual(
8282
symbols[0],
83-
createExpectedSymbolInformation('apiVersion', 15, undefined, TEST_URI, 0, 0, 0, 16)
83+
createExpectedSymbolInformation('apiVersion', SymbolKind.Variable, undefined, TEST_URI, 0, 0, 0, 16)
8484
);
8585
});
8686

@@ -90,7 +90,7 @@ suite('Document Symbols Tests', () => {
9090
assert.equal(symbols.length, 1);
9191
assert.deepEqual(
9292
symbols[0],
93-
createExpectedSymbolInformation('items', 18, undefined, TEST_URI, 0, 0, 2, 8)
93+
createExpectedSymbolInformation('items', SymbolKind.Array, undefined, TEST_URI, 0, 0, 2, 8)
9494
);
9595
});
9696

@@ -221,7 +221,7 @@ suite('Document Symbols Tests', () => {
221221
assert.equal(symbols.length, 1);
222222
assert.deepEqual(
223223
symbols[0],
224-
createExpectedDocumentSymbol('apiVersion', SymbolKind.String, 0, 0, 0, 16, 0, 0, 0, 10)
224+
createExpectedDocumentSymbol('apiVersion', SymbolKind.Variable, 0, 0, 0, 16, 0, 0, 0, 10)
225225
);
226226
});
227227

test/schemaValidation.test.ts

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,6 @@ suite('Validation Tests', () => {
9696
}).then(done, done);
9797
});
9898

99-
it('Null scalar value should be treated as string', done => {
100-
const content = 'cwd: Null';
101-
const validator = parseSetup(content);
102-
validator.then(function (result) {
103-
assert.equal(result.length, 0);
104-
}).then(done, done);
105-
});
106-
10799
it('Anchor should not not error', done => {
108100
const content = 'default: &DEFAULT\n name: Anchor\nanchor_test:\n <<: *DEFAULT';
109101
const validator = parseSetup(content);
@@ -430,5 +422,55 @@ suite('Validation Tests', () => {
430422
}).then(done, done);
431423
});
432424
});
425+
426+
// https://github.com/redhat-developer/yaml-language-server/issues/118
427+
describe('Null literals', () => {
428+
['NULL', 'Null', 'null', '~', ''].forEach(content => {
429+
it(`Test type null is parsed from [${content}]`, done => {
430+
const schema = {
431+
type: 'null'
432+
};
433+
languageService.configure({
434+
schemas: [{
435+
uri: 'file://test.yaml',
436+
fileMatch: ['*.yaml', '*.yml'],
437+
schema
438+
}],
439+
validate: true
440+
});
441+
const validator = parseSetup(content);
442+
validator.then(function (result) {
443+
assert.equal(result.length, 0);
444+
}).then(done, done);
445+
});
446+
});
447+
448+
it('Test type null is working correctly in array', done => {
449+
const schema = {
450+
properties: {
451+
values: {
452+
type: 'array',
453+
items: {
454+
type: 'null'
455+
}
456+
}
457+
},
458+
required: ['values']
459+
};
460+
languageService.configure({
461+
schemas: [{
462+
uri: 'file://test.yaml',
463+
fileMatch: ['*.yaml', '*.yml'],
464+
schema
465+
}],
466+
validate: true
467+
});
468+
const content = 'values: [Null, NULL, null, ~,]';
469+
const validator = parseSetup(content);
470+
validator.then(function (result) {
471+
assert.equal(result.length, 0);
472+
}).then(done, done);
473+
});
474+
});
433475
});
434476
});

0 commit comments

Comments
 (0)