Skip to content

Commit

Permalink
Add test for hover contributions
Browse files Browse the repository at this point in the history
  • Loading branch information
apexskier committed Oct 1, 2020
1 parent 33577eb commit 89eb0dd
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions src/test/hover.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ import * as JsonSchema from '../jsonSchema';
import { JSONHover } from '../services/jsonHover';

import { Hover, Position, MarkedString, TextDocument } from '../jsonLanguageService';
import { MarkupKind } from "../jsonLanguageTypes";
import { JSONWorkerContribution, MarkupKind } from "../jsonLanguageTypes";

suite('JSON Hover', () => {

function testComputeInfo(value: string, schema: JsonSchema.JSONSchema, position: Position): PromiseLike<Hover> {
function testComputeInfo(
value: string,
schema: JsonSchema.JSONSchema,
position: Position,
contributions: JSONWorkerContribution[] = [],
): PromiseLike<Hover> {
const uri = 'test://test.json';

const schemaService = new SchemaService.JSONSchemaService(requestService);
const hoverProvider = new JSONHover(schemaService, [], Promise);
const hoverProvider = new JSONHover(schemaService, contributions, Promise);
const id = "http://myschemastore/test1";
schemaService.registerExternalSchema(id, ["*.json"], schema);

Expand Down Expand Up @@ -182,4 +187,32 @@ suite('JSON Hover', () => {
assert.deepEqual(result.contents, { kind: MarkupKind.Markdown, value: 'Title with \\*markdown\\* characters\n\nline1\r\n*line2*\r\n\r\n`line3`' });
});
});

test("Hover contributions", async () => {
const content = '{"a": 42, "b": "hello", "c": false}';
const schema: JsonSchema.JSONSchema = {};
const contribution: JSONWorkerContribution = {
async getInfoContribution(uri, location) {
return {
kind: MarkupKind.PlainText,
value: "Custom contribution info"
};
},
async collectPropertyCompletions(uri, location, currentWord, addValue, isLast, result) {
assert.fail();
},
async collectValueCompletions(uri, location, propertyKey, result) {
assert.fail();
},
async collectDefaultCompletions(uri, result) {
assert.fail();
},
async resolveCompletion(item) {
assert.fail();
}
};
await testComputeInfo(content, schema, { line: 0, character: 7 }, [contribution]).then((result) => {
assert.deepEqual(result.contents, { kind: MarkupKind.PlainText, value: 'Custom contribution info' });
});
});
});

0 comments on commit 89eb0dd

Please sign in to comment.