mirror of
https://github.com/danbulant/monaco-yaml
synced 2026-07-05 02:50:47 +00:00
style: lint files
This commit is contained in:
parent
1e0e5ebb54
commit
84e82b52f7
22 changed files with 338 additions and 317 deletions
|
|
@ -213,7 +213,7 @@ export interface ISchemaCollector {
|
||||||
|
|
||||||
class SchemaCollector implements ISchemaCollector {
|
class SchemaCollector implements ISchemaCollector {
|
||||||
public schemas: IApplicableSchema[] = [];
|
public schemas: IApplicableSchema[] = [];
|
||||||
constructor(private focusOffset = -1, private exclude: ASTNode = null) { }
|
constructor(private focusOffset = -1, private exclude: ASTNode = null) {}
|
||||||
public add(schema: IApplicableSchema) {
|
public add(schema: IApplicableSchema) {
|
||||||
this.schemas.push(schema);
|
this.schemas.push(schema);
|
||||||
}
|
}
|
||||||
|
|
@ -237,9 +237,9 @@ class NoOpSchemaCollector implements ISchemaCollector {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static instance = new NoOpSchemaCollector();
|
public static instance = new NoOpSchemaCollector();
|
||||||
private constructor() { }
|
private constructor() {}
|
||||||
public add(schema: IApplicableSchema) { }
|
public add(schema: IApplicableSchema) {}
|
||||||
public merge(other: ISchemaCollector) { }
|
public merge(other: ISchemaCollector) {}
|
||||||
public include(node: ASTNode) {
|
public include(node: ASTNode) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -389,7 +389,7 @@ export class JSONDocument {
|
||||||
public root: ASTNode,
|
public root: ASTNode,
|
||||||
public readonly syntaxErrors: Diagnostic[] = [],
|
public readonly syntaxErrors: Diagnostic[] = [],
|
||||||
public readonly comments: Range[] = []
|
public readonly comments: Range[] = []
|
||||||
) { }
|
) {}
|
||||||
|
|
||||||
public getNodeFromOffset(
|
public getNodeFromOffset(
|
||||||
offset: number,
|
offset: number,
|
||||||
|
|
@ -1110,13 +1110,15 @@ function validate(
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'array': {
|
case 'array': {
|
||||||
propertyNode.valueNode.items.forEach((sequenceNode: ObjectASTNode) => {
|
propertyNode.valueNode.items.forEach(
|
||||||
sequenceNode.properties.forEach(propASTNode => {
|
(sequenceNode: ObjectASTNode) => {
|
||||||
const seqKey = propASTNode.keyNode.value;
|
sequenceNode.properties.forEach(propASTNode => {
|
||||||
seenKeys[seqKey] = propASTNode.valueNode;
|
const seqKey = propASTNode.keyNode.value;
|
||||||
unprocessedProperties.push(seqKey);
|
seenKeys[seqKey] = propASTNode.valueNode;
|
||||||
});
|
unprocessedProperties.push(seqKey);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
|
|
||||||
|
|
@ -226,11 +226,10 @@ function recursivelyBuildAst(parent: ASTNode, node: Yaml.YAMLNode): ASTNode {
|
||||||
function convertError(e: Yaml.Error) {
|
function convertError(e: Yaml.Error) {
|
||||||
return {
|
return {
|
||||||
message: `${e.reason}`,
|
message: `${e.reason}`,
|
||||||
// TODO: YAML ast parser does not give a length for validation error,
|
// TODO: YAML ast parser does not give a length for validation error.
|
||||||
// TODO: thus we treat the range from line start to the target position.
|
|
||||||
location: {
|
location: {
|
||||||
offset: e.mark.position - e.mark.column,
|
offset: e.mark.position,
|
||||||
length: e.mark.column,
|
length: 0,
|
||||||
},
|
},
|
||||||
code: ErrorCode.Undefined,
|
code: ErrorCode.Undefined,
|
||||||
severity: e.isWarning
|
severity: e.isWarning
|
||||||
|
|
|
||||||
|
|
@ -557,7 +557,7 @@ export class JSONSchemaService implements IJSONSchemaService {
|
||||||
next.allOf,
|
next.allOf,
|
||||||
next.oneOf,
|
next.oneOf,
|
||||||
next.items as JSONSchema[],
|
next.items as JSONSchema[],
|
||||||
next.schemaSequence,
|
next.schemaSequence
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,7 @@ export class YamlFormatter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
doFormat(
|
doFormat(document: TextDocument, options: FormattingOptions): TextEdit[] {
|
||||||
document: TextDocument,
|
|
||||||
options: FormattingOptions,
|
|
||||||
): TextEdit[] {
|
|
||||||
const text = document.getText();
|
const text = document.getText();
|
||||||
const customTags = this.customTags || [];
|
const customTags = this.customTags || [];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,11 +29,11 @@ export class YAMLHover {
|
||||||
private contributions: JSONWorkerContribution[] = []
|
private contributions: JSONWorkerContribution[] = []
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public configure(languageSettings: LanguageSettings){
|
public configure(languageSettings: LanguageSettings) {
|
||||||
if(languageSettings){
|
if (languageSettings) {
|
||||||
this.shouldHover = !!languageSettings.hover;
|
this.shouldHover = !!languageSettings.hover;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public doHover(
|
public doHover(
|
||||||
document: TextDocument,
|
document: TextDocument,
|
||||||
|
|
@ -95,8 +95,14 @@ export class YAMLHover {
|
||||||
.then(schema => {
|
.then(schema => {
|
||||||
if (schema) {
|
if (schema) {
|
||||||
let newSchema = schema;
|
let newSchema = schema;
|
||||||
if (schema.schema && schema.schema.schemaSequence && schema.schema.schemaSequence[currentDocIndex]) {
|
if (
|
||||||
newSchema = new SchemaService.ResolvedSchema(schema.schema.schemaSequence[currentDocIndex]);
|
schema.schema &&
|
||||||
|
schema.schema.schemaSequence &&
|
||||||
|
schema.schema.schemaSequence[currentDocIndex]
|
||||||
|
) {
|
||||||
|
newSchema = new SchemaService.ResolvedSchema(
|
||||||
|
schema.schema.schemaSequence[currentDocIndex]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const matchingSchemas = currentDoc.getMatchingSchemas(
|
const matchingSchemas = currentDoc.getMatchingSchemas(
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,11 @@
|
||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import { DiagnosticSeverity, TextDocument, Diagnostic } from 'vscode-languageserver-types';
|
import {
|
||||||
|
DiagnosticSeverity,
|
||||||
|
TextDocument,
|
||||||
|
Diagnostic,
|
||||||
|
} from 'vscode-languageserver-types';
|
||||||
import { LanguageSettings } from '../yamlLanguageService';
|
import { LanguageSettings } from '../yamlLanguageService';
|
||||||
import { YAMLDocument } from '../yamlLanguageTypes';
|
import { YAMLDocument } from '../yamlLanguageTypes';
|
||||||
import { JSONSchemaService, ResolvedSchema } from './jsonSchemaService';
|
import { JSONSchemaService, ResolvedSchema } from './jsonSchemaService';
|
||||||
|
|
@ -23,13 +27,16 @@ export class YAMLValidation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public doValidation(textDocument: TextDocument, yamlDocument: YAMLDocument): Thenable<Diagnostic[]> {
|
public doValidation(
|
||||||
|
textDocument: TextDocument,
|
||||||
|
yamlDocument: YAMLDocument
|
||||||
|
): Thenable<Diagnostic[]> {
|
||||||
if (!this.validationEnabled) {
|
if (!this.validationEnabled) {
|
||||||
return Promise.resolve([]);
|
return Promise.resolve([]);
|
||||||
}
|
}
|
||||||
return this.jsonSchemaService
|
return this.jsonSchemaService
|
||||||
.getSchemaForResource(textDocument.uri)
|
.getSchemaForResource(textDocument.uri)
|
||||||
.then(function (schema) {
|
.then(function(schema) {
|
||||||
const diagnostics: Diagnostic[] = [];
|
const diagnostics: Diagnostic[] = [];
|
||||||
const added = {};
|
const added = {};
|
||||||
let newSchema = schema;
|
let newSchema = schema;
|
||||||
|
|
@ -55,7 +62,9 @@ export class YAMLValidation {
|
||||||
currentDoc.errors.push({
|
currentDoc.errors.push({
|
||||||
location: {
|
location: {
|
||||||
offset: textDocument.offsetAt(curDiagnostic.range.start),
|
offset: textDocument.offsetAt(curDiagnostic.range.start),
|
||||||
length: textDocument.offsetAt(curDiagnostic.range.end) - textDocument.offsetAt(curDiagnostic.range.start),
|
length:
|
||||||
|
textDocument.offsetAt(curDiagnostic.range.end) -
|
||||||
|
textDocument.offsetAt(curDiagnostic.range.start),
|
||||||
},
|
},
|
||||||
message: curDiagnostic.message,
|
message: curDiagnostic.message,
|
||||||
severity: curDiagnostic.severity,
|
severity: curDiagnostic.severity,
|
||||||
|
|
@ -86,7 +95,7 @@ export class YAMLValidation {
|
||||||
const currentDoc = yamlDocument.documents[currentYAMLDoc];
|
const currentDoc = yamlDocument.documents[currentYAMLDoc];
|
||||||
currentDoc.errors
|
currentDoc.errors
|
||||||
.concat(currentDoc.warnings)
|
.concat(currentDoc.warnings)
|
||||||
.forEach(function (error, idx) {
|
.forEach(function(error, idx) {
|
||||||
// remove duplicated messages
|
// remove duplicated messages
|
||||||
const signature =
|
const signature =
|
||||||
error.location.offset +
|
error.location.offset +
|
||||||
|
|
@ -103,7 +112,9 @@ export class YAMLValidation {
|
||||||
: DiagnosticSeverity.Error,
|
: DiagnosticSeverity.Error,
|
||||||
range: {
|
range: {
|
||||||
start: textDocument.positionAt(error.location.offset),
|
start: textDocument.positionAt(error.location.offset),
|
||||||
end: textDocument.positionAt(error.location.offset + error.location.length),
|
end: textDocument.positionAt(
|
||||||
|
error.location.offset + error.location.length
|
||||||
|
),
|
||||||
},
|
},
|
||||||
message: error.message,
|
message: error.message,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@ import {
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
describe('Array Utils Tests', () => {
|
describe('Array Utils Tests', () => {
|
||||||
describe('Server - Array Utils', function () {
|
describe('Server - Array Utils', function() {
|
||||||
describe('removeDuplicates', function () {
|
describe('removeDuplicates', function() {
|
||||||
it('Remove one duplicate with property', () => {
|
it('Remove one duplicate with property', () => {
|
||||||
const obj1 = {
|
const obj1 = {
|
||||||
test_key: 'test_value',
|
test_key: 'test_value',
|
||||||
|
|
@ -69,7 +69,7 @@ describe('Array Utils Tests', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getLineOffsets', function () {
|
describe('getLineOffsets', function() {
|
||||||
it('No offset', () => {
|
it('No offset', () => {
|
||||||
const offsets = getLineOffsets('');
|
const offsets = getLineOffsets('');
|
||||||
assert.equal(offsets.length, 0);
|
assert.equal(offsets.length, 0);
|
||||||
|
|
@ -89,7 +89,7 @@ describe('Array Utils Tests', () => {
|
||||||
|
|
||||||
it('Multiple offsets', () => {
|
it('Multiple offsets', () => {
|
||||||
const offsets = getLineOffsets(
|
const offsets = getLineOffsets(
|
||||||
'first_offset\n second_offset\n third_offset',
|
'first_offset\n second_offset\n third_offset'
|
||||||
);
|
);
|
||||||
assert.equal(offsets.length, 3);
|
assert.equal(offsets.length, 3);
|
||||||
assert.equal(offsets[0], 0);
|
assert.equal(offsets[0], 0);
|
||||||
|
|
@ -98,7 +98,7 @@ describe('Array Utils Tests', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('removeDuplicatesObj', function () {
|
describe('removeDuplicatesObj', function() {
|
||||||
it('Remove one duplicate with property', () => {
|
it('Remove one duplicate with property', () => {
|
||||||
const obj1 = {
|
const obj1 = {
|
||||||
test_key: 'test_value',
|
test_key: 'test_value',
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ const assert = require('assert');
|
||||||
const languageService = getLanguageService(
|
const languageService = getLanguageService(
|
||||||
schemaRequestService,
|
schemaRequestService,
|
||||||
workspaceContext,
|
workspaceContext,
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const uri = 'http://json.schemastore.org/bowerrc';
|
const uri = 'http://json.schemastore.org/bowerrc';
|
||||||
|
|
@ -25,14 +25,14 @@ languageSettings.schemas.push({ uri, fileMatch });
|
||||||
languageService.configure(languageSettings);
|
languageService.configure(languageSettings);
|
||||||
|
|
||||||
describe('Auto Completion Tests', () => {
|
describe('Auto Completion Tests', () => {
|
||||||
describe('yamlCompletion with bowerrc', function () {
|
describe('yamlCompletion with bowerrc', function() {
|
||||||
describe('doComplete', function () {
|
describe('doComplete', function() {
|
||||||
function setup(content: string) {
|
function setup(content: string) {
|
||||||
return TextDocument.create(
|
return TextDocument.create(
|
||||||
'file://~/Desktop/vscode-k8s/test.yaml',
|
'file://~/Desktop/vscode-k8s/test.yaml',
|
||||||
'yaml',
|
'yaml',
|
||||||
0,
|
0,
|
||||||
content,
|
content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,145 +40,145 @@ describe('Auto Completion Tests', () => {
|
||||||
const testTextDocument = setup(content);
|
const testTextDocument = setup(content);
|
||||||
return completionHelper(
|
return completionHelper(
|
||||||
testTextDocument,
|
testTextDocument,
|
||||||
testTextDocument.positionAt(position),
|
testTextDocument.positionAt(position)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
it('Autocomplete on root node without word', (done) => {
|
it('Autocomplete on root node without word', done => {
|
||||||
const content = '';
|
const content = '';
|
||||||
const completion = parseSetup(content, 0);
|
const completion = parseSetup(content, 0);
|
||||||
completion
|
completion
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.items.length, 0);
|
assert.notEqual(result.items.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete on root node with word', (done) => {
|
it('Autocomplete on root node with word', done => {
|
||||||
const content = 'analyt';
|
const content = 'analyt';
|
||||||
const completion = parseSetup(content, 6);
|
const completion = parseSetup(content, 6);
|
||||||
completion
|
completion
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.items.length, 0);
|
assert.notEqual(result.items.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete on default value (without value content)', (done) => {
|
it('Autocomplete on default value (without value content)', done => {
|
||||||
const content = 'directory: ';
|
const content = 'directory: ';
|
||||||
const completion = parseSetup(content, 12);
|
const completion = parseSetup(content, 12);
|
||||||
completion
|
completion
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.items.length).toEqual(1);
|
expect(result.items.length).toEqual(1);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete on default value (with value content)', (done) => {
|
it('Autocomplete on default value (with value content)', done => {
|
||||||
const content = 'directory: bow';
|
const content = 'directory: bow';
|
||||||
const completion = parseSetup(content, 15);
|
const completion = parseSetup(content, 15);
|
||||||
completion
|
completion
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.items.length, 0);
|
assert.notEqual(result.items.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete on boolean value (without value content)', (done) => {
|
it('Autocomplete on boolean value (without value content)', done => {
|
||||||
const content = 'analytics: ';
|
const content = 'analytics: ';
|
||||||
const completion = parseSetup(content, 11);
|
const completion = parseSetup(content, 11);
|
||||||
completion
|
completion
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.items.length).toEqual(2);
|
expect(result.items.length).toEqual(2);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete on boolean value (with value content)', (done) => {
|
it('Autocomplete on boolean value (with value content)', done => {
|
||||||
const content = 'analytics: fal';
|
const content = 'analytics: fal';
|
||||||
const completion = parseSetup(content, 11);
|
const completion = parseSetup(content, 11);
|
||||||
completion
|
completion
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.equal(result.items.length, 2);
|
assert.equal(result.items.length, 2);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete on number value (without value content)', (done) => {
|
it('Autocomplete on number value (without value content)', done => {
|
||||||
const content = 'timeout: ';
|
const content = 'timeout: ';
|
||||||
const completion = parseSetup(content, 9);
|
const completion = parseSetup(content, 9);
|
||||||
completion
|
completion
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.items.length).toEqual(1);
|
expect(result.items.length).toEqual(1);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete on number value (with value content)', (done) => {
|
it('Autocomplete on number value (with value content)', done => {
|
||||||
const content = 'timeout: 6';
|
const content = 'timeout: 6';
|
||||||
const completion = parseSetup(content, 10);
|
const completion = parseSetup(content, 10);
|
||||||
completion
|
completion
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.equal(result.items.length, 1);
|
assert.equal(result.items.length, 1);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete key in middle of file', (done) => {
|
it('Autocomplete key in middle of file', done => {
|
||||||
const content = 'scripts:\n post';
|
const content = 'scripts:\n post';
|
||||||
const completion = parseSetup(content, 11);
|
const completion = parseSetup(content, 11);
|
||||||
completion
|
completion
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.items.length, 0);
|
assert.notEqual(result.items.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete key in middle of file 2', (done) => {
|
it('Autocomplete key in middle of file 2', done => {
|
||||||
const content = 'scripts:\n postinstall: /test\n preinsta';
|
const content = 'scripts:\n postinstall: /test\n preinsta';
|
||||||
const completion = parseSetup(content, 31);
|
const completion = parseSetup(content, 31);
|
||||||
completion
|
completion
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.items.length, 0);
|
assert.notEqual(result.items.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete does not happen right after :', (done) => {
|
it('Autocomplete does not happen right after :', done => {
|
||||||
const content = 'analytics:';
|
const content = 'analytics:';
|
||||||
const completion = parseSetup(content, 9);
|
const completion = parseSetup(content, 9);
|
||||||
completion
|
completion
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.items.length, 0);
|
assert.notEqual(result.items.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete does not happen right after : under an object', (done) => {
|
it('Autocomplete does not happen right after : under an object', done => {
|
||||||
const content = 'scripts:\n postinstall:';
|
const content = 'scripts:\n postinstall:';
|
||||||
const completion = parseSetup(content, 21);
|
const completion = parseSetup(content, 21);
|
||||||
completion
|
completion
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.items.length, 0);
|
assert.notEqual(result.items.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete on multi yaml documents in a single file on root', (done) => {
|
it('Autocomplete on multi yaml documents in a single file on root', done => {
|
||||||
const content = `---\nanalytics: true\n...\n---\n...`;
|
const content = `---\nanalytics: true\n...\n---\n...`;
|
||||||
const completion = parseSetup(content, 28);
|
const completion = parseSetup(content, 28);
|
||||||
completion
|
completion
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.items.length, 0);
|
assert.notEqual(result.items.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete on multi yaml documents in a single file on scalar', (done) => {
|
it('Autocomplete on multi yaml documents in a single file on scalar', done => {
|
||||||
const content = `---\nanalytics: true\n...\n---\njson: \n...`;
|
const content = `---\nanalytics: true\n...\n---\njson: \n...`;
|
||||||
const completion = parseSetup(content, 34);
|
const completion = parseSetup(content, 34);
|
||||||
completion
|
completion
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.items.length, 0);
|
assert.notEqual(result.items.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ const assert = require('assert');
|
||||||
const languageService = getLanguageService(
|
const languageService = getLanguageService(
|
||||||
schemaRequestService,
|
schemaRequestService,
|
||||||
workspaceContext,
|
workspaceContext,
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const uri = 'http://json.schemastore.org/composer';
|
const uri = 'http://json.schemastore.org/composer';
|
||||||
|
|
@ -30,7 +30,7 @@ describe('Auto Completion Tests', () => {
|
||||||
'file://~/Desktop/vscode-k8s/test.yaml',
|
'file://~/Desktop/vscode-k8s/test.yaml',
|
||||||
'yaml',
|
'yaml',
|
||||||
0,
|
0,
|
||||||
content,
|
content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -38,13 +38,13 @@ describe('Auto Completion Tests', () => {
|
||||||
const testTextDocument = setup(content);
|
const testTextDocument = setup(content);
|
||||||
return completionHelper(
|
return completionHelper(
|
||||||
testTextDocument,
|
testTextDocument,
|
||||||
testTextDocument.positionAt(position),
|
testTextDocument.positionAt(position)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('yamlCompletion with composer', function() {
|
describe('yamlCompletion with composer', function() {
|
||||||
describe('doComplete', function() {
|
describe('doComplete', function() {
|
||||||
it('Array autocomplete without word', (done) => {
|
it('Array autocomplete without word', done => {
|
||||||
const content = 'authors:\n - ';
|
const content = 'authors:\n - ';
|
||||||
const completion = parseSetup(content, 14);
|
const completion = parseSetup(content, 14);
|
||||||
completion
|
completion
|
||||||
|
|
@ -54,7 +54,7 @@ describe('Auto Completion Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Array autocomplete without word on array symbol', (done) => {
|
it('Array autocomplete without word on array symbol', done => {
|
||||||
const content = 'authors:\n -';
|
const content = 'authors:\n -';
|
||||||
const completion = parseSetup(content, 13);
|
const completion = parseSetup(content, 13);
|
||||||
completion
|
completion
|
||||||
|
|
@ -64,7 +64,7 @@ describe('Auto Completion Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Array autocomplete without word on space before array symbol', (done) => {
|
it('Array autocomplete without word on space before array symbol', done => {
|
||||||
const content = 'authors:\n - name: test\n ';
|
const content = 'authors:\n - name: test\n ';
|
||||||
const completion = parseSetup(content, 24);
|
const completion = parseSetup(content, 24);
|
||||||
completion
|
completion
|
||||||
|
|
@ -74,7 +74,7 @@ describe('Auto Completion Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Array autocomplete with letter', (done) => {
|
it('Array autocomplete with letter', done => {
|
||||||
const content = 'authors:\n - n';
|
const content = 'authors:\n - n';
|
||||||
const completion = parseSetup(content, 14);
|
const completion = parseSetup(content, 14);
|
||||||
completion
|
completion
|
||||||
|
|
@ -84,7 +84,7 @@ describe('Auto Completion Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Array autocomplete without word (second item)', (done) => {
|
it('Array autocomplete without word (second item)', done => {
|
||||||
const content = 'authors:\n - name: test\n ';
|
const content = 'authors:\n - name: test\n ';
|
||||||
const completion = parseSetup(content, 32);
|
const completion = parseSetup(content, 32);
|
||||||
completion
|
completion
|
||||||
|
|
@ -94,7 +94,7 @@ describe('Auto Completion Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Array autocomplete with letter (second item)', (done) => {
|
it('Array autocomplete with letter (second item)', done => {
|
||||||
const content = 'authors:\n - name: test\n e';
|
const content = 'authors:\n - name: test\n e';
|
||||||
const completion = parseSetup(content, 27);
|
const completion = parseSetup(content, 27);
|
||||||
completion
|
completion
|
||||||
|
|
@ -104,7 +104,7 @@ describe('Auto Completion Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocompletion after array', (done) => {
|
it('Autocompletion after array', done => {
|
||||||
const content = 'authors:\n - name: test\n';
|
const content = 'authors:\n - name: test\n';
|
||||||
const completion = parseSetup(content, 24);
|
const completion = parseSetup(content, 24);
|
||||||
completion
|
completion
|
||||||
|
|
@ -114,7 +114,7 @@ describe('Auto Completion Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocompletion after array with depth', (done) => {
|
it('Autocompletion after array with depth', done => {
|
||||||
const content = 'archive:\n exclude:\n - test\n';
|
const content = 'archive:\n exclude:\n - test\n';
|
||||||
const completion = parseSetup(content, 29);
|
const completion = parseSetup(content, 29);
|
||||||
completion
|
completion
|
||||||
|
|
@ -124,7 +124,7 @@ describe('Auto Completion Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocompletion after array with depth', (done) => {
|
it('Autocompletion after array with depth', done => {
|
||||||
const content =
|
const content =
|
||||||
'autoload:\n classmap:\n - test\n exclude-from-classmap:\n - test\n ';
|
'autoload:\n classmap:\n - test\n exclude-from-classmap:\n - test\n ';
|
||||||
const completion = parseSetup(content, 70);
|
const completion = parseSetup(content, 70);
|
||||||
|
|
@ -137,7 +137,7 @@ describe('Auto Completion Tests', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Failure tests', function() {
|
describe('Failure tests', function() {
|
||||||
it('Autocompletion has no results on value when they are not available', (done) => {
|
it('Autocompletion has no results on value when they are not available', done => {
|
||||||
const content = 'time: ';
|
const content = 'time: ';
|
||||||
const completion = parseSetup(content, 6);
|
const completion = parseSetup(content, 6);
|
||||||
completion
|
completion
|
||||||
|
|
@ -147,7 +147,7 @@ describe('Auto Completion Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocompletion has no results on value when they are not available (with depth)', (done) => {
|
it('Autocompletion has no results on value when they are not available (with depth)', done => {
|
||||||
const content = 'archive:\n exclude:\n - test\n ';
|
const content = 'archive:\n exclude:\n - test\n ';
|
||||||
const completion = parseSetup(content, 33);
|
const completion = parseSetup(content, 33);
|
||||||
completion
|
completion
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ const assert = require('assert');
|
||||||
const languageService = getLanguageService(
|
const languageService = getLanguageService(
|
||||||
schemaRequestService,
|
schemaRequestService,
|
||||||
workspaceContext,
|
workspaceContext,
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const uri = 'http://json.schemastore.org/asmdef';
|
const uri = 'http://json.schemastore.org/asmdef';
|
||||||
|
|
@ -32,7 +32,7 @@ describe('Auto Completion Tests', () => {
|
||||||
'file://~/Desktop/vscode-k8s/test.yaml',
|
'file://~/Desktop/vscode-k8s/test.yaml',
|
||||||
'yaml',
|
'yaml',
|
||||||
0,
|
0,
|
||||||
content,
|
content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,11 +40,11 @@ describe('Auto Completion Tests', () => {
|
||||||
const testTextDocument = setup(content);
|
const testTextDocument = setup(content);
|
||||||
return completionHelper(
|
return completionHelper(
|
||||||
testTextDocument,
|
testTextDocument,
|
||||||
testTextDocument.positionAt(position),
|
testTextDocument.positionAt(position)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
it('Array of enum autocomplete without word on array symbol', (done) => {
|
it('Array of enum autocomplete without word on array symbol', done => {
|
||||||
const content = 'optionalUnityReferences:\n -';
|
const content = 'optionalUnityReferences:\n -';
|
||||||
const completion = parseSetup(content, 29);
|
const completion = parseSetup(content, 29);
|
||||||
completion
|
completion
|
||||||
|
|
@ -54,7 +54,7 @@ describe('Auto Completion Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Array of enum autocomplete without word', (done) => {
|
it('Array of enum autocomplete without word', done => {
|
||||||
const content = 'optionalUnityReferences:\n - ';
|
const content = 'optionalUnityReferences:\n - ';
|
||||||
const completion = parseSetup(content, 30);
|
const completion = parseSetup(content, 30);
|
||||||
completion
|
completion
|
||||||
|
|
@ -64,7 +64,7 @@ describe('Auto Completion Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Array of enum autocomplete with letter', (done) => {
|
it('Array of enum autocomplete with letter', done => {
|
||||||
const content = 'optionalUnityReferences:\n - T';
|
const content = 'optionalUnityReferences:\n - T';
|
||||||
const completion = parseSetup(content, 31);
|
const completion = parseSetup(content, 31);
|
||||||
completion
|
completion
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ const assert = require('assert');
|
||||||
const languageService = getLanguageService(
|
const languageService = getLanguageService(
|
||||||
schemaRequestService,
|
schemaRequestService,
|
||||||
workspaceContext,
|
workspaceContext,
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO: this suite is outdated and should be updated.
|
// TODO: this suite is outdated and should be updated.
|
||||||
|
|
@ -24,7 +24,7 @@ xdescribe('Document Symbols Tests', () => {
|
||||||
'file://~/Desktop/vscode-k8s/test.yaml',
|
'file://~/Desktop/vscode-k8s/test.yaml',
|
||||||
'yaml',
|
'yaml',
|
||||||
0,
|
0,
|
||||||
content,
|
content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -33,67 +33,67 @@ xdescribe('Document Symbols Tests', () => {
|
||||||
const jsonDocument = parseYAML(testTextDocument.getText());
|
const jsonDocument = parseYAML(testTextDocument.getText());
|
||||||
return languageService.findDocumentSymbols(
|
return languageService.findDocumentSymbols(
|
||||||
testTextDocument,
|
testTextDocument,
|
||||||
jsonDocument,
|
jsonDocument
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
it('Document is empty', (done) => {
|
it('Document is empty', done => {
|
||||||
const content = '';
|
const content = '';
|
||||||
const symbols = parseSetup(content);
|
const symbols = parseSetup(content);
|
||||||
assert.equal(symbols, null);
|
assert.equal(symbols, null);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Simple document symbols', (done) => {
|
it('Simple document symbols', done => {
|
||||||
const content = 'cwd: test';
|
const content = 'cwd: test';
|
||||||
const symbols = parseSetup(content);
|
const symbols = parseSetup(content);
|
||||||
assert.equal(symbols.length, 1);
|
assert.equal(symbols.length, 1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Document Symbols with number', (done) => {
|
it('Document Symbols with number', done => {
|
||||||
const content = 'node1: 10000';
|
const content = 'node1: 10000';
|
||||||
const symbols = parseSetup(content);
|
const symbols = parseSetup(content);
|
||||||
assert.equal(symbols.length, 1);
|
assert.equal(symbols.length, 1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Document Symbols with boolean', (done) => {
|
it('Document Symbols with boolean', done => {
|
||||||
const content = 'node1: False';
|
const content = 'node1: False';
|
||||||
const symbols = parseSetup(content);
|
const symbols = parseSetup(content);
|
||||||
assert.equal(symbols.length, 1);
|
assert.equal(symbols.length, 1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Document Symbols with object', (done) => {
|
it('Document Symbols with object', done => {
|
||||||
const content = 'scripts:\n node1: test\n node2: test';
|
const content = 'scripts:\n node1: test\n node2: test';
|
||||||
const symbols = parseSetup(content);
|
const symbols = parseSetup(content);
|
||||||
assert.equal(symbols.length, 3);
|
assert.equal(symbols.length, 3);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Document Symbols with null', (done) => {
|
it('Document Symbols with null', done => {
|
||||||
const content = 'apiVersion: null';
|
const content = 'apiVersion: null';
|
||||||
const symbols = parseSetup(content);
|
const symbols = parseSetup(content);
|
||||||
assert.equal(symbols.length, 1);
|
assert.equal(symbols.length, 1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Document Symbols with array of strings', (done) => {
|
it('Document Symbols with array of strings', done => {
|
||||||
const content = 'items:\n - test\n - test';
|
const content = 'items:\n - test\n - test';
|
||||||
const symbols = parseSetup(content);
|
const symbols = parseSetup(content);
|
||||||
assert.equal(symbols.length, 1);
|
assert.equal(symbols.length, 1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Document Symbols with array', (done) => {
|
it('Document Symbols with array', done => {
|
||||||
const content = 'authors:\n - name: Josh\n - email: jp';
|
const content = 'authors:\n - name: Josh\n - email: jp';
|
||||||
const symbols = parseSetup(content);
|
const symbols = parseSetup(content);
|
||||||
assert.equal(symbols.length, 3);
|
assert.equal(symbols.length, 3);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Document Symbols with object and array', (done) => {
|
it('Document Symbols with object and array', done => {
|
||||||
const content =
|
const content =
|
||||||
'scripts:\n node1: test\n node2: test\nauthors:\n - name: Josh\n - email: jp';
|
'scripts:\n node1: test\n node2: test\nauthors:\n - name: Josh\n - email: jp';
|
||||||
const symbols = parseSetup(content);
|
const symbols = parseSetup(content);
|
||||||
|
|
@ -101,7 +101,7 @@ xdescribe('Document Symbols Tests', () => {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Document Symbols with multi documents', (done) => {
|
it('Document Symbols with multi documents', done => {
|
||||||
const content = '---\nanalytics: true\n...\n---\njson: test\n...';
|
const content = '---\nanalytics: true\n...\n---\njson: test\n...';
|
||||||
const symbols = parseSetup(content);
|
const symbols = parseSetup(content);
|
||||||
assert.equal(symbols.length, 2);
|
assert.equal(symbols.length, 2);
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ const assert = require('assert');
|
||||||
const languageService = getLanguageService(
|
const languageService = getLanguageService(
|
||||||
schemaRequestService,
|
schemaRequestService,
|
||||||
workspaceContext,
|
workspaceContext,
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const uri = 'http://json.schemastore.org/bowerrc';
|
const uri = 'http://json.schemastore.org/bowerrc';
|
||||||
|
|
@ -32,7 +32,7 @@ describe('Formatter Tests', () => {
|
||||||
'file://~/Desktop/vscode-k8s/test.yaml',
|
'file://~/Desktop/vscode-k8s/test.yaml',
|
||||||
'yaml',
|
'yaml',
|
||||||
0,
|
0,
|
||||||
content,
|
content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,7 +42,7 @@ describe('Formatter Tests', () => {
|
||||||
const testTextDocument = setup(content);
|
const testTextDocument = setup(content);
|
||||||
const edits = languageService.doFormat(
|
const edits = languageService.doFormat(
|
||||||
testTextDocument,
|
testTextDocument,
|
||||||
{} as FormattingOptions,
|
{} as FormattingOptions
|
||||||
);
|
);
|
||||||
assert.notEqual(edits.length, 0);
|
assert.notEqual(edits.length, 0);
|
||||||
assert.equal(edits[0].newText, 'cwd: test\n');
|
assert.equal(edits[0].newText, 'cwd: test\n');
|
||||||
|
|
@ -53,7 +53,7 @@ describe('Formatter Tests', () => {
|
||||||
const testTextDocument = setup(content);
|
const testTextDocument = setup(content);
|
||||||
const edits = languageService.doFormat(
|
const edits = languageService.doFormat(
|
||||||
testTextDocument,
|
testTextDocument,
|
||||||
{} as FormattingOptions,
|
{} as FormattingOptions
|
||||||
);
|
);
|
||||||
assert.notEqual(edits.length, 0);
|
assert.notEqual(edits.length, 0);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,17 @@
|
||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
import { TextDocument } from 'vscode-languageserver';
|
import { TextDocument } from 'vscode-languageserver';
|
||||||
import { parse as parseYAML } from '../src/languageservice/parser/yamlParser';
|
import { parse as parseYAML } from '../src/languageservice/parser/yamlParser';
|
||||||
import { getLanguageService, LanguageSettings } from '../src/languageservice/yamlLanguageService';
|
import {
|
||||||
|
getLanguageService,
|
||||||
|
LanguageSettings,
|
||||||
|
} from '../src/languageservice/yamlLanguageService';
|
||||||
import { schemaRequestService, workspaceContext } from './testHelper';
|
import { schemaRequestService, workspaceContext } from './testHelper';
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
const languageService = getLanguageService(
|
const languageService = getLanguageService(
|
||||||
schemaRequestService,
|
schemaRequestService,
|
||||||
workspaceContext,
|
workspaceContext,
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const uri = 'http://json.schemastore.org/bowerrc';
|
const uri = 'http://json.schemastore.org/bowerrc';
|
||||||
|
|
@ -24,14 +27,14 @@ languageSettings.schemas.push({ uri, fileMatch });
|
||||||
languageService.configure(languageSettings);
|
languageService.configure(languageSettings);
|
||||||
|
|
||||||
describe('Hover Tests', () => {
|
describe('Hover Tests', () => {
|
||||||
describe('Yaml Hover with bowerrc', function () {
|
describe('Yaml Hover with bowerrc', function() {
|
||||||
describe('doComplete', function () {
|
describe('doComplete', function() {
|
||||||
function setup(content: string) {
|
function setup(content: string) {
|
||||||
return TextDocument.create(
|
return TextDocument.create(
|
||||||
'file://~/Desktop/vscode-k8s/test.yaml',
|
'file://~/Desktop/vscode-k8s/test.yaml',
|
||||||
'yaml',
|
'yaml',
|
||||||
0,
|
0,
|
||||||
content,
|
content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -41,81 +44,81 @@ describe('Hover Tests', () => {
|
||||||
return languageService.doHover(
|
return languageService.doHover(
|
||||||
testTextDocument,
|
testTextDocument,
|
||||||
testTextDocument.positionAt(position),
|
testTextDocument.positionAt(position),
|
||||||
jsonDocument,
|
jsonDocument
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
it('Hover on key on root', (done) => {
|
it('Hover on key on root', done => {
|
||||||
const content = 'cwd: test';
|
const content = 'cwd: test';
|
||||||
const hover = parseSetup(content, 1);
|
const hover = parseSetup(content, 1);
|
||||||
hover
|
hover
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.contents.length, 0);
|
assert.notEqual(result.contents.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Hover on value on root', (done) => {
|
it('Hover on value on root', done => {
|
||||||
const content = 'cwd: test';
|
const content = 'cwd: test';
|
||||||
const hover = parseSetup(content, 6);
|
const hover = parseSetup(content, 6);
|
||||||
hover
|
hover
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.contents.length, 0);
|
assert.notEqual(result.contents.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Hover on key with depth', (done) => {
|
it('Hover on key with depth', done => {
|
||||||
const content = 'scripts:\n postinstall: test';
|
const content = 'scripts:\n postinstall: test';
|
||||||
const hover = parseSetup(content, 15);
|
const hover = parseSetup(content, 15);
|
||||||
hover
|
hover
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.contents.length, 0);
|
assert.notEqual(result.contents.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Hover on value with depth', (done) => {
|
it('Hover on value with depth', done => {
|
||||||
const content = 'scripts:\n postinstall: test';
|
const content = 'scripts:\n postinstall: test';
|
||||||
const hover = parseSetup(content, 26);
|
const hover = parseSetup(content, 26);
|
||||||
hover
|
hover
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.contents.length, 0);
|
assert.notEqual(result.contents.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Hover works on both root node and child nodes works', (done) => {
|
it('Hover works on both root node and child nodes works', done => {
|
||||||
const content = 'scripts:\n postinstall: test';
|
const content = 'scripts:\n postinstall: test';
|
||||||
|
|
||||||
const firstHover = parseSetup(content, 3);
|
const firstHover = parseSetup(content, 3);
|
||||||
firstHover.then(function (result) {
|
firstHover.then(function(result) {
|
||||||
assert.notEqual(result.contents.length, 0);
|
assert.notEqual(result.contents.length, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
const secondHover = parseSetup(content, 15);
|
const secondHover = parseSetup(content, 15);
|
||||||
secondHover
|
secondHover
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.contents.length, 0);
|
assert.notEqual(result.contents.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Hover does not show results when there isnt description field', (done) => {
|
it('Hover does not show results when there isnt description field', done => {
|
||||||
const content = 'analytics: true';
|
const content = 'analytics: true';
|
||||||
const hover = parseSetup(content, 3);
|
const hover = parseSetup(content, 3);
|
||||||
hover
|
hover
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.contents.length, 0);
|
assert.notEqual(result.contents.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Hover on multi document', (done) => {
|
it('Hover on multi document', done => {
|
||||||
const content = '---\nanalytics: true\n...\n---\njson: test\n...';
|
const content = '---\nanalytics: true\n...\n---\njson: test\n...';
|
||||||
const hover = parseSetup(content, 30);
|
const hover = parseSetup(content, 30);
|
||||||
hover
|
hover
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.contents.length, 0);
|
assert.notEqual(result.contents.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ const assert = require('assert');
|
||||||
const languageService = getLanguageService(
|
const languageService = getLanguageService(
|
||||||
schemaRequestService,
|
schemaRequestService,
|
||||||
workspaceContext,
|
workspaceContext,
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const uri = 'http://json.schemastore.org/composer';
|
const uri = 'http://json.schemastore.org/composer';
|
||||||
|
|
@ -34,7 +34,7 @@ describe('Hover Tests', () => {
|
||||||
'file://~/Desktop/vscode-k8s/test.yaml',
|
'file://~/Desktop/vscode-k8s/test.yaml',
|
||||||
'yaml',
|
'yaml',
|
||||||
0,
|
0,
|
||||||
content,
|
content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -44,11 +44,11 @@ describe('Hover Tests', () => {
|
||||||
return languageService.doHover(
|
return languageService.doHover(
|
||||||
testTextDocument,
|
testTextDocument,
|
||||||
testTextDocument.positionAt(position),
|
testTextDocument.positionAt(position),
|
||||||
jsonDocument,
|
jsonDocument
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
it('Hover works on array nodes', (done) => {
|
it('Hover works on array nodes', done => {
|
||||||
const content = 'authors:\n - name: Josh';
|
const content = 'authors:\n - name: Josh';
|
||||||
const hover = parseSetup(content, 14);
|
const hover = parseSetup(content, 14);
|
||||||
hover
|
hover
|
||||||
|
|
@ -58,7 +58,7 @@ describe('Hover Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Hover works on array nodes 2', (done) => {
|
it('Hover works on array nodes 2', done => {
|
||||||
const content = 'authors:\n - name: Josh\n - email: jp';
|
const content = 'authors:\n - name: Josh\n - email: jp';
|
||||||
const hover = parseSetup(content, 28);
|
const hover = parseSetup(content, 28);
|
||||||
hover
|
hover
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,17 @@
|
||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
import { TextDocument } from 'vscode-languageserver';
|
import { TextDocument } from 'vscode-languageserver';
|
||||||
import { parse as parseYAML } from '../src/languageservice/parser/yamlParser';
|
import { parse as parseYAML } from '../src/languageservice/parser/yamlParser';
|
||||||
import { getLanguageService, LanguageSettings } from '../src/languageservice/yamlLanguageService';
|
import {
|
||||||
|
getLanguageService,
|
||||||
|
LanguageSettings,
|
||||||
|
} from '../src/languageservice/yamlLanguageService';
|
||||||
import { schemaRequestService, workspaceContext } from './testHelper';
|
import { schemaRequestService, workspaceContext } from './testHelper';
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
const languageService = getLanguageService(
|
const languageService = getLanguageService(
|
||||||
schemaRequestService,
|
schemaRequestService,
|
||||||
workspaceContext,
|
workspaceContext,
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const uri = 'http://json.schemastore.org/bowerrc';
|
const uri = 'http://json.schemastore.org/bowerrc';
|
||||||
|
|
@ -24,14 +27,14 @@ languageSettings.schemas.push({ uri, fileMatch });
|
||||||
languageService.configure(languageSettings);
|
languageService.configure(languageSettings);
|
||||||
|
|
||||||
describe('Hover Setting Tests', () => {
|
describe('Hover Setting Tests', () => {
|
||||||
describe('Yaml Hover with bowerrc', function () {
|
describe('Yaml Hover with bowerrc', function() {
|
||||||
describe('doComplete', function () {
|
describe('doComplete', function() {
|
||||||
function setup(content: string) {
|
function setup(content: string) {
|
||||||
return TextDocument.create(
|
return TextDocument.create(
|
||||||
'file://~/Desktop/vscode-k8s/test.yaml',
|
'file://~/Desktop/vscode-k8s/test.yaml',
|
||||||
'yaml',
|
'yaml',
|
||||||
0,
|
0,
|
||||||
content,
|
content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -41,15 +44,15 @@ describe('Hover Setting Tests', () => {
|
||||||
return languageService.doHover(
|
return languageService.doHover(
|
||||||
testTextDocument,
|
testTextDocument,
|
||||||
testTextDocument.positionAt(position),
|
testTextDocument.positionAt(position),
|
||||||
jsonDocument,
|
jsonDocument
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
it('Hover should not return anything', (done) => {
|
it('Hover should not return anything', done => {
|
||||||
const content = 'cwd: test';
|
const content = 'cwd: test';
|
||||||
const hover = parseSetup(content, 1);
|
const hover = parseSetup(content, 1);
|
||||||
hover
|
hover
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.equal(result, undefined);
|
assert.equal(result, undefined);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ const assert = require('assert');
|
||||||
const languageService = getLanguageService(
|
const languageService = getLanguageService(
|
||||||
schemaRequestService,
|
schemaRequestService,
|
||||||
workspaceContext,
|
workspaceContext,
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const uri =
|
const uri =
|
||||||
|
|
@ -34,7 +34,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
'file://~/Desktop/vscode-k8s/test.yaml',
|
'file://~/Desktop/vscode-k8s/test.yaml',
|
||||||
'yaml',
|
'yaml',
|
||||||
0,
|
0,
|
||||||
content,
|
content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -46,7 +46,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
|
|
||||||
// Validating basic nodes
|
// Validating basic nodes
|
||||||
describe('Test that validation does not throw errors', function() {
|
describe('Test that validation does not throw errors', function() {
|
||||||
it('Basic test', (done) => {
|
it('Basic test', done => {
|
||||||
const content = `apiVersion: v1`;
|
const content = `apiVersion: v1`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -56,7 +56,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Basic test on nodes with children', (done) => {
|
it('Basic test on nodes with children', done => {
|
||||||
const content = `metadata:\n name: hello`;
|
const content = `metadata:\n name: hello`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -66,7 +66,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Advanced test on nodes with children', (done) => {
|
it('Advanced test on nodes with children', done => {
|
||||||
const content = `apiVersion: v1\nmetadata:\n name: test1`;
|
const content = `apiVersion: v1\nmetadata:\n name: test1`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -76,7 +76,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Type string validates under children', (done) => {
|
it('Type string validates under children', done => {
|
||||||
const content = `apiVersion: v1\nkind: Pod\nmetadata:\n resourceVersion: test`;
|
const content = `apiVersion: v1\nkind: Pod\nmetadata:\n resourceVersion: test`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -87,7 +87,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Type tests', function() {
|
describe('Type tests', function() {
|
||||||
it('Type String does not error on valid node', (done) => {
|
it('Type String does not error on valid node', done => {
|
||||||
const content = `apiVersion: v1`;
|
const content = `apiVersion: v1`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -97,7 +97,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Type Boolean does not error on valid node', (done) => {
|
it('Type Boolean does not error on valid node', done => {
|
||||||
const content = `readOnlyRootFilesystem: false`;
|
const content = `readOnlyRootFilesystem: false`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -107,7 +107,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Type Number does not error on valid node', (done) => {
|
it('Type Number does not error on valid node', done => {
|
||||||
const content = `generation: 5`;
|
const content = `generation: 5`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -117,7 +117,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Type Object does not error on valid node', (done) => {
|
it('Type Object does not error on valid node', done => {
|
||||||
const content = `metadata:\n clusterName: tes`;
|
const content = `metadata:\n clusterName: tes`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -127,7 +127,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Type Array does not error on valid node', (done) => {
|
it('Type Array does not error on valid node', done => {
|
||||||
const content = `items:\n - apiVersion: v1`;
|
const content = `items:\n - apiVersion: v1`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -140,7 +140,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Test that validation DOES throw errors', function() {
|
describe('Test that validation DOES throw errors', function() {
|
||||||
it('Error when theres no value for a node', (done) => {
|
it('Error when theres no value for a node', done => {
|
||||||
const content = `apiVersion:`;
|
const content = `apiVersion:`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -150,7 +150,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Error on incorrect value type (number)', (done) => {
|
it('Error on incorrect value type (number)', done => {
|
||||||
const content = `apiVersion: 1000`;
|
const content = `apiVersion: 1000`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -160,7 +160,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Error on incorrect value type (boolean)', (done) => {
|
it('Error on incorrect value type (boolean)', done => {
|
||||||
const content = `apiVersion: False`;
|
const content = `apiVersion: False`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -170,7 +170,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Error on incorrect value type (string)', (done) => {
|
it('Error on incorrect value type (string)', done => {
|
||||||
const content = `isNonResourceURL: hello_world`;
|
const content = `isNonResourceURL: hello_world`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -180,7 +180,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Error on incorrect value type (object)', (done) => {
|
it('Error on incorrect value type (object)', done => {
|
||||||
const content = `apiVersion: v1\nkind: Pod\nmetadata:\n name: False`;
|
const content = `apiVersion: v1\nkind: Pod\nmetadata:\n name: False`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -190,7 +190,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Error on incorrect value type in multiple yaml documents', (done) => {
|
it('Error on incorrect value type in multiple yaml documents', done => {
|
||||||
const content = `---\napiVersion: v1\n...\n---\napiVersion: False\n...`;
|
const content = `---\napiVersion: v1\n...\n---\napiVersion: False\n...`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -200,7 +200,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Property error message should be "Unexpected property {$property_name}" when property is not allowed ', (done) => {
|
it('Property error message should be "Unexpected property {$property_name}" when property is not allowed ', done => {
|
||||||
const content = `unknown_node: test`;
|
const content = `unknown_node: test`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
@ -220,7 +220,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
'file://~/Desktop/vscode-k8s/test.yaml',
|
'file://~/Desktop/vscode-k8s/test.yaml',
|
||||||
'yaml',
|
'yaml',
|
||||||
0,
|
0,
|
||||||
content,
|
content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -229,11 +229,11 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
const yDoc = parseYAML(testTextDocument.getText());
|
const yDoc = parseYAML(testTextDocument.getText());
|
||||||
return completionHelper(
|
return completionHelper(
|
||||||
testTextDocument,
|
testTextDocument,
|
||||||
testTextDocument.positionAt(position),
|
testTextDocument.positionAt(position)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
it('Autocomplete on root node without word', (done) => {
|
it('Autocomplete on root node without word', done => {
|
||||||
const content = '';
|
const content = '';
|
||||||
const completion = parseSetup(content, 0);
|
const completion = parseSetup(content, 0);
|
||||||
completion
|
completion
|
||||||
|
|
@ -243,7 +243,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete on root node with word', (done) => {
|
it('Autocomplete on root node with word', done => {
|
||||||
const content = 'api';
|
const content = 'api';
|
||||||
const completion = parseSetup(content, 6);
|
const completion = parseSetup(content, 6);
|
||||||
completion
|
completion
|
||||||
|
|
@ -253,7 +253,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete on default value (without value content)', (done) => {
|
it('Autocomplete on default value (without value content)', done => {
|
||||||
const content = 'apiVersion: ';
|
const content = 'apiVersion: ';
|
||||||
const completion = parseSetup(content, 10);
|
const completion = parseSetup(content, 10);
|
||||||
completion
|
completion
|
||||||
|
|
@ -263,7 +263,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete on default value (with value content)', (done) => {
|
it('Autocomplete on default value (with value content)', done => {
|
||||||
const content = 'apiVersion: v1\nkind: Bin';
|
const content = 'apiVersion: v1\nkind: Bin';
|
||||||
const completion = parseSetup(content, 19);
|
const completion = parseSetup(content, 19);
|
||||||
completion
|
completion
|
||||||
|
|
@ -273,7 +273,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete on boolean value (without value content)', (done) => {
|
it('Autocomplete on boolean value (without value content)', done => {
|
||||||
const content = 'isNonResourceURL: ';
|
const content = 'isNonResourceURL: ';
|
||||||
const completion = parseSetup(content, 18);
|
const completion = parseSetup(content, 18);
|
||||||
completion
|
completion
|
||||||
|
|
@ -283,7 +283,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete on boolean value (with value content)', (done) => {
|
it('Autocomplete on boolean value (with value content)', done => {
|
||||||
const content = 'isNonResourceURL: fal';
|
const content = 'isNonResourceURL: fal';
|
||||||
const completion = parseSetup(content, 21);
|
const completion = parseSetup(content, 21);
|
||||||
completion
|
completion
|
||||||
|
|
@ -293,7 +293,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete key in middle of file', (done) => {
|
it('Autocomplete key in middle of file', done => {
|
||||||
const content = 'metadata:\n nam';
|
const content = 'metadata:\n nam';
|
||||||
const completion = parseSetup(content, 14);
|
const completion = parseSetup(content, 14);
|
||||||
completion
|
completion
|
||||||
|
|
@ -303,7 +303,7 @@ xdescribe('Kubernetes Integration Tests', () => {
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autocomplete key in middle of file 2', (done) => {
|
it('Autocomplete key in middle of file 2', done => {
|
||||||
const content = 'metadata:\n name: test\n cluster';
|
const content = 'metadata:\n name: test\n cluster';
|
||||||
const completion = parseSetup(content, 31);
|
const completion = parseSetup(content, 31);
|
||||||
completion
|
completion
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ function toFsPath(str): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
const uri = toFsPath(
|
const uri = toFsPath(
|
||||||
path.join(__dirname, './fixtures/customMultipleSchemaSequences.json'),
|
path.join(__dirname, './fixtures/customMultipleSchemaSequences.json')
|
||||||
);
|
);
|
||||||
const languageSettings: LanguageSettings = {
|
const languageSettings: LanguageSettings = {
|
||||||
schemas: [],
|
schemas: [],
|
||||||
|
|
@ -50,13 +50,13 @@ languageService.configure(languageSettings);
|
||||||
|
|
||||||
describe('Multiple Documents Validation Tests', () => {
|
describe('Multiple Documents Validation Tests', () => {
|
||||||
// Tests for validator
|
// Tests for validator
|
||||||
describe('Multiple Documents Validation', function () {
|
describe('Multiple Documents Validation', function() {
|
||||||
function setup(content: string) {
|
function setup(content: string) {
|
||||||
return TextDocument.create(
|
return TextDocument.create(
|
||||||
'file://~/Desktop/vscode-k8s/test.yaml',
|
'file://~/Desktop/vscode-k8s/test.yaml',
|
||||||
'yaml',
|
'yaml',
|
||||||
0,
|
0,
|
||||||
content,
|
content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,7 +64,7 @@ describe('Multiple Documents Validation Tests', () => {
|
||||||
const testTextDocument = setup(content);
|
const testTextDocument = setup(content);
|
||||||
const yDoc = parseYAML(
|
const yDoc = parseYAML(
|
||||||
testTextDocument.getText(),
|
testTextDocument.getText(),
|
||||||
languageSettings.customTags,
|
languageSettings.customTags
|
||||||
);
|
);
|
||||||
return languageService.doValidation(testTextDocument, yDoc);
|
return languageService.doValidation(testTextDocument, yDoc);
|
||||||
}
|
}
|
||||||
|
|
@ -75,11 +75,11 @@ describe('Multiple Documents Validation Tests', () => {
|
||||||
return languageService.doHover(
|
return languageService.doHover(
|
||||||
testTextDocument,
|
testTextDocument,
|
||||||
testTextDocument.positionAt(position),
|
testTextDocument.positionAt(position),
|
||||||
jsonDocument,
|
jsonDocument
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
it('Should validate multiple documents', (done) => {
|
it('Should validate multiple documents', done => {
|
||||||
const content = `
|
const content = `
|
||||||
name: jack
|
name: jack
|
||||||
age: 22
|
age: 22
|
||||||
|
|
@ -88,56 +88,56 @@ analytics: true
|
||||||
`;
|
`;
|
||||||
const validator = validatorSetup(content);
|
const validator = validatorSetup(content);
|
||||||
validator
|
validator
|
||||||
.then((result) => {
|
.then(result => {
|
||||||
assert.equal(result.length, 0);
|
assert.equal(result.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should find errors in both documents', (done) => {
|
it('Should find errors in both documents', done => {
|
||||||
const content = `name1: jack
|
const content = `name1: jack
|
||||||
age: asd
|
age: asd
|
||||||
---
|
---
|
||||||
cwd: False`;
|
cwd: False`;
|
||||||
const validator = validatorSetup(content);
|
const validator = validatorSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.equal(result.length, 3);
|
assert.equal(result.length, 3);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should find errors in first document', (done) => {
|
it('Should find errors in first document', done => {
|
||||||
const content = `name: jack
|
const content = `name: jack
|
||||||
age: age
|
age: age
|
||||||
---
|
---
|
||||||
analytics: true`;
|
analytics: true`;
|
||||||
const validator = validatorSetup(content);
|
const validator = validatorSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.equal(result.length, 1);
|
assert.equal(result.length, 1);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should find errors in second document', (done) => {
|
it('Should find errors in second document', done => {
|
||||||
const content = `name: jack
|
const content = `name: jack
|
||||||
age: 22
|
age: 22
|
||||||
---
|
---
|
||||||
cwd: False`;
|
cwd: False`;
|
||||||
const validator = validatorSetup(content);
|
const validator = validatorSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.equal(result.length, 1);
|
assert.equal(result.length, 1);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should hover in first document', (done) => {
|
it('Should hover in first document', done => {
|
||||||
const content = `name: jack\nage: 22\n---\ncwd: False`;
|
const content = `name: jack\nage: 22\n---\ncwd: False`;
|
||||||
const hover = hoverSetup(content, 1 + content.indexOf('age'));
|
const hover = hoverSetup(content, 1 + content.indexOf('age'));
|
||||||
hover
|
hover
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.contents.length, 0);
|
assert.notEqual(result.contents.length, 0);
|
||||||
assert.equal(result.contents[0], 'The age of this person');
|
assert.equal(result.contents[0], 'The age of this person');
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ const fixtureDocuments = {
|
||||||
'http://schema.management.azure.com/schemas/2015-08-01/Microsoft.Compute.json':
|
'http://schema.management.azure.com/schemas/2015-08-01/Microsoft.Compute.json':
|
||||||
'Microsoft.Compute.json',
|
'Microsoft.Compute.json',
|
||||||
};
|
};
|
||||||
const requestServiceMock = function (uri: string): Promise<string> {
|
const requestServiceMock = function(uri: string): Promise<string> {
|
||||||
if (uri.length && uri[uri.length - 1] === '#') {
|
if (uri.length && uri[uri.length - 1] === '#') {
|
||||||
uri = uri.substr(0, uri.length - 1);
|
uri = uri.substr(0, uri.length - 1);
|
||||||
}
|
}
|
||||||
|
|
@ -48,10 +48,10 @@ const workspaceContext = {
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('JSON Schema', () => {
|
describe('JSON Schema', () => {
|
||||||
test('Resolving $refs', function (testDone) {
|
test('Resolving $refs', function(testDone) {
|
||||||
const service = new SchemaService.JSONSchemaService(
|
const service = new SchemaService.JSONSchemaService(
|
||||||
requestServiceMock,
|
requestServiceMock,
|
||||||
workspaceContext,
|
workspaceContext
|
||||||
);
|
);
|
||||||
service.setSchemaContributions({
|
service.setSchemaContributions({
|
||||||
schemas: {
|
schemas: {
|
||||||
|
|
@ -74,7 +74,7 @@ describe('JSON Schema', () => {
|
||||||
|
|
||||||
service
|
service
|
||||||
.getResolvedSchema('https://myschemastore/main')
|
.getResolvedSchema('https://myschemastore/main')
|
||||||
.then((solvedSchema) => {
|
.then(solvedSchema => {
|
||||||
assert.deepEqual(solvedSchema.schema.properties.child, {
|
assert.deepEqual(solvedSchema.schema.properties.child, {
|
||||||
id: 'https://myschemastore/child',
|
id: 'https://myschemastore/child',
|
||||||
type: 'bool',
|
type: 'bool',
|
||||||
|
|
@ -83,16 +83,16 @@ describe('JSON Schema', () => {
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
() => testDone(),
|
() => testDone(),
|
||||||
(error) => {
|
error => {
|
||||||
testDone(error);
|
testDone(error);
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Resolving $refs 2', function (testDone) {
|
test('Resolving $refs 2', function(testDone) {
|
||||||
const service = new SchemaService.JSONSchemaService(
|
const service = new SchemaService.JSONSchemaService(
|
||||||
requestServiceMock,
|
requestServiceMock,
|
||||||
workspaceContext,
|
workspaceContext
|
||||||
);
|
);
|
||||||
service.setSchemaContributions({
|
service.setSchemaContributions({
|
||||||
schemas: {
|
schemas: {
|
||||||
|
|
@ -121,7 +121,7 @@ describe('JSON Schema', () => {
|
||||||
|
|
||||||
service
|
service
|
||||||
.getResolvedSchema('http://json.schemastore.org/swagger-2.0')
|
.getResolvedSchema('http://json.schemastore.org/swagger-2.0')
|
||||||
.then((fs) => {
|
.then(fs => {
|
||||||
assert.deepEqual(fs.schema.properties.responseValue, {
|
assert.deepEqual(fs.schema.properties.responseValue, {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
required: ['$ref'],
|
required: ['$ref'],
|
||||||
|
|
@ -130,16 +130,16 @@ describe('JSON Schema', () => {
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
() => testDone(),
|
() => testDone(),
|
||||||
(error) => {
|
error => {
|
||||||
testDone(error);
|
testDone(error);
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Resolving $refs 3', function (testDone) {
|
test('Resolving $refs 3', function(testDone) {
|
||||||
const service = new SchemaService.JSONSchemaService(
|
const service = new SchemaService.JSONSchemaService(
|
||||||
requestServiceMock,
|
requestServiceMock,
|
||||||
workspaceContext,
|
workspaceContext
|
||||||
);
|
);
|
||||||
service.setSchemaContributions({
|
service.setSchemaContributions({
|
||||||
schemas: {
|
schemas: {
|
||||||
|
|
@ -172,7 +172,7 @@ describe('JSON Schema', () => {
|
||||||
|
|
||||||
service
|
service
|
||||||
.getResolvedSchema('https://myschemastore/main/schema1.json')
|
.getResolvedSchema('https://myschemastore/main/schema1.json')
|
||||||
.then((fs) => {
|
.then(fs => {
|
||||||
assert.deepEqual(fs.schema.properties.p1, {
|
assert.deepEqual(fs.schema.properties.p1, {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
enum: ['object'],
|
enum: ['object'],
|
||||||
|
|
@ -188,16 +188,16 @@ describe('JSON Schema', () => {
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
() => testDone(),
|
() => testDone(),
|
||||||
(error) => {
|
error => {
|
||||||
testDone(error);
|
testDone(error);
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('FileSchema', function (testDone) {
|
test('FileSchema', function(testDone) {
|
||||||
const service = new SchemaService.JSONSchemaService(
|
const service = new SchemaService.JSONSchemaService(
|
||||||
requestServiceMock,
|
requestServiceMock,
|
||||||
workspaceContext,
|
workspaceContext
|
||||||
);
|
);
|
||||||
|
|
||||||
service.setSchemaContributions({
|
service.setSchemaContributions({
|
||||||
|
|
@ -222,22 +222,22 @@ describe('JSON Schema', () => {
|
||||||
|
|
||||||
service
|
service
|
||||||
.getResolvedSchema('main')
|
.getResolvedSchema('main')
|
||||||
.then((fs) => {
|
.then(fs => {
|
||||||
const section = fs.getSection(['child', 'grandchild']);
|
const section = fs.getSection(['child', 'grandchild']);
|
||||||
assert.equal(section.description, 'Meaning of Life');
|
assert.equal(section.description, 'Meaning of Life');
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
() => testDone(),
|
() => testDone(),
|
||||||
(error) => {
|
error => {
|
||||||
testDone(error);
|
testDone(error);
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Array FileSchema', function (testDone) {
|
test('Array FileSchema', function(testDone) {
|
||||||
const service = new SchemaService.JSONSchemaService(
|
const service = new SchemaService.JSONSchemaService(
|
||||||
requestServiceMock,
|
requestServiceMock,
|
||||||
workspaceContext,
|
workspaceContext
|
||||||
);
|
);
|
||||||
|
|
||||||
service.setSchemaContributions({
|
service.setSchemaContributions({
|
||||||
|
|
@ -265,22 +265,22 @@ describe('JSON Schema', () => {
|
||||||
|
|
||||||
service
|
service
|
||||||
.getResolvedSchema('main')
|
.getResolvedSchema('main')
|
||||||
.then((fs) => {
|
.then(fs => {
|
||||||
const section = fs.getSection(['child', '0', 'grandchild']);
|
const section = fs.getSection(['child', '0', 'grandchild']);
|
||||||
assert.equal(section.description, 'Meaning of Life');
|
assert.equal(section.description, 'Meaning of Life');
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
() => testDone(),
|
() => testDone(),
|
||||||
(error) => {
|
error => {
|
||||||
testDone(error);
|
testDone(error);
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Missing subschema', function (testDone) {
|
test('Missing subschema', function(testDone) {
|
||||||
const service = new SchemaService.JSONSchemaService(
|
const service = new SchemaService.JSONSchemaService(
|
||||||
requestServiceMock,
|
requestServiceMock,
|
||||||
workspaceContext,
|
workspaceContext
|
||||||
);
|
);
|
||||||
|
|
||||||
service.setSchemaContributions({
|
service.setSchemaContributions({
|
||||||
|
|
@ -299,22 +299,22 @@ describe('JSON Schema', () => {
|
||||||
|
|
||||||
service
|
service
|
||||||
.getResolvedSchema('main')
|
.getResolvedSchema('main')
|
||||||
.then((fs) => {
|
.then(fs => {
|
||||||
const section = fs.getSection(['child', 'grandchild']);
|
const section = fs.getSection(['child', 'grandchild']);
|
||||||
assert.strictEqual(section, null);
|
assert.strictEqual(section, null);
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
() => testDone(),
|
() => testDone(),
|
||||||
(error) => {
|
error => {
|
||||||
testDone(error);
|
testDone(error);
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Preloaded Schema', function (testDone) {
|
test('Preloaded Schema', function(testDone) {
|
||||||
const service = new SchemaService.JSONSchemaService(
|
const service = new SchemaService.JSONSchemaService(
|
||||||
requestServiceMock,
|
requestServiceMock,
|
||||||
workspaceContext,
|
workspaceContext
|
||||||
);
|
);
|
||||||
const id = 'https://myschemastore/test1';
|
const id = 'https://myschemastore/test1';
|
||||||
const schema: JsonSchema.JSONSchema = {
|
const schema: JsonSchema.JSONSchema = {
|
||||||
|
|
@ -336,53 +336,53 @@ describe('JSON Schema', () => {
|
||||||
|
|
||||||
service
|
service
|
||||||
.getSchemaForResource('test.json')
|
.getSchemaForResource('test.json')
|
||||||
.then((schema) => {
|
.then(schema => {
|
||||||
const section = schema.getSection(['child', 'grandchild']);
|
const section = schema.getSection(['child', 'grandchild']);
|
||||||
assert.equal(section.description, 'Meaning of Life');
|
assert.equal(section.description, 'Meaning of Life');
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
() => testDone(),
|
() => testDone(),
|
||||||
(error) => {
|
error => {
|
||||||
testDone(error);
|
testDone(error);
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Null Schema', function (testDone) {
|
test('Null Schema', function(testDone) {
|
||||||
const service = new SchemaService.JSONSchemaService(
|
const service = new SchemaService.JSONSchemaService(
|
||||||
requestServiceMock,
|
requestServiceMock,
|
||||||
workspaceContext,
|
workspaceContext
|
||||||
);
|
);
|
||||||
|
|
||||||
service
|
service
|
||||||
.getSchemaForResource('test.json')
|
.getSchemaForResource('test.json')
|
||||||
.then((schema) => {
|
.then(schema => {
|
||||||
assert.equal(schema, null);
|
assert.equal(schema, null);
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
() => testDone(),
|
() => testDone(),
|
||||||
(error) => {
|
error => {
|
||||||
testDone(error);
|
testDone(error);
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Schema not found', function (testDone) {
|
test('Schema not found', function(testDone) {
|
||||||
const service = new SchemaService.JSONSchemaService(
|
const service = new SchemaService.JSONSchemaService(
|
||||||
requestServiceMock,
|
requestServiceMock,
|
||||||
workspaceContext,
|
workspaceContext
|
||||||
);
|
);
|
||||||
|
|
||||||
service
|
service
|
||||||
.loadSchema('test.json')
|
.loadSchema('test.json')
|
||||||
.then((schema) => {
|
.then(schema => {
|
||||||
assert.notEqual(schema.errors.length, 0);
|
assert.notEqual(schema.errors.length, 0);
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
() => testDone(),
|
() => testDone(),
|
||||||
(error) => {
|
error => {
|
||||||
testDone(error);
|
testDone(error);
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ const assert = require('assert');
|
||||||
const languageService = getLanguageService(
|
const languageService = getLanguageService(
|
||||||
schemaRequestService,
|
schemaRequestService,
|
||||||
workspaceContext,
|
workspaceContext,
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const uri = 'SchemaDoesNotExist';
|
const uri = 'SchemaDoesNotExist';
|
||||||
|
|
@ -32,7 +32,7 @@ describe('Validation Tests', () => {
|
||||||
'file://~/Desktop/vscode-k8s/test.yaml',
|
'file://~/Desktop/vscode-k8s/test.yaml',
|
||||||
'yaml',
|
'yaml',
|
||||||
0,
|
0,
|
||||||
content,
|
content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,14 +40,14 @@ describe('Validation Tests', () => {
|
||||||
const testTextDocument = setup(content);
|
const testTextDocument = setup(content);
|
||||||
const yDoc = parseYAML(
|
const yDoc = parseYAML(
|
||||||
testTextDocument.getText(),
|
testTextDocument.getText(),
|
||||||
languageSettings.customTags,
|
languageSettings.customTags
|
||||||
);
|
);
|
||||||
return languageService.doValidation(testTextDocument, yDoc);
|
return languageService.doValidation(testTextDocument, yDoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validating basic nodes
|
// Validating basic nodes
|
||||||
describe('Test that validation throws error when schema is not found', function() {
|
describe('Test that validation throws error when schema is not found', function() {
|
||||||
it('Basic test', (done) => {
|
it('Basic test', done => {
|
||||||
const content = `testing: true`;
|
const content = `testing: true`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ const assert = require('assert');
|
||||||
const languageService = getLanguageService(
|
const languageService = getLanguageService(
|
||||||
schemaRequestService,
|
schemaRequestService,
|
||||||
workspaceContext,
|
workspaceContext,
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const uri = 'http://json.schemastore.org/bowerrc';
|
const uri = 'http://json.schemastore.org/bowerrc';
|
||||||
|
|
@ -28,13 +28,13 @@ languageService.configure(languageSettings);
|
||||||
|
|
||||||
describe('Validation Tests', () => {
|
describe('Validation Tests', () => {
|
||||||
// Tests for validator
|
// Tests for validator
|
||||||
describe('Validation', function () {
|
describe('Validation', function() {
|
||||||
function setup(content: string) {
|
function setup(content: string) {
|
||||||
return TextDocument.create(
|
return TextDocument.create(
|
||||||
'file://~/Desktop/vscode-k8s/test.yaml',
|
'file://~/Desktop/vscode-k8s/test.yaml',
|
||||||
'yaml',
|
'yaml',
|
||||||
0,
|
0,
|
||||||
content,
|
content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,154 +42,154 @@ describe('Validation Tests', () => {
|
||||||
const testTextDocument = setup(content);
|
const testTextDocument = setup(content);
|
||||||
const yDoc = parseYAML(
|
const yDoc = parseYAML(
|
||||||
testTextDocument.getText(),
|
testTextDocument.getText(),
|
||||||
languageSettings.customTags,
|
languageSettings.customTags
|
||||||
);
|
);
|
||||||
return languageService.doValidation(testTextDocument, yDoc);
|
return languageService.doValidation(testTextDocument, yDoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validating basic nodes
|
// Validating basic nodes
|
||||||
describe('Test that validation does not throw errors', function () {
|
describe('Test that validation does not throw errors', function() {
|
||||||
it('Basic test', (done) => {
|
it('Basic test', done => {
|
||||||
const content = `analytics: true`;
|
const content = `analytics: true`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Test that boolean value in quotations is not interpreted as boolean i.e. it errors', (done) => {
|
it('Test that boolean value in quotations is not interpreted as boolean i.e. it errors', done => {
|
||||||
const content = `analytics: "no"`;
|
const content = `analytics: "no"`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.length, 0);
|
assert.notEqual(result.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Test that boolean value without quotations is valid', (done) => {
|
it('Test that boolean value without quotations is valid', done => {
|
||||||
const content = `analytics: no`;
|
const content = `analytics: no`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Test that boolean is valid when inside strings', (done) => {
|
it('Test that boolean is valid when inside strings', done => {
|
||||||
const content = `cwd: "no"`;
|
const content = `cwd: "no"`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Test that boolean is invalid when no strings present and schema wants string', (done) => {
|
it('Test that boolean is invalid when no strings present and schema wants string', done => {
|
||||||
const content = `cwd: no`;
|
const content = `cwd: no`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.length, 0);
|
assert.notEqual(result.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Basic test', (done) => {
|
it('Basic test', done => {
|
||||||
const content = `analytics: true`;
|
const content = `analytics: true`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Basic test on nodes with children', (done) => {
|
it('Basic test on nodes with children', done => {
|
||||||
const content = `scripts:\n preinstall: test1\n postinstall: test2`;
|
const content = `scripts:\n preinstall: test1\n postinstall: test2`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Advanced test on nodes with children', (done) => {
|
it('Advanced test on nodes with children', done => {
|
||||||
const content = `analytics: true\ncwd: this\nscripts:\n preinstall: test1\n postinstall: test2`;
|
const content = `analytics: true\ncwd: this\nscripts:\n preinstall: test1\n postinstall: test2`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Type string validates under children', (done) => {
|
it('Type string validates under children', done => {
|
||||||
const content = `registry:\n register: http://test_url.com`;
|
const content = `registry:\n register: http://test_url.com`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Include with value should not error', (done) => {
|
it('Include with value should not error', done => {
|
||||||
const content = `customize: !include customize.yaml`;
|
const content = `customize: !include customize.yaml`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Null scalar value should be treated as null', (done) => {
|
it('Null scalar value should be treated as null', done => {
|
||||||
const content = `cwd: Null`;
|
const content = `cwd: Null`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(1);
|
expect(result.length).toEqual(1);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Anchor should not not error', (done) => {
|
it('Anchor should not not error', done => {
|
||||||
const content = `default: &DEFAULT\n name: Anchor\nanchor_test:\n <<: *DEFAULT`;
|
const content = `default: &DEFAULT\n name: Anchor\nanchor_test:\n <<: *DEFAULT`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Anchor with multiple references should not not error', (done) => {
|
it('Anchor with multiple references should not not error', done => {
|
||||||
const content = `default: &DEFAULT\n name: Anchor\nanchor_test:\n <<: *DEFAULT\nanchor_test2:\n <<: *DEFAULT`;
|
const content = `default: &DEFAULT\n name: Anchor\nanchor_test:\n <<: *DEFAULT\nanchor_test2:\n <<: *DEFAULT`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Multiple Anchor in array of references should not not error', (done) => {
|
it('Multiple Anchor in array of references should not not error', done => {
|
||||||
const content = `default: &DEFAULT\n name: Anchor\ncustomname: &CUSTOMNAME\n custom_name: Anchor\nanchor_test:\n <<: [*DEFAULT, *CUSTOMNAME]`;
|
const content = `default: &DEFAULT\n name: Anchor\ncustomname: &CUSTOMNAME\n custom_name: Anchor\nanchor_test:\n <<: [*DEFAULT, *CUSTOMNAME]`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Multiple Anchors being referenced in same level at same time', (done) => {
|
it('Multiple Anchors being referenced in same level at same time', done => {
|
||||||
const content = `
|
const content = `
|
||||||
default: &DEFAULT
|
default: &DEFAULT
|
||||||
name: Anchor
|
name: Anchor
|
||||||
|
|
@ -201,87 +201,87 @@ describe('Validation Tests', () => {
|
||||||
`;
|
`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Custom Tags without type', (done) => {
|
it('Custom Tags without type', done => {
|
||||||
const content = `analytics: !Test false`;
|
const content = `analytics: !Test false`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Custom Tags with type', (done) => {
|
it('Custom Tags with type', done => {
|
||||||
const content = `resolvers: !Ref\n - test`;
|
const content = `resolvers: !Ref\n - test`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Type tests', function () {
|
describe('Type tests', function() {
|
||||||
it('Type String does not error on valid node', (done) => {
|
it('Type String does not error on valid node', done => {
|
||||||
const content = `cwd: this`;
|
const content = `cwd: this`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Type Boolean does not error on valid node', (done) => {
|
it('Type Boolean does not error on valid node', done => {
|
||||||
const content = `analytics: true`;
|
const content = `analytics: true`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Type Number does not error on valid node', (done) => {
|
it('Type Number does not error on valid node', done => {
|
||||||
const content = `timeout: 60000`;
|
const content = `timeout: 60000`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Type Object does not error on valid node', (done) => {
|
it('Type Object does not error on valid node', done => {
|
||||||
const content = `registry:\n search: http://test_url.com`;
|
const content = `registry:\n search: http://test_url.com`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Type Array does not error on valid node', (done) => {
|
it('Type Array does not error on valid node', done => {
|
||||||
const content = `resolvers:\n - test\n - test\n - test`;
|
const content = `resolvers:\n - test\n - test\n - test`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Do not error when there are multiple types in schema and theyre valid', (done) => {
|
it('Do not error when there are multiple types in schema and theyre valid', done => {
|
||||||
const content = `license: MIT`;
|
const content = `license: MIT`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator.then(function (result) {
|
validator.then(function(result) {
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
});
|
});
|
||||||
done();
|
done();
|
||||||
|
|
@ -289,82 +289,82 @@ describe('Validation Tests', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Test that validation DOES throw errors', function () {
|
describe('Test that validation DOES throw errors', function() {
|
||||||
it('Error when theres a finished untyped item', (done) => {
|
it('Error when theres a finished untyped item', done => {
|
||||||
const content = `cwd: hello\nan`;
|
const content = `cwd: hello\nan`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.length, 0);
|
assert.notEqual(result.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Error when theres no value for a node', (done) => {
|
it('Error when theres no value for a node', done => {
|
||||||
const content = `cwd:`;
|
const content = `cwd:`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.length, 0);
|
assert.notEqual(result.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Error on incorrect value type (number)', (done) => {
|
it('Error on incorrect value type (number)', done => {
|
||||||
const content = `cwd: 100000`;
|
const content = `cwd: 100000`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.length, 0);
|
assert.notEqual(result.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Error on incorrect value type (boolean)', (done) => {
|
it('Error on incorrect value type (boolean)', done => {
|
||||||
const content = `cwd: False`;
|
const content = `cwd: False`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.length, 0);
|
assert.notEqual(result.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Error on incorrect value type (string)', (done) => {
|
it('Error on incorrect value type (string)', done => {
|
||||||
const content = `analytics: hello`;
|
const content = `analytics: hello`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.length, 0);
|
assert.notEqual(result.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Error on incorrect value type (object)', (done) => {
|
it('Error on incorrect value type (object)', done => {
|
||||||
const content = `scripts: test`;
|
const content = `scripts: test`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.length, 0);
|
assert.notEqual(result.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Error on incorrect value type (array)', (done) => {
|
it('Error on incorrect value type (array)', done => {
|
||||||
const content = `resolvers: test`;
|
const content = `resolvers: test`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
assert.notEqual(result.length, 0);
|
assert.notEqual(result.length, 0);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Include without value should error', (done) => {
|
it('Include without value should error', done => {
|
||||||
const content = `customize: !include`;
|
const content = `customize: !include`;
|
||||||
const validator = parseSetup(content);
|
const validator = parseSetup(content);
|
||||||
validator
|
validator
|
||||||
.then(function (result) {
|
.then(function(result) {
|
||||||
expect(result.length).toEqual(1);
|
expect(result.length).toEqual(1);
|
||||||
})
|
})
|
||||||
.then(done, done);
|
.then(done, done);
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ import URI from '../src/languageservice/utils/uri';
|
||||||
|
|
||||||
namespace VSCodeContentRequest {
|
namespace VSCodeContentRequest {
|
||||||
export const type: RequestType<{}, {}, {}, {}> = new RequestType(
|
export const type: RequestType<{}, {}, {}, {}> = new RequestType(
|
||||||
'vscode/content',
|
'vscode/content'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -28,7 +28,7 @@ let connection: IConnection = null;
|
||||||
if (process.argv.indexOf('--stdio') === -1) {
|
if (process.argv.indexOf('--stdio') === -1) {
|
||||||
connection = createConnection(
|
connection = createConnection(
|
||||||
new IPCMessageReader(process),
|
new IPCMessageReader(process),
|
||||||
new IPCMessageWriter(process),
|
new IPCMessageWriter(process)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
connection = createConnection();
|
connection = createConnection();
|
||||||
|
|
@ -50,7 +50,7 @@ connection.onInitialize(
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
export let workspaceContext = {
|
export let workspaceContext = {
|
||||||
|
|
@ -69,24 +69,24 @@ export let schemaRequestService = (uri: string): Thenable<string> => {
|
||||||
});
|
});
|
||||||
} else if (Strings.startsWith(uri, 'vscode://')) {
|
} else if (Strings.startsWith(uri, 'vscode://')) {
|
||||||
return connection.sendRequest(VSCodeContentRequest.type, uri).then(
|
return connection.sendRequest(VSCodeContentRequest.type, uri).then(
|
||||||
(responseText) => {
|
responseText => {
|
||||||
return responseText;
|
return responseText;
|
||||||
},
|
},
|
||||||
(error) => {
|
error => {
|
||||||
return error.message;
|
return error.message;
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return xhr({ url: uri, followRedirects: 5 }).then(
|
return xhr({ url: uri, followRedirects: 5 }).then(
|
||||||
(response) => {
|
response => {
|
||||||
return response.responseText;
|
return response.responseText;
|
||||||
},
|
},
|
||||||
(error: XHRResponse) => {
|
(error: XHRResponse) => {
|
||||||
return Promise.reject(
|
return Promise.reject(
|
||||||
error.responseText ||
|
error.responseText ||
|
||||||
getErrorStatusDescription(error.status) ||
|
getErrorStatusDescription(error.status) ||
|
||||||
error.toString(),
|
error.toString()
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ describe('URI Tests', () => {
|
||||||
'www.foo.com',
|
'www.foo.com',
|
||||||
'/bar.html',
|
'/bar.html',
|
||||||
'name=hello',
|
'name=hello',
|
||||||
'123',
|
'123'
|
||||||
);
|
);
|
||||||
assert.equal(result.authority, 'www.foo.com');
|
assert.equal(result.authority, 'www.foo.com');
|
||||||
assert.equal(result.fragment, '123');
|
assert.equal(result.fragment, '123');
|
||||||
|
|
@ -69,14 +69,14 @@ describe('URI Tests', () => {
|
||||||
describe('URI toString', function() {
|
describe('URI toString', function() {
|
||||||
it('toString with encoding', () => {
|
it('toString with encoding', () => {
|
||||||
const result = URI.parse(
|
const result = URI.parse(
|
||||||
'http://www.foo.com:8080/bar.html?name=hello#123',
|
'http://www.foo.com:8080/bar.html?name=hello#123'
|
||||||
).toString();
|
).toString();
|
||||||
assert.equal('http://www.foo.com:8080/bar.html?name%3Dhello#123', result);
|
assert.equal('http://www.foo.com:8080/bar.html?name%3Dhello#123', result);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('toString without encoding', () => {
|
it('toString without encoding', () => {
|
||||||
const result = URI.parse(
|
const result = URI.parse(
|
||||||
'http://www.foo.com/bar.html?name=hello#123',
|
'http://www.foo.com/bar.html?name=hello#123'
|
||||||
).toString(true);
|
).toString(true);
|
||||||
assert.equal('http://www.foo.com/bar.html?name=hello#123', result);
|
assert.equal('http://www.foo.com/bar.html?name=hello#123', result);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue