From ecc350ca5c2eb50be8309c5f14f8bf0d87db9a02 Mon Sep 17 00:00:00 2001 From: Moon Flower Date: Mon, 12 Oct 2026 08:46:23 +0330 Subject: a --- tests/drivers/hover_test.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/drivers/hover_test.js (limited to 'tests/drivers/hover_test.js') diff --git a/tests/drivers/hover_test.js b/tests/drivers/hover_test.js new file mode 100644 index 0000000..10af643 --- /dev/null +++ b/tests/drivers/hover_test.js @@ -0,0 +1,23 @@ +// protocol conversion checks. run with node tests/drivers/hover_test.js. +const assert = require('assert'); +const { hoverContents } = require('../../editors/vscode/client/hover'); +class MarkdownString { + constructor() { this.value = ''; this.calls = []; } + appendMarkdown(value) { this.calls.push('markdown'); this.value += value; return this; } + appendText(value) { this.calls.push('text'); this.value += value; return this; } + appendCodeblock(value, language) { this.calls.push('code'); this.value += '\n```' + language + '\n' + value + '\n```\n'; return this; } +} +const api = { MarkdownString }; +const markdown = '```zc\nint add(int a, int b)\n```\n\nAdds **two** numbers.'; +const md = hoverContents(api, { kind: 'markdown', value: markdown })[0]; +assert.strictEqual(md.value, markdown); +assert.deepStrictEqual(md.calls, ['markdown']); +assert.strictEqual(md.isTrusted, false); +assert.strictEqual(md.supportHtml, false); +assert.deepStrictEqual(hoverContents(api, { kind: 'plaintext', value: '*literal*' })[0].calls, ['text']); +const legacy = hoverContents(api, { language: 'zc', value: 'int x;' })[0]; +assert.match(legacy.value, /```zc\nint x;\n```/); +assert.deepStrictEqual(legacy.calls, ['code']); +assert.strictEqual(hoverContents(api, ['**Doc**', { language: 'zc', value: 'fn main()' }]).length, 2); +for (const contents of [null, undefined, '', [], {}, { value: 123 }]) assert.deepStrictEqual(hoverContents(api, contents), []); +console.log('ok hover conversion preserves Markdown, plaintext, code, and arrays'); -- cgit v1.2.3