Merge pull request #10 from pengx17/feat/dev

add jest tests
This commit is contained in:
Peng Xiao 2018-12-21 17:35:21 +08:00 committed by GitHub
commit 27349f9d15
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 585 additions and 451 deletions

18
.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,18 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"name": "vscode-jest-tests",
"request": "launch",
"args": ["--runInBand"],
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
}
]
}

View file

@ -9,7 +9,7 @@
"watch": "tsc -p ./src --watch",
"prepublish": "rimraf ./out && rimraf ./release && yarn compile:umd && node ./scripts/bundle && mcopy ./src/monaco.d.ts ./release/monaco.d.ts",
"lint": "prettier \"{src,test}/**/*.{json,scss,html,ts}\" --write",
"test": "jest"
"test": "jest --verbose"
},
"author": "Kevin Decker <kpdecker@gmail.com> (http://incaseofstairs.com)",
"maintainers": [
@ -51,14 +51,11 @@
},
"lint-staged": {
"linters": {
"*.{json,scss,html}": [
"*.{json,scss,html,ts}": [
"prettier --write",
"git add"
]
},
"ignore": [
"src/backend/vendor/**/*"
]
}
},
"husky": {
"hooks": {

View file

@ -142,6 +142,7 @@ export class NumberASTNodeImpl extends ASTNodeImpl implements NumberASTNode {
export class StringASTNodeImpl extends ASTNodeImpl implements StringASTNode {
public type: 'string' = 'string';
public value: string;
public isKey: boolean;
constructor(parent: ASTNode, offset: number, length?: number) {
super(parent, offset, length);
@ -213,7 +214,7 @@ export interface ISchemaCollector {
class SchemaCollector implements ISchemaCollector {
public schemas: IApplicableSchema[] = [];
constructor(private focusOffset = -1, private exclude: ASTNode = null) { }
constructor(private focusOffset = -1, private exclude: ASTNode = null) {}
public add(schema: IApplicableSchema) {
this.schemas.push(schema);
}
@ -237,9 +238,9 @@ class NoOpSchemaCollector implements ISchemaCollector {
}
public static instance = new NoOpSchemaCollector();
private constructor() { }
public add(schema: IApplicableSchema) { }
public merge(other: ISchemaCollector) { }
private constructor() {}
public add(schema: IApplicableSchema) {}
public merge(other: ISchemaCollector) {}
public include(node: ASTNode) {
return true;
}
@ -389,7 +390,7 @@ export class JSONDocument {
public root: ASTNode,
public readonly syntaxErrors: Diagnostic[] = [],
public readonly comments: Range[] = []
) { }
) {}
public getNodeFromOffset(
offset: number,
@ -1110,13 +1111,15 @@ function validate(
break;
}
case 'array': {
propertyNode.valueNode.items.forEach((sequenceNode: ObjectASTNode) => {
sequenceNode.properties.forEach(propASTNode => {
const seqKey = propASTNode.keyNode.value;
seenKeys[seqKey] = propASTNode.valueNode;
unprocessedProperties.push(seqKey);
});
});
propertyNode.valueNode.items.forEach(
(sequenceNode: ObjectASTNode) => {
sequenceNode.properties.forEach(propASTNode => {
const seqKey = propASTNode.keyNode.value;
seenKeys[seqKey] = propASTNode.valueNode;
unprocessedProperties.push(seqKey);
});
}
);
break;
}
default: {

View file

@ -25,6 +25,7 @@ import {
StringASTNodeImpl,
} from './jsonParser';
import { parseYamlBoolean } from './scalar-type';
import { DiagnosticSeverity } from 'vscode-languageserver-types';
function recursivelyBuildAst(parent: ASTNode, node: Yaml.YAMLNode): ASTNode {
if (!node) {
@ -60,6 +61,8 @@ function recursivelyBuildAst(parent: ASTNode, node: Yaml.YAMLNode): ASTNode {
instance.endPosition - key.startPosition
);
result.colonOffset = key.colonPosition;
// Technically, this is an arbitrary node in YAML
// I doubt we would get a better string representation by parsing it
const keyNode = new StringASTNodeImpl(
@ -68,11 +71,12 @@ function recursivelyBuildAst(parent: ASTNode, node: Yaml.YAMLNode): ASTNode {
key.endPosition - key.startPosition
);
keyNode.value = key.value;
keyNode.isKey = true;
// TODO: calculate the correct NULL range.
const valueNode = instance.value
? recursivelyBuildAst(result, instance.value)
: new NullASTNodeImpl(parent, instance.endPosition);
: new NullASTNodeImpl(result, instance.endPosition);
result.keyNode = keyNode;
result.valueNode = valueNode;
@ -99,10 +103,10 @@ function recursivelyBuildAst(parent: ASTNode, node: Yaml.YAMLNode): ASTNode {
const itemNode =
item === null
? new NullASTNodeImpl(
parent,
instance.startPosition,
instance.endPosition - instance.startPosition
)
parent,
instance.startPosition,
instance.endPosition - instance.startPosition
)
: recursivelyBuildAst(result, item);
result.items.push(itemNode);
@ -225,10 +229,15 @@ function recursivelyBuildAst(parent: ASTNode, node: Yaml.YAMLNode): ASTNode {
function convertError(e: Yaml.Error) {
return {
message: `${e.reason}`,
// TODO: YAML ast parser does not give a length for validation error.
location: {
offset: e.mark.position,
code: ErrorCode.Undefined,
length: 0,
},
code: ErrorCode.Undefined,
severity: e.isWarning
? DiagnosticSeverity.Warning
: DiagnosticSeverity.Error,
};
}
@ -248,14 +257,18 @@ function createJSONDocument(
'Expected a YAML object, array or literal'
),
code: ErrorCode.Undefined,
location: { start: yamlDoc.startPosition, end: yamlDoc.endPosition },
location: {
offset: yamlDoc.startPosition,
length: yamlDoc.endPosition - yamlDoc.startPosition,
},
severity: DiagnosticSeverity.Error,
});
}
const duplicateKeyReason = 'duplicate key';
// Patch ontop of yaml-ast-parser to disable duplicate key message on merge key
const isDuplicateAndNotMergeKey = function (
const isDuplicateAndNotMergeKey = function(
error: Yaml.Error,
yamlText: string
) {

View file

@ -556,7 +556,8 @@ export class JSONSchemaService implements IJSONSchemaService {
next.anyOf,
next.allOf,
next.oneOf,
next.items as JSONSchema[]
next.items as JSONSchema[],
next.schemaSequence
);
};

View file

@ -35,22 +35,19 @@ import {
ClientCapabilities,
ObjectASTNode,
PropertyASTNode,
StringASTNode,
} from '../jsonLanguageTypes';
import { matchOffsetToDocument } from '../utils/arrUtils';
import { stringifyObject } from '../utils/json';
import { isDefined } from '../utils/objects';
import { endsWith } from '../utils/strings';
import { YAMLDocument } from '../yamlLanguageTypes';
import { LanguageSettings } from '../yamlLanguageService';
const localize = nls.loadMessageBundle();
// !! FIXME: this implementation is buggy
export class YAMLCompletion {
private completionEnabled = true;
private supportsMarkdown: boolean | undefined;
private templateVarIdCounter = 0;
constructor(
private schemaService: SchemaService.IJSONSchemaService,
private contributions: JSONWorkerContribution[] = [],
@ -60,6 +57,12 @@ export class YAMLCompletion {
this.contributions = contributions;
}
public configure(settings: LanguageSettings) {
if (settings) {
this.completionEnabled = settings.completion !== false;
}
}
public doResolve(item: CompletionItem): Thenable<CompletionItem> {
for (let i = this.contributions.length - 1; i >= 0; i--) {
if (this.contributions[i].resolveCompletion) {
@ -88,7 +91,7 @@ export class YAMLCompletion {
const currentDocIndex = doc.documents.indexOf(currentDoc);
if (currentDoc === null) {
if (currentDoc === null || !this.completionEnabled) {
return Promise.resolve(result);
}

View file

@ -15,60 +15,67 @@ import {
} from 'vscode-languageserver-types';
import { EOL } from '../../fillers/os';
import * as Yaml from '../../yaml-ast-parser/index';
import { LanguageSettings } from '../yamlLanguageService';
export function format(
document: TextDocument,
options: FormattingOptions,
customTags: String[]
): TextEdit[] {
const text = document.getText();
customTags = customTags || [];
export class YamlFormatter {
private customTags: string[];
const schemaWithAdditionalTags = jsyaml.Schema.create(
customTags.map(tag => {
const typeInfo = tag.split(' ');
return new jsyaml.Type(typeInfo[0], { kind: typeInfo[1] || 'scalar' });
})
);
// We need compiledTypeMap to be available from schemaWithAdditionalTags before we add the new custom properties
customTags.map(tag => {
const typeInfo = tag.split(' ');
schemaWithAdditionalTags.compiledTypeMap[typeInfo[0]] = new jsyaml.Type(
typeInfo[0],
{ kind: typeInfo[1] || 'scalar' }
);
});
const additionalOptions: Yaml.LoadOptions = {
schema: schemaWithAdditionalTags,
};
const documents = [];
jsyaml.loadAll(text, doc => documents.push(doc), additionalOptions);
const dumpOptions = { indent: options.tabSize, noCompatMode: true };
let newText;
if (documents.length == 1) {
const yaml = documents[0];
newText = jsyaml.safeDump(yaml, dumpOptions);
} else {
const formatted = documents.map(d => jsyaml.safeDump(d, dumpOptions));
newText =
'%YAML 1.2' +
EOL +
'---' +
EOL +
formatted.join('...' + EOL + '---' + EOL) +
'...' +
EOL;
configure(settings: LanguageSettings) {
if (settings) {
this.customTags = settings.customTags || [];
}
}
return [
TextEdit.replace(
Range.create(Position.create(0, 0), document.positionAt(text.length)),
newText
),
];
doFormat(document: TextDocument, options: FormattingOptions): TextEdit[] {
const text = document.getText();
const customTags = this.customTags || [];
const schemaWithAdditionalTags = jsyaml.Schema.create(
customTags.map(tag => {
const typeInfo = tag.split(' ');
return new jsyaml.Type(typeInfo[0], { kind: typeInfo[1] || 'scalar' });
})
);
// We need compiledTypeMap to be available from schemaWithAdditionalTags before we add the new custom properties
customTags.map(tag => {
const typeInfo = tag.split(' ');
schemaWithAdditionalTags.compiledTypeMap[typeInfo[0]] = new jsyaml.Type(
typeInfo[0],
{ kind: typeInfo[1] || 'scalar' }
);
});
const additionalOptions: Yaml.LoadOptions = {
schema: schemaWithAdditionalTags,
};
const documents = [];
jsyaml.loadAll(text, doc => documents.push(doc), additionalOptions);
const dumpOptions = { indent: options.tabSize, noCompatMode: true };
let newText;
if (documents.length == 1) {
const yaml = documents[0];
newText = jsyaml.safeDump(yaml, dumpOptions);
} else {
const formatted = documents.map(d => jsyaml.safeDump(d, dumpOptions));
newText =
'%YAML 1.2' +
EOL +
'---' +
EOL +
formatted.join('...' + EOL + '---' + EOL) +
'...' +
EOL;
}
return [
TextEdit.replace(
Range.create(Position.create(0, 0), document.positionAt(text.length)),
newText
),
];
}
}

View file

@ -19,13 +19,22 @@ import {
} from 'vscode-languageserver-types';
import { matchOffsetToDocument } from '../utils/arrUtils';
import { YAMLDocument } from '../yamlLanguageTypes';
import { LanguageSettings } from '../yamlLanguageService';
export class YAMLHover {
private shouldHover = true;
constructor(
private schemaService: SchemaService.IJSONSchemaService,
private contributions: JSONWorkerContribution[] = []
) {}
public configure(languageSettings: LanguageSettings) {
if (languageSettings) {
this.shouldHover = languageSettings.hover !== false;
}
}
public doHover(
document: TextDocument,
position: Position,
@ -33,11 +42,11 @@ export class YAMLHover {
): Thenable<Hover> {
const offset = document.offsetAt(position);
const currentDoc = matchOffsetToDocument(offset, doc);
if (currentDoc === null) {
if (currentDoc === null || !this.shouldHover) {
return Promise.resolve(void 0);
}
const currentDocIndex = doc.documents.indexOf(currentDoc);
let node = currentDoc.getNodeFromOffset(offset);
const currentDocIndex = doc.documents.indexOf(currentDoc);
if (
!node ||
((node.type === 'object' || node.type === 'array') &&
@ -85,8 +94,19 @@ export class YAMLHover {
.getSchemaForResource(document.uri, currentDoc)
.then(schema => {
if (schema) {
let newSchema = schema;
if (
schema.schema &&
schema.schema.schemaSequence &&
schema.schema.schemaSequence[currentDocIndex]
) {
newSchema = new SchemaService.ResolvedSchema(
schema.schema.schemaSequence[currentDocIndex]
);
}
const matchingSchemas = currentDoc.getMatchingSchemas(
schema.schema,
newSchema.schema,
node.offset
);

View file

@ -5,10 +5,15 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import { DiagnosticSeverity, TextDocument } from 'vscode-languageserver-types';
import {
DiagnosticSeverity,
TextDocument,
Diagnostic,
} from 'vscode-languageserver-types';
import { LanguageSettings } from '../yamlLanguageService';
import { YAMLDocument } from '../yamlLanguageTypes';
import { JSONSchemaService, ResolvedSchema } from './jsonSchemaService';
import { Thenable } from '../jsonLanguageTypes';
export class YAMLValidation {
private validationEnabled: boolean;
@ -18,18 +23,21 @@ export class YAMLValidation {
public configure(raw: LanguageSettings) {
if (raw) {
this.validationEnabled = raw.validate;
this.validationEnabled = raw.validate !== false;
}
}
public doValidation(textDocument: TextDocument, yamlDocument: YAMLDocument) {
public doValidation(
textDocument: TextDocument,
yamlDocument: YAMLDocument
): Thenable<Diagnostic[]> {
if (!this.validationEnabled) {
return Promise.resolve([]);
}
return this.jsonSchemaService
.getSchemaForResource(textDocument.uri)
.then(function(schema) {
const diagnostics = [];
const diagnostics: Diagnostic[] = [];
const added = {};
let newSchema = schema;
if (schema) {
@ -53,10 +61,13 @@ export class YAMLValidation {
const curDiagnostic = diagnostics[diag];
currentDoc.errors.push({
location: {
start: curDiagnostic.range.start,
end: curDiagnostic.range.end,
offset: textDocument.offsetAt(curDiagnostic.range.start),
length:
textDocument.offsetAt(curDiagnostic.range.end) -
textDocument.offsetAt(curDiagnostic.range.start),
},
message: curDiagnostic.message,
severity: curDiagnostic.severity,
});
}
documentIndex++;
@ -87,23 +98,24 @@ export class YAMLValidation {
.forEach(function(error, idx) {
// remove duplicated messages
const signature =
error.location.start +
error.location.offset +
' ' +
error.location.end +
error.location.length +
' ' +
error.message;
if (!added[signature]) {
added[signature] = true;
const range = {
start: textDocument.positionAt(error.location.start),
end: textDocument.positionAt(error.location.end),
};
diagnostics.push({
severity:
idx >= currentDoc.errors.length
? DiagnosticSeverity.Warning
: DiagnosticSeverity.Error,
range,
range: {
start: textDocument.positionAt(error.location.offset),
end: textDocument.positionAt(
error.location.offset + error.location.length
),
},
message: error.message,
});
}

View file

@ -27,7 +27,7 @@ import {
JSONSchemaService,
} from './services/jsonSchemaService';
import { YAMLCompletion } from './services/yamlCompletion';
import { format } from './services/yamlFormatter';
import { YamlFormatter } from './services/yamlFormatter';
import { YAMLHover } from './services/yamlHover';
import { YAMLValidation } from './services/yamlValidation';
import { YAMLDocument } from './yamlLanguageTypes';
@ -38,7 +38,7 @@ export interface LanguageSettings {
completion?: boolean; // Setting for whether we want to have completion results
isKubernetes?: boolean; // If true then its validating against kubernetes
schemas?: any[]; // List of schemas,
customTags?: String[]; // Array of Custom Tags
customTags?: string[]; // Array of Custom Tags
}
export interface Thenable<R> {
@ -134,6 +134,7 @@ export function getLanguageService(
const hover = new YAMLHover(schemaService, contributions);
const yamlDocumentSymbols = new YAMLDocumentSymbols(schemaService);
const yamlValidation = new YAMLValidation(schemaService);
const yamlFormatter = new YamlFormatter();
return {
configure: settings => {
@ -147,6 +148,11 @@ export function getLanguageService(
);
});
}
yamlValidation.configure(settings);
hover.configure(settings);
completer.configure(settings);
yamlFormatter.configure(settings);
},
registerCustomSchemaProvider: (schemaProvider: CustomSchemaProvider) => {
schemaService.registerCustomSchemaProvider(schemaProvider);
@ -165,7 +171,7 @@ export function getLanguageService(
yamlDocumentSymbols
),
resetSchema: (uri: string) => schemaService.onResourceChange(uri),
doFormat: format,
doFormat: yamlFormatter.doFormat.bind(yamlFormatter),
parseYAMLDocument: (document: TextDocument) =>
parseYAML(document.getText()),
};

View file

@ -1,10 +1,11 @@
import { ASTNode } from './jsonLanguageTypes';
import { JSONDocument } from './parser/jsonParser';
import { JSONDocument, IProblem } from './parser/jsonParser';
import { getPosition } from './utils/documentPositionCalculator';
export class SingleYAMLDocument extends JSONDocument {
public lines;
public errors;
public warnings;
public lines: number[];
public errors: IProblem[];
public warnings: IProblem[];
constructor(lines: number[]) {
super(null, []);
@ -56,16 +57,21 @@ export class SingleYAMLDocument extends JSONDocument {
}
return currMinNode || foundNode;
}
// Returns a node at offset which will be used as a hint for completion
//
public getCompletionNodeFromOffset(offset: number): ASTNode {
if (!this.root) {
return;
}
// TODO
}
}
export class YAMLDocument {
public documents: SingleYAMLDocument[];
public errors;
public warnings;
constructor(documents: SingleYAMLDocument[]) {
this.documents = documents;
this.errors = [];
this.warnings = [];
}
}

View file

@ -492,11 +492,7 @@ function storeMappingPair(
});
_result.mappings.push(mapping);
_result.endPosition = valueNode
? valueNode.endPosition
: keyNode.endPosition + 1; // FIXME.workaround should be position of ':' indeed
// }
_result.endPosition = mapping.endPosition;
return _result;
}
@ -646,7 +642,8 @@ function readPlainScalar(state: State, nodeIndent, withinFlowCollection) {
_lineIndent,
_kind = state.kind,
_result = state.result,
ch;
ch,
_colonPosition = -1;
const state_result = ast.newScalar();
state_result.plainScalar = true;
state.result = state_result;
@ -694,6 +691,7 @@ function readPlainScalar(state: State, nodeIndent, withinFlowCollection) {
is_WS_OR_EOL(following) ||
(withinFlowCollection && is_FLOW_INDICATOR(following))
) {
_colonPosition = state.position;
break;
}
} else if (0x23 /* # */ === ch) {
@ -750,6 +748,7 @@ function readPlainScalar(state: State, nodeIndent, withinFlowCollection) {
state_result.startPosition,
state_result.endPosition
);
state_result.colonPosition = _colonPosition;
return true;
}

View file

@ -20,6 +20,7 @@ export interface YAMLNode extends YAMLDocument {
startPosition: number;
endPosition: number;
kind: Kind;
colonPosition?: number; // Nearest colon position.
anchorId?: string;
valueObject?: any;
parent: YAMLNode;
@ -63,8 +64,7 @@ export interface YamlMap extends YAMLNode {
mappings: YAMLMapping[];
}
export function newMapping(key: YAMLScalar, value: YAMLNode): YAMLMapping {
const end = value ? value.endPosition : key.endPosition + 1; // FIXME.workaround, end should be defied by position of ':'
// console.log('key: ' + key.value + ' ' + key.startPosition + '..' + key.endPosition + ' ' + value + ' end: ' + end);
const end = value ? value.endPosition : key.colonPosition + 1;
const node = {
key,
value,

View file

@ -10,8 +10,8 @@ import {
const assert = require('assert');
describe('Array Utils Tests', () => {
describe('Server - Array Utils', function () {
describe('removeDuplicates', function () {
describe('Server - Array Utils', function() {
describe('removeDuplicates', function() {
it('Remove one duplicate with property', () => {
const obj1 = {
test_key: 'test_value',
@ -69,7 +69,7 @@ describe('Array Utils Tests', () => {
});
});
describe('getLineOffsets', function () {
describe('getLineOffsets', function() {
it('No offset', () => {
const offsets = getLineOffsets('');
assert.equal(offsets.length, 0);
@ -89,7 +89,7 @@ describe('Array Utils Tests', () => {
it('Multiple offsets', () => {
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[0], 0);
@ -98,7 +98,7 @@ describe('Array Utils Tests', () => {
});
});
describe('removeDuplicatesObj', function () {
describe('removeDuplicatesObj', function() {
it('Remove one duplicate with property', () => {
const obj1 = {
test_key: 'test_value',

View file

@ -12,7 +12,7 @@ const assert = require('assert');
const languageService = getLanguageService(
schemaRequestService,
workspaceContext,
[],
[]
);
const uri = 'http://json.schemastore.org/bowerrc';
@ -25,161 +25,160 @@ languageSettings.schemas.push({ uri, fileMatch });
languageService.configure(languageSettings);
describe('Auto Completion Tests', () => {
describe('yamlCompletion with bowerrc', function () {
describe('doComplete', function () {
describe('yamlCompletion with bowerrc', function() {
describe('doComplete', function() {
function setup(content: string) {
return TextDocument.create(
'file://~/Desktop/vscode-k8s/test.yaml',
'yaml',
0,
content,
content
);
}
function parseSetup(content: string, position) {
const testTextDocument = setup(content);
const yDoc = parseYAML(testTextDocument.getText());
return completionHelper(
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 completion = parseSetup(content, 0);
completion
.then(function (result) {
.then(function(result) {
assert.notEqual(result.items.length, 0);
})
.then(done, done);
});
it('Autocomplete on root node with word', (done) => {
it('Autocomplete on root node with word', done => {
const content = 'analyt';
const completion = parseSetup(content, 6);
completion
.then(function (result) {
.then(function(result) {
assert.notEqual(result.items.length, 0);
})
.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 completion = parseSetup(content, 12);
completion
.then(function (result) {
expect(result.items.length).toEqual(0);
})
.then(done, done);
});
it('Autocomplete on default value (with value content)', (done) => {
const content = 'directory: bow';
const completion = parseSetup(content, 15);
completion
.then(function (result) {
assert.notEqual(result.items.length, 0);
})
.then(done, done);
});
it('Autocomplete on boolean value (without value content)', (done) => {
const content = 'analytics: ';
const completion = parseSetup(content, 11);
completion
.then(function (result) {
expect(result.items.length).toEqual(2);
})
.then(done, done);
});
it('Autocomplete on boolean value (with value content)', (done) => {
const content = 'analytics: fal';
const completion = parseSetup(content, 11);
completion
.then(function (result) {
assert.equal(result.items.length, 2);
})
.then(done, done);
});
it('Autocomplete on number value (without value content)', (done) => {
const content = 'timeout: ';
const completion = parseSetup(content, 9);
completion
.then(function (result) {
.then(function(result) {
expect(result.items.length).toEqual(1);
})
.then(done, done);
});
it('Autocomplete on number value (with value content)', (done) => {
it('Autocomplete on default value (with value content)', done => {
const content = 'directory: bow';
const completion = parseSetup(content, 15);
completion
.then(function(result) {
assert.notEqual(result.items.length, 0);
})
.then(done, done);
});
it('Autocomplete on boolean value (without value content)', done => {
const content = 'analytics: ';
const completion = parseSetup(content, 11);
completion
.then(function(result) {
expect(result.items.length).toEqual(2);
})
.then(done, done);
});
it('Autocomplete on boolean value (with value content)', done => {
const content = 'analytics: fal';
const completion = parseSetup(content, 11);
completion
.then(function(result) {
assert.equal(result.items.length, 2);
})
.then(done, done);
});
it('Autocomplete on number value (without value content)', done => {
const content = 'timeout: ';
const completion = parseSetup(content, 9);
completion
.then(function(result) {
expect(result.items.length).toEqual(1);
})
.then(done, done);
});
it('Autocomplete on number value (with value content)', done => {
const content = 'timeout: 6';
const completion = parseSetup(content, 10);
completion
.then(function (result) {
.then(function(result) {
assert.equal(result.items.length, 1);
})
.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 completion = parseSetup(content, 11);
completion
.then(function (result) {
.then(function(result) {
assert.notEqual(result.items.length, 0);
})
.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 completion = parseSetup(content, 31);
completion
.then(function (result) {
.then(function(result) {
assert.notEqual(result.items.length, 0);
})
.then(done, done);
});
it('Autocomplete does not happen right after :', (done) => {
it('Autocomplete does not happen right after :', done => {
const content = 'analytics:';
const completion = parseSetup(content, 9);
completion
.then(function (result) {
.then(function(result) {
assert.notEqual(result.items.length, 0);
})
.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 completion = parseSetup(content, 21);
completion
.then(function (result) {
.then(function(result) {
assert.notEqual(result.items.length, 0);
})
.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 completion = parseSetup(content, 28);
completion
.then(function (result) {
.then(function(result) {
assert.notEqual(result.items.length, 0);
})
.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 completion = parseSetup(content, 34);
completion
.then(function (result) {
.then(function(result) {
assert.notEqual(result.items.length, 0);
})
.then(done, done);

View file

@ -12,7 +12,7 @@ const assert = require('assert');
const languageService = getLanguageService(
schemaRequestService,
workspaceContext,
[],
[]
);
const uri = 'http://json.schemastore.org/composer';
@ -30,7 +30,7 @@ describe('Auto Completion Tests', () => {
'file://~/Desktop/vscode-k8s/test.yaml',
'yaml',
0,
content,
content
);
}
@ -38,13 +38,13 @@ describe('Auto Completion Tests', () => {
const testTextDocument = setup(content);
return completionHelper(
testTextDocument,
testTextDocument.positionAt(position),
testTextDocument.positionAt(position)
);
}
describe('yamlCompletion with composer', function() {
describe('doComplete', function() {
it('Array autocomplete without word', (done) => {
it('Array autocomplete without word', done => {
const content = 'authors:\n - ';
const completion = parseSetup(content, 14);
completion
@ -54,7 +54,7 @@ describe('Auto Completion Tests', () => {
.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 completion = parseSetup(content, 13);
completion
@ -64,7 +64,7 @@ describe('Auto Completion Tests', () => {
.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 completion = parseSetup(content, 24);
completion
@ -74,7 +74,7 @@ describe('Auto Completion Tests', () => {
.then(done, done);
});
it('Array autocomplete with letter', (done) => {
it('Array autocomplete with letter', done => {
const content = 'authors:\n - n';
const completion = parseSetup(content, 14);
completion
@ -84,7 +84,7 @@ describe('Auto Completion Tests', () => {
.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 completion = parseSetup(content, 32);
completion
@ -94,7 +94,7 @@ describe('Auto Completion Tests', () => {
.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 completion = parseSetup(content, 27);
completion
@ -104,7 +104,7 @@ describe('Auto Completion Tests', () => {
.then(done, done);
});
it('Autocompletion after array', (done) => {
it('Autocompletion after array', done => {
const content = 'authors:\n - name: test\n';
const completion = parseSetup(content, 24);
completion
@ -114,7 +114,7 @@ describe('Auto Completion Tests', () => {
.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 completion = parseSetup(content, 29);
completion
@ -124,7 +124,7 @@ describe('Auto Completion Tests', () => {
.then(done, done);
});
it('Autocompletion after array with depth', (done) => {
it('Autocompletion after array with depth', done => {
const content =
'autoload:\n classmap:\n - test\n exclude-from-classmap:\n - test\n ';
const completion = parseSetup(content, 70);
@ -137,7 +137,7 @@ describe('Auto Completion Tests', () => {
});
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 completion = parseSetup(content, 6);
completion
@ -147,7 +147,7 @@ describe('Auto Completion Tests', () => {
.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 completion = parseSetup(content, 33);
completion

View file

@ -12,7 +12,7 @@ const assert = require('assert');
const languageService = getLanguageService(
schemaRequestService,
workspaceContext,
[],
[]
);
const uri = 'http://json.schemastore.org/asmdef';
@ -32,7 +32,7 @@ describe('Auto Completion Tests', () => {
'file://~/Desktop/vscode-k8s/test.yaml',
'yaml',
0,
content,
content
);
}
@ -40,11 +40,11 @@ describe('Auto Completion Tests', () => {
const testTextDocument = setup(content);
return completionHelper(
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 completion = parseSetup(content, 29);
completion
@ -54,7 +54,7 @@ describe('Auto Completion Tests', () => {
.then(done, done);
});
it('Array of enum autocomplete without word', (done) => {
it('Array of enum autocomplete without word', done => {
const content = 'optionalUnityReferences:\n - ';
const completion = parseSetup(content, 30);
completion
@ -64,7 +64,7 @@ describe('Auto Completion Tests', () => {
.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 completion = parseSetup(content, 31);
completion

View file

@ -12,96 +12,117 @@ const assert = require('assert');
const languageService = getLanguageService(
schemaRequestService,
workspaceContext,
[],
[]
);
function traverse(
rootSymbols: DocumentSymbol[],
fn: (doc: DocumentSymbol) => void
) {
if (!rootSymbols || rootSymbols.length === 0) {
return;
}
rootSymbols.forEach(symbol => {
fn(symbol);
traverse(symbol.children, fn);
});
}
function allNodes(rootSymbols: DocumentSymbol[]): DocumentSymbol[] {
const res: DocumentSymbol[] = [];
traverse(rootSymbols, doc => res.push(doc));
return res;
}
// TODO: this suite is outdated and should be updated.
// https://github.com/Microsoft/vscode-json-languageservice/blob/master/src/test/documentSymbols.test.ts
xdescribe('Document Symbols Tests', () => {
describe('Document Symbols Tests', () => {
describe('Document Symbols Tests', function() {
function setup(content: string) {
return TextDocument.create(
'file://~/Desktop/vscode-k8s/test.yaml',
'yaml',
0,
content,
content
);
}
function parseSetup(content: string) {
const testTextDocument = setup(content);
const jsonDocument = parseYAML(testTextDocument.getText());
return languageService.findDocumentSymbols(
const rootSymbols = languageService.findDocumentSymbols(
testTextDocument,
jsonDocument,
jsonDocument
);
return allNodes(rootSymbols);
}
it('Document is empty', (done) => {
it('Document is empty', done => {
const content = '';
const symbols = parseSetup(content);
assert.equal(symbols, null);
assert.equal(symbols.length, 0);
done();
});
it('Simple document symbols', (done) => {
it('Simple document symbols', done => {
const content = 'cwd: test';
const symbols = parseSetup(content);
assert.equal(symbols.length, 1);
done();
});
it('Document Symbols with number', (done) => {
it('Document Symbols with number', done => {
const content = 'node1: 10000';
const symbols = parseSetup(content);
assert.equal(symbols.length, 1);
done();
});
it('Document Symbols with boolean', (done) => {
it('Document Symbols with boolean', done => {
const content = 'node1: False';
const symbols = parseSetup(content);
assert.equal(symbols.length, 1);
done();
});
it('Document Symbols with object', (done) => {
it('Document Symbols with object', done => {
const content = 'scripts:\n node1: test\n node2: test';
const symbols = parseSetup(content);
assert.equal(symbols.length, 3);
done();
});
it('Document Symbols with null', (done) => {
it('Document Symbols with null', done => {
const content = 'apiVersion: null';
const symbols = parseSetup(content);
assert.equal(symbols.length, 1);
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 symbols = parseSetup(content);
assert.equal(symbols.length, 1);
done();
});
it('Document Symbols with array', (done) => {
const content = 'authors:\n - name: Josh\n - email: jp';
const symbols = parseSetup(content);
assert.equal(symbols.length, 3);
done();
});
it('Document Symbols with object and array', (done) => {
const content =
'scripts:\n node1: test\n node2: test\nauthors:\n - name: Josh\n - email: jp';
it('Document Symbols with array', done => {
const content = 'authors:\n - name: Josh\n - email: jp';
const symbols = parseSetup(content);
assert.equal(symbols.length, 6);
assert.equal(symbols.length, 5);
done();
});
it('Document Symbols with multi documents', (done) => {
it('Document Symbols with object and array', done => {
const content =
'scripts:\n node1: test\n node2: test\nauthors:\n - name: Josh\n - email: jp';
const symbols = parseSetup(content);
assert.equal(symbols.length, 8);
done();
});
it('Document Symbols with multi documents', done => {
const content = '---\nanalytics: true\n...\n---\njson: test\n...';
const symbols = parseSetup(content);
assert.equal(symbols.length, 2);

View file

@ -10,7 +10,7 @@ const assert = require('assert');
const languageService = getLanguageService(
schemaRequestService,
workspaceContext,
[],
[]
);
const uri = 'http://json.schemastore.org/bowerrc';
@ -32,7 +32,7 @@ describe('Formatter Tests', () => {
'file://~/Desktop/vscode-k8s/test.yaml',
'yaml',
0,
content,
content
);
}
@ -42,18 +42,18 @@ describe('Formatter Tests', () => {
const testTextDocument = setup(content);
const edits = languageService.doFormat(
testTextDocument,
{} as FormattingOptions,
{} as FormattingOptions
);
assert.notEqual(edits.length, 0);
assert.equal(edits[0].newText, 'cwd: test\n');
});
it('Formatting works without custom tags', () => {
it('Formatting works with custom tags', () => {
const content = `cwd: !Test test`;
const testTextDocument = setup(content);
const edits = languageService.doFormat(
testTextDocument,
{} as FormattingOptions,
{} as FormattingOptions
);
assert.notEqual(edits.length, 0);
});

View file

@ -4,14 +4,17 @@
*--------------------------------------------------------------------------------------------*/
import { TextDocument } from 'vscode-languageserver';
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';
const assert = require('assert');
const languageService = getLanguageService(
schemaRequestService,
workspaceContext,
[],
[]
);
const uri = 'http://json.schemastore.org/bowerrc';
@ -24,14 +27,14 @@ languageSettings.schemas.push({ uri, fileMatch });
languageService.configure(languageSettings);
describe('Hover Tests', () => {
describe('Yaml Hover with bowerrc', function () {
describe('doComplete', function () {
describe('Yaml Hover with bowerrc', function() {
describe('doComplete', function() {
function setup(content: string) {
return TextDocument.create(
'file://~/Desktop/vscode-k8s/test.yaml',
'yaml',
0,
content,
content
);
}
@ -41,81 +44,81 @@ describe('Hover Tests', () => {
return languageService.doHover(
testTextDocument,
testTextDocument.positionAt(position),
jsonDocument,
jsonDocument
);
}
it('Hover on key on root', (done) => {
it('Hover on key on root', done => {
const content = 'cwd: test';
const hover = parseSetup(content, 1);
hover
.then(function (result) {
.then(function(result) {
assert.notEqual(result.contents.length, 0);
})
.then(done, done);
});
it('Hover on value on root', (done) => {
it('Hover on value on root', done => {
const content = 'cwd: test';
const hover = parseSetup(content, 6);
hover
.then(function (result) {
.then(function(result) {
assert.notEqual(result.contents.length, 0);
})
.then(done, done);
});
it('Hover on key with depth', (done) => {
it('Hover on key with depth', done => {
const content = 'scripts:\n postinstall: test';
const hover = parseSetup(content, 15);
hover
.then(function (result) {
.then(function(result) {
assert.notEqual(result.contents.length, 0);
})
.then(done, done);
});
it('Hover on value with depth', (done) => {
it('Hover on value with depth', done => {
const content = 'scripts:\n postinstall: test';
const hover = parseSetup(content, 26);
hover
.then(function (result) {
.then(function(result) {
assert.notEqual(result.contents.length, 0);
})
.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 firstHover = parseSetup(content, 3);
firstHover.then(function (result) {
firstHover.then(function(result) {
assert.notEqual(result.contents.length, 0);
});
const secondHover = parseSetup(content, 15);
secondHover
.then(function (result) {
.then(function(result) {
assert.notEqual(result.contents.length, 0);
})
.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 hover = parseSetup(content, 3);
hover
.then(function (result) {
.then(function(result) {
assert.notEqual(result.contents.length, 0);
})
.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 hover = parseSetup(content, 30);
hover
.then(function (result) {
.then(function(result) {
assert.notEqual(result.contents.length, 0);
})
.then(done, done);

View file

@ -14,7 +14,7 @@ const assert = require('assert');
const languageService = getLanguageService(
schemaRequestService,
workspaceContext,
[],
[]
);
const uri = 'http://json.schemastore.org/composer';
@ -34,7 +34,7 @@ describe('Hover Tests', () => {
'file://~/Desktop/vscode-k8s/test.yaml',
'yaml',
0,
content,
content
);
}
@ -44,11 +44,11 @@ describe('Hover Tests', () => {
return languageService.doHover(
testTextDocument,
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 hover = parseSetup(content, 14);
hover
@ -58,7 +58,7 @@ describe('Hover Tests', () => {
.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 hover = parseSetup(content, 28);
hover

View file

@ -4,14 +4,17 @@
*--------------------------------------------------------------------------------------------*/
import { TextDocument } from 'vscode-languageserver';
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';
const assert = require('assert');
const languageService = getLanguageService(
schemaRequestService,
workspaceContext,
[],
[]
);
const uri = 'http://json.schemastore.org/bowerrc';
@ -24,14 +27,14 @@ languageSettings.schemas.push({ uri, fileMatch });
languageService.configure(languageSettings);
describe('Hover Setting Tests', () => {
describe('Yaml Hover with bowerrc', function () {
describe('doComplete', function () {
describe('Yaml Hover with bowerrc', function() {
describe('doComplete', function() {
function setup(content: string) {
return TextDocument.create(
'file://~/Desktop/vscode-k8s/test.yaml',
'yaml',
0,
content,
content
);
}
@ -41,16 +44,16 @@ describe('Hover Setting Tests', () => {
return languageService.doHover(
testTextDocument,
testTextDocument.positionAt(position),
jsonDocument,
jsonDocument
);
}
it('Hover should not return anything', (done) => {
it('Hover should not return anything', done => {
const content = 'cwd: test';
const hover = parseSetup(content, 1);
hover
.then(function (result) {
assert.notEqual(result, undefined);
.then(function(result) {
assert.equal(result, undefined);
})
.then(done, done);
});

View file

@ -12,7 +12,7 @@ const assert = require('assert');
const languageService = getLanguageService(
schemaRequestService,
workspaceContext,
[],
[]
);
const uri =
@ -34,7 +34,7 @@ xdescribe('Kubernetes Integration Tests', () => {
'file://~/Desktop/vscode-k8s/test.yaml',
'yaml',
0,
content,
content
);
}
@ -46,7 +46,7 @@ xdescribe('Kubernetes Integration Tests', () => {
// Validating basic nodes
describe('Test that validation does not throw errors', function() {
it('Basic test', (done) => {
it('Basic test', done => {
const content = `apiVersion: v1`;
const validator = parseSetup(content);
validator
@ -56,7 +56,7 @@ xdescribe('Kubernetes Integration Tests', () => {
.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 validator = parseSetup(content);
validator
@ -66,7 +66,7 @@ xdescribe('Kubernetes Integration Tests', () => {
.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 validator = parseSetup(content);
validator
@ -76,7 +76,7 @@ xdescribe('Kubernetes Integration Tests', () => {
.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 validator = parseSetup(content);
validator
@ -87,7 +87,7 @@ xdescribe('Kubernetes Integration Tests', () => {
});
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 validator = parseSetup(content);
validator
@ -97,7 +97,7 @@ xdescribe('Kubernetes Integration Tests', () => {
.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 validator = parseSetup(content);
validator
@ -107,7 +107,7 @@ xdescribe('Kubernetes Integration Tests', () => {
.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 validator = parseSetup(content);
validator
@ -117,7 +117,7 @@ xdescribe('Kubernetes Integration Tests', () => {
.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 validator = parseSetup(content);
validator
@ -127,7 +127,7 @@ xdescribe('Kubernetes Integration Tests', () => {
.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 validator = parseSetup(content);
validator
@ -140,7 +140,7 @@ xdescribe('Kubernetes Integration Tests', () => {
});
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 validator = parseSetup(content);
validator
@ -150,7 +150,7 @@ xdescribe('Kubernetes Integration Tests', () => {
.then(done, done);
});
it('Error on incorrect value type (number)', (done) => {
it('Error on incorrect value type (number)', done => {
const content = `apiVersion: 1000`;
const validator = parseSetup(content);
validator
@ -160,7 +160,7 @@ xdescribe('Kubernetes Integration Tests', () => {
.then(done, done);
});
it('Error on incorrect value type (boolean)', (done) => {
it('Error on incorrect value type (boolean)', done => {
const content = `apiVersion: False`;
const validator = parseSetup(content);
validator
@ -170,7 +170,7 @@ xdescribe('Kubernetes Integration Tests', () => {
.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 validator = parseSetup(content);
validator
@ -180,7 +180,7 @@ xdescribe('Kubernetes Integration Tests', () => {
.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 validator = parseSetup(content);
validator
@ -190,7 +190,7 @@ xdescribe('Kubernetes Integration Tests', () => {
.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 validator = parseSetup(content);
validator
@ -200,7 +200,7 @@ xdescribe('Kubernetes Integration Tests', () => {
.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 validator = parseSetup(content);
validator
@ -220,7 +220,7 @@ xdescribe('Kubernetes Integration Tests', () => {
'file://~/Desktop/vscode-k8s/test.yaml',
'yaml',
0,
content,
content
);
}
@ -229,11 +229,11 @@ xdescribe('Kubernetes Integration Tests', () => {
const yDoc = parseYAML(testTextDocument.getText());
return completionHelper(
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 completion = parseSetup(content, 0);
completion
@ -243,7 +243,7 @@ xdescribe('Kubernetes Integration Tests', () => {
.then(done, done);
});
it('Autocomplete on root node with word', (done) => {
it('Autocomplete on root node with word', done => {
const content = 'api';
const completion = parseSetup(content, 6);
completion
@ -253,7 +253,7 @@ xdescribe('Kubernetes Integration Tests', () => {
.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 completion = parseSetup(content, 10);
completion
@ -263,7 +263,7 @@ xdescribe('Kubernetes Integration Tests', () => {
.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 completion = parseSetup(content, 19);
completion
@ -273,7 +273,7 @@ xdescribe('Kubernetes Integration Tests', () => {
.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 completion = parseSetup(content, 18);
completion
@ -283,7 +283,7 @@ xdescribe('Kubernetes Integration Tests', () => {
.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 completion = parseSetup(content, 21);
completion
@ -293,7 +293,7 @@ xdescribe('Kubernetes Integration Tests', () => {
.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 completion = parseSetup(content, 14);
completion
@ -303,7 +303,7 @@ xdescribe('Kubernetes Integration Tests', () => {
.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 completion = parseSetup(content, 31);
completion

View file

@ -34,7 +34,7 @@ function toFsPath(str): string {
}
const uri = toFsPath(
path.join(__dirname, './fixtures/customMultipleSchemaSequences.json'),
path.join(__dirname, './fixtures/customMultipleSchemaSequences.json')
);
const languageSettings: LanguageSettings = {
schemas: [],
@ -50,13 +50,13 @@ languageService.configure(languageSettings);
describe('Multiple Documents Validation Tests', () => {
// Tests for validator
describe('Multiple Documents Validation', function () {
describe('Multiple Documents Validation', function() {
function setup(content: string) {
return TextDocument.create(
'file://~/Desktop/vscode-k8s/test.yaml',
'yaml',
0,
content,
content
);
}
@ -64,7 +64,7 @@ describe('Multiple Documents Validation Tests', () => {
const testTextDocument = setup(content);
const yDoc = parseYAML(
testTextDocument.getText(),
languageSettings.customTags,
languageSettings.customTags
);
return languageService.doValidation(testTextDocument, yDoc);
}
@ -75,11 +75,11 @@ describe('Multiple Documents Validation Tests', () => {
return languageService.doHover(
testTextDocument,
testTextDocument.positionAt(position),
jsonDocument,
jsonDocument
);
}
it('Should validate multiple documents', (done) => {
it('Should validate multiple documents', done => {
const content = `
name: jack
age: 22
@ -88,56 +88,56 @@ analytics: true
`;
const validator = validatorSetup(content);
validator
.then((result) => {
.then(result => {
assert.equal(result.length, 0);
})
.then(done, done);
});
it('Should find errors in both documents', (done) => {
it('Should find errors in both documents', done => {
const content = `name1: jack
age: asd
---
cwd: False`;
const validator = validatorSetup(content);
validator
.then(function (result) {
.then(function(result) {
assert.equal(result.length, 3);
})
.then(done, done);
});
it('Should find errors in first document', (done) => {
it('Should find errors in first document', done => {
const content = `name: jack
age: age
---
analytics: true`;
const validator = validatorSetup(content);
validator
.then(function (result) {
.then(function(result) {
assert.equal(result.length, 1);
})
.then(done, done);
});
it('Should find errors in second document', (done) => {
it('Should find errors in second document', done => {
const content = `name: jack
age: 22
---
cwd: False`;
const validator = validatorSetup(content);
validator
.then(function (result) {
.then(function(result) {
assert.equal(result.length, 1);
})
.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 hover = hoverSetup(content, 1 + content.indexOf('age'));
hover
.then(function (result) {
.then(function(result) {
assert.notEqual(result.contents.length, 0);
assert.equal(result.contents[0], 'The age of this person');
})

View file

@ -25,7 +25,7 @@ const fixtureDocuments = {
'http://schema.management.azure.com/schemas/2015-08-01/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] === '#') {
uri = uri.substr(0, uri.length - 1);
}
@ -48,10 +48,10 @@ const workspaceContext = {
};
describe('JSON Schema', () => {
test('Resolving $refs', function (testDone) {
test('Resolving $refs', function(testDone) {
const service = new SchemaService.JSONSchemaService(
requestServiceMock,
workspaceContext,
workspaceContext
);
service.setSchemaContributions({
schemas: {
@ -74,7 +74,7 @@ describe('JSON Schema', () => {
service
.getResolvedSchema('https://myschemastore/main')
.then((solvedSchema) => {
.then(solvedSchema => {
assert.deepEqual(solvedSchema.schema.properties.child, {
id: 'https://myschemastore/child',
type: 'bool',
@ -83,16 +83,16 @@ describe('JSON Schema', () => {
})
.then(
() => testDone(),
(error) => {
error => {
testDone(error);
},
}
);
});
test('Resolving $refs 2', function (testDone) {
test('Resolving $refs 2', function(testDone) {
const service = new SchemaService.JSONSchemaService(
requestServiceMock,
workspaceContext,
workspaceContext
);
service.setSchemaContributions({
schemas: {
@ -121,7 +121,7 @@ describe('JSON Schema', () => {
service
.getResolvedSchema('http://json.schemastore.org/swagger-2.0')
.then((fs) => {
.then(fs => {
assert.deepEqual(fs.schema.properties.responseValue, {
type: 'object',
required: ['$ref'],
@ -130,16 +130,16 @@ describe('JSON Schema', () => {
})
.then(
() => testDone(),
(error) => {
error => {
testDone(error);
},
}
);
});
test('Resolving $refs 3', function (testDone) {
test('Resolving $refs 3', function(testDone) {
const service = new SchemaService.JSONSchemaService(
requestServiceMock,
workspaceContext,
workspaceContext
);
service.setSchemaContributions({
schemas: {
@ -172,7 +172,7 @@ describe('JSON Schema', () => {
service
.getResolvedSchema('https://myschemastore/main/schema1.json')
.then((fs) => {
.then(fs => {
assert.deepEqual(fs.schema.properties.p1, {
type: 'string',
enum: ['object'],
@ -188,16 +188,16 @@ describe('JSON Schema', () => {
})
.then(
() => testDone(),
(error) => {
error => {
testDone(error);
},
}
);
});
test('FileSchema', function (testDone) {
test('FileSchema', function(testDone) {
const service = new SchemaService.JSONSchemaService(
requestServiceMock,
workspaceContext,
workspaceContext
);
service.setSchemaContributions({
@ -222,22 +222,22 @@ describe('JSON Schema', () => {
service
.getResolvedSchema('main')
.then((fs) => {
.then(fs => {
const section = fs.getSection(['child', 'grandchild']);
assert.equal(section.description, 'Meaning of Life');
})
.then(
() => testDone(),
(error) => {
error => {
testDone(error);
},
}
);
});
test('Array FileSchema', function (testDone) {
test('Array FileSchema', function(testDone) {
const service = new SchemaService.JSONSchemaService(
requestServiceMock,
workspaceContext,
workspaceContext
);
service.setSchemaContributions({
@ -265,22 +265,22 @@ describe('JSON Schema', () => {
service
.getResolvedSchema('main')
.then((fs) => {
.then(fs => {
const section = fs.getSection(['child', '0', 'grandchild']);
assert.equal(section.description, 'Meaning of Life');
})
.then(
() => testDone(),
(error) => {
error => {
testDone(error);
},
}
);
});
test('Missing subschema', function (testDone) {
test('Missing subschema', function(testDone) {
const service = new SchemaService.JSONSchemaService(
requestServiceMock,
workspaceContext,
workspaceContext
);
service.setSchemaContributions({
@ -299,22 +299,22 @@ describe('JSON Schema', () => {
service
.getResolvedSchema('main')
.then((fs) => {
.then(fs => {
const section = fs.getSection(['child', 'grandchild']);
assert.strictEqual(section, null);
})
.then(
() => testDone(),
(error) => {
error => {
testDone(error);
},
}
);
});
test('Preloaded Schema', function (testDone) {
test('Preloaded Schema', function(testDone) {
const service = new SchemaService.JSONSchemaService(
requestServiceMock,
workspaceContext,
workspaceContext
);
const id = 'https://myschemastore/test1';
const schema: JsonSchema.JSONSchema = {
@ -336,53 +336,53 @@ describe('JSON Schema', () => {
service
.getSchemaForResource('test.json')
.then((schema) => {
.then(schema => {
const section = schema.getSection(['child', 'grandchild']);
assert.equal(section.description, 'Meaning of Life');
})
.then(
() => testDone(),
(error) => {
error => {
testDone(error);
},
}
);
});
test('Null Schema', function (testDone) {
test('Null Schema', function(testDone) {
const service = new SchemaService.JSONSchemaService(
requestServiceMock,
workspaceContext,
workspaceContext
);
service
.getSchemaForResource('test.json')
.then((schema) => {
.then(schema => {
assert.equal(schema, null);
})
.then(
() => testDone(),
(error) => {
error => {
testDone(error);
},
}
);
});
test('Schema not found', function (testDone) {
test('Schema not found', function(testDone) {
const service = new SchemaService.JSONSchemaService(
requestServiceMock,
workspaceContext,
workspaceContext
);
service
.loadSchema('test.json')
.then((schema) => {
.then(schema => {
assert.notEqual(schema.errors.length, 0);
})
.then(
() => testDone(),
(error) => {
error => {
testDone(error);
},
}
);
});
});

View file

@ -11,7 +11,7 @@ const assert = require('assert');
const languageService = getLanguageService(
schemaRequestService,
workspaceContext,
[],
[]
);
const uri = 'SchemaDoesNotExist';
@ -32,7 +32,7 @@ describe('Validation Tests', () => {
'file://~/Desktop/vscode-k8s/test.yaml',
'yaml',
0,
content,
content
);
}
@ -40,14 +40,14 @@ describe('Validation Tests', () => {
const testTextDocument = setup(content);
const yDoc = parseYAML(
testTextDocument.getText(),
languageSettings.customTags,
languageSettings.customTags
);
return languageService.doValidation(testTextDocument, yDoc);
}
// Validating basic nodes
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 validator = parseSetup(content);
validator

View file

@ -11,7 +11,7 @@ const assert = require('assert');
const languageService = getLanguageService(
schemaRequestService,
workspaceContext,
[],
[]
);
const uri = 'http://json.schemastore.org/bowerrc';
@ -28,13 +28,13 @@ languageService.configure(languageSettings);
describe('Validation Tests', () => {
// Tests for validator
describe('Validation', function () {
describe('Validation', function() {
function setup(content: string) {
return TextDocument.create(
'file://~/Desktop/vscode-k8s/test.yaml',
'yaml',
0,
content,
content
);
}
@ -42,154 +42,154 @@ describe('Validation Tests', () => {
const testTextDocument = setup(content);
const yDoc = parseYAML(
testTextDocument.getText(),
languageSettings.customTags,
languageSettings.customTags
);
return languageService.doValidation(testTextDocument, yDoc);
}
// Validating basic nodes
describe('Test that validation does not throw errors', function () {
it('Basic test', (done) => {
describe('Test that validation does not throw errors', function() {
it('Basic test', done => {
const content = `analytics: true`;
const validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
expect(result.length).toEqual(0);
})
.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 validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
assert.notEqual(result.length, 0);
})
.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 validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
expect(result.length).toEqual(0);
})
.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 validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
expect(result.length).toEqual(0);
})
.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 validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
assert.notEqual(result.length, 0);
})
.then(done, done);
});
it('Basic test', (done) => {
it('Basic test', done => {
const content = `analytics: true`;
const validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
expect(result.length).toEqual(0);
})
.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 validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
expect(result.length).toEqual(0);
})
.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 validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
expect(result.length).toEqual(0);
})
.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 validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
expect(result.length).toEqual(0);
})
.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 validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
expect(result.length).toEqual(0);
})
.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 validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
expect(result.length).toEqual(1);
})
.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 validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
expect(result.length).toEqual(0);
})
.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 validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
expect(result.length).toEqual(0);
})
.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 validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
expect(result.length).toEqual(0);
})
.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 = `
default: &DEFAULT
name: Anchor
@ -201,87 +201,87 @@ describe('Validation Tests', () => {
`;
const validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
expect(result.length).toEqual(0);
})
.then(done, done);
});
it('Custom Tags without type', (done) => {
it('Custom Tags without type', done => {
const content = `analytics: !Test false`;
const validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
expect(result.length).toEqual(0);
})
.then(done, done);
});
it('Custom Tags with type', (done) => {
it('Custom Tags with type', done => {
const content = `resolvers: !Ref\n - test`;
const validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
expect(result.length).toEqual(0);
})
.then(done, done);
});
describe('Type tests', function () {
it('Type String does not error on valid node', (done) => {
describe('Type tests', function() {
it('Type String does not error on valid node', done => {
const content = `cwd: this`;
const validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
expect(result.length).toEqual(0);
})
.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 validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
expect(result.length).toEqual(0);
})
.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 validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
expect(result.length).toEqual(0);
})
.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 validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
expect(result.length).toEqual(0);
})
.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 validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
expect(result.length).toEqual(0);
})
.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 validator = parseSetup(content);
validator.then(function (result) {
validator.then(function(result) {
expect(result.length).toEqual(0);
});
done();
@ -289,82 +289,82 @@ describe('Validation Tests', () => {
});
});
describe('Test that validation DOES throw errors', function () {
it('Error when theres a finished untyped item', (done) => {
describe('Test that validation DOES throw errors', function() {
it('Error when theres a finished untyped item', done => {
const content = `cwd: hello\nan`;
const validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
assert.notEqual(result.length, 0);
})
.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 validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
assert.notEqual(result.length, 0);
})
.then(done, done);
});
it('Error on incorrect value type (number)', (done) => {
it('Error on incorrect value type (number)', done => {
const content = `cwd: 100000`;
const validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
assert.notEqual(result.length, 0);
})
.then(done, done);
});
it('Error on incorrect value type (boolean)', (done) => {
it('Error on incorrect value type (boolean)', done => {
const content = `cwd: False`;
const validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
assert.notEqual(result.length, 0);
})
.then(done, done);
});
it('Error on incorrect value type (string)', (done) => {
it('Error on incorrect value type (string)', done => {
const content = `analytics: hello`;
const validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
assert.notEqual(result.length, 0);
})
.then(done, done);
});
it('Error on incorrect value type (object)', (done) => {
it('Error on incorrect value type (object)', done => {
const content = `scripts: test`;
const validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
assert.notEqual(result.length, 0);
})
.then(done, done);
});
it('Error on incorrect value type (array)', (done) => {
it('Error on incorrect value type (array)', done => {
const content = `resolvers: test`;
const validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
assert.notEqual(result.length, 0);
})
.then(done, done);
});
it('Include without value should error', (done) => {
it('Include without value should error', done => {
const content = `customize: !include`;
const validator = parseSetup(content);
validator
.then(function (result) {
.then(function(result) {
expect(result.length).toEqual(1);
})
.then(done, done);

View file

@ -19,7 +19,7 @@ import URI from '../src/languageservice/utils/uri';
namespace VSCodeContentRequest {
export const type: RequestType<{}, {}, {}, {}> = new RequestType(
'vscode/content',
'vscode/content'
);
}
@ -28,7 +28,7 @@ let connection: IConnection = null;
if (process.argv.indexOf('--stdio') === -1) {
connection = createConnection(
new IPCMessageReader(process),
new IPCMessageWriter(process),
new IPCMessageWriter(process)
);
} else {
connection = createConnection();
@ -50,7 +50,7 @@ connection.onInitialize(
},
},
};
},
}
);
export let workspaceContext = {
@ -69,24 +69,24 @@ export let schemaRequestService = (uri: string): Thenable<string> => {
});
} else if (Strings.startsWith(uri, 'vscode://')) {
return connection.sendRequest(VSCodeContentRequest.type, uri).then(
(responseText) => {
responseText => {
return responseText;
},
(error) => {
error => {
return error.message;
},
}
);
}
return xhr({ url: uri, followRedirects: 5 }).then(
(response) => {
response => {
return response.responseText;
},
(error: XHRResponse) => {
return Promise.reject(
error.responseText ||
getErrorStatusDescription(error.status) ||
error.toString(),
error.toString()
);
},
}
);
};

View file

@ -7,7 +7,6 @@
"esModuleInterop": true,
"sourceMap": true,
"lib": ["es2016"],
"outDir": "./out/server",
"downlevelIteration": true
},
"exclude": ["node_modules", "out"]

View file

@ -26,7 +26,7 @@ describe('URI Tests', () => {
'www.foo.com',
'/bar.html',
'name=hello',
'123',
'123'
);
assert.equal(result.authority, 'www.foo.com');
assert.equal(result.fragment, '123');
@ -69,14 +69,14 @@ describe('URI Tests', () => {
describe('URI toString', function() {
it('toString with encoding', () => {
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();
assert.equal('http://www.foo.com:8080/bar.html?name%3Dhello#123', result);
});
it('toString without encoding', () => {
const result = URI.parse(
'http://www.foo.com/bar.html?name=hello#123',
'http://www.foo.com/bar.html?name=hello#123'
).toString(true);
assert.equal('http://www.foo.com/bar.html?name=hello#123', result);
});

24
test/yamlDocument.test.ts Normal file
View file

@ -0,0 +1,24 @@
import { TextDocument } from 'vscode-languageserver';
import { parse as parseYAML } from '../src/languageservice/parser/yamlParser';
describe('SingleYAMLDocument tests', () => {
function setup(content: string) {
return (offset: number) => {
const yamlDocs = parseYAML(content);
// Should be one doc only
expect(yamlDocs.documents.length).toBe(1);
return yamlDocs.documents[0].getCompletionNodeFromOffset(offset);
};
}
describe('getCompletionNodeFromOffset for simple null value mapping', () => {
const content = 'a : \n ';
const parseSetup = setup(content);
it('within value of `a`', () => {
const node = parseSetup(1);
expect(node.value).toBe('a');
expect(node.type).toBe('string');
});
});
});