// 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');