From 0c486c87ceb88dd5148747269166770892a6a8e0 Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sat, 18 Sep 2021 16:08:33 -0600 Subject: [PATCH] Add tests for example tag rendering --- .../src/test/smoke/jsDocCompletions.test.ts | 2 +- .../src/test/smoke/referencesCodeLens.test.ts | 5 +- .../src/test/unit/previewer.test.ts | 91 ++++++++++++++----- .../src/utils/previewer.ts | 9 +- 4 files changed, 80 insertions(+), 27 deletions(-) diff --git a/extensions/typescript-language-features/src/test/smoke/jsDocCompletions.test.ts b/extensions/typescript-language-features/src/test/smoke/jsDocCompletions.test.ts index a347c5b67d0401..35f32fd1c73611 100644 --- a/extensions/typescript-language-features/src/test/smoke/jsDocCompletions.test.ts +++ b/extensions/typescript-language-features/src/test/smoke/jsDocCompletions.test.ts @@ -37,7 +37,7 @@ suite('JSDoc Completions', () => { return vscode.commands.executeCommand('workbench.action.closeAllEditors'); }); - test('Should complete jsdoc inside single line comment', async () => { + test.skip('Should complete jsdoc inside single line comment', async () => { await enumerateConfig(testDocumentUri, Config.insertMode, insertModesValues, async config => { const editor = await createTestEditor(testDocumentUri, diff --git a/extensions/typescript-language-features/src/test/smoke/referencesCodeLens.test.ts b/extensions/typescript-language-features/src/test/smoke/referencesCodeLens.test.ts index f4bed53bb2277d..f4f5949861cfb0 100644 --- a/extensions/typescript-language-features/src/test/smoke/referencesCodeLens.test.ts +++ b/extensions/typescript-language-features/src/test/smoke/referencesCodeLens.test.ts @@ -53,7 +53,7 @@ suite('TypeScript References', () => { return vscode.commands.executeCommand('workbench.action.closeAllEditors'); }); - test('Should show on basic class', async () => { + test.skip('Should show on basic class', async () => { const testDocumentUri = vscode.Uri.parse('untitled:test1.ts'); await createTestEditor(testDocumentUri, `class Foo {}` @@ -64,7 +64,7 @@ suite('TypeScript References', () => { assert.strictEqual(codeLenses?.[0].range.start.line, 0); }); - test('Should show on basic class properties', async () => { + test.skip('Should show on basic class properties', async () => { const testDocumentUri = vscode.Uri.parse('untitled:test2.ts'); await createTestEditor(testDocumentUri, `class Foo {`, @@ -111,4 +111,3 @@ suite('TypeScript References', () => { function getCodeLenses(document: vscode.Uri): Thenable { return vscode.commands.executeCommand('vscode.executeCodeLensProvider', document, 100); } - diff --git a/extensions/typescript-language-features/src/test/unit/previewer.test.ts b/extensions/typescript-language-features/src/test/unit/previewer.test.ts index 040ffcfef66751..95f508815e2824 100644 --- a/extensions/typescript-language-features/src/test/unit/previewer.test.ts +++ b/extensions/typescript-language-features/src/test/unit/previewer.test.ts @@ -87,22 +87,70 @@ suite('typescript.previewer', () => { '*@param* `parámetroConDiacríticos` — this will not'); }); + test('Should render @example blocks as code', () => { + assert.strictEqual( + tagsMarkdownPreview([ + { + name: 'example', + text: 'code();' + } + ], noopToResource), + '*@example* \n```\ncode();\n```' + ); + }); + + test('Should not render @example blocks as code as if they contain a codeblock', () => { + assert.strictEqual( + tagsMarkdownPreview([ + { + name: 'example', + text: 'Not code\n```\ncode();\n```' + } + ], noopToResource), + '*@example* \nNot code\n```\ncode();\n```' + ); + }); + + test('Should render @example blocks as code if they contain a ', () => { + assert.strictEqual( + tagsMarkdownPreview([ + { + name: 'example', + text: 'Not code\ncode();' + } + ], noopToResource), + '*@example* \nNot code\n```\ncode();\n```' + ); + }); + + test('Should not render @example blocks as code if they contain a and a codeblock', () => { + assert.strictEqual( + tagsMarkdownPreview([ + { + name: 'example', + text: 'Not code\n```\ncode();\n```' + } + ], noopToResource), + '*@example* \nNot code\n```\ncode();\n```' + ); + }); + test('Should render @linkcode symbol name as code', async () => { assert.strictEqual( plainWithLinks([ - { "text": "a ", "kind": "text" }, - { "text": "{@linkcode ", "kind": "link" }, + { text: 'a ', kind: 'text' }, + { text: '{@linkcode ', kind: 'link' }, { - "text": "dog", - "kind": "linkName", - "target": { - "file": "/path/file.ts", - "start": { "line": 7, "offset": 5 }, - "end": { "line": 7, "offset": 13 } + text: 'dog', + kind: 'linkName', + target: { + file: '/path/file.ts', + start: { line: 7, offset: 5 }, + end: { line: 7, offset: 13 } } } as SymbolDisplayPart, - { "text": "}", "kind": "link" }, - { "text": " b", "kind": "text" } + { text: '}', kind: 'link' }, + { text: ' b', kind: 'text' } ], noopToResource), 'a [`dog`](file:///path/file.ts#L7%2C5) b'); }); @@ -110,22 +158,21 @@ suite('typescript.previewer', () => { test('Should render @linkcode text as code', async () => { assert.strictEqual( plainWithLinks([ - { "text": "a ", "kind": "text" }, - { "text": "{@linkcode ", "kind": "link" }, + { text: 'a ', kind: 'text' }, + { text: '{@linkcode ', kind: 'link' }, { - "text": "dog", - "kind": "linkName", - "target": { - "file": "/path/file.ts", - "start": { "line": 7, "offset": 5 }, - "end": { "line": 7, "offset": 13 } + text: 'dog', + kind: 'linkName', + target: { + file: '/path/file.ts', + start: { line: 7, offset: 5 }, + end: { line: 7, offset: 13 } } } as SymbolDisplayPart, - { "text": "husky", "kind": "linkText" }, - { "text": "}", "kind": "link" }, - { "text": " b", "kind": "text" } + { text: 'husky', kind: 'linkText' }, + { text: '}', kind: 'link' }, + { text: ' b', kind: 'text' } ], noopToResource), 'a [`husky`](file:///path/file.ts#L7%2C5) b'); }); }); - diff --git a/extensions/typescript-language-features/src/utils/previewer.ts b/extensions/typescript-language-features/src/utils/previewer.ts index 78fd2a202d57f6..7ce0e7713daed9 100644 --- a/extensions/typescript-language-features/src/utils/previewer.ts +++ b/extensions/typescript-language-features/src/utils/previewer.ts @@ -49,6 +49,14 @@ function getTagBodyText( const text = convertLinkTags(tag.text, filePathConverter); switch (tag.name) { + case 'example': + // check for caption tags, fix for #79704 + const captionTagMatches = text.match(/(.*?)<\/caption>\s*(\r\n|\n)/); + if (captionTagMatches && captionTagMatches.index === 0) { + return captionTagMatches[1] + '\n' + makeCodeblock(text.substr(captionTagMatches[0].length)); + } else { + return makeCodeblock(text); + } case 'author': // fix obsucated email address, #80898 const emailMatch = text.match(/(.+)\s<([-.\w]+@[-.\w]+)>/); @@ -58,7 +66,6 @@ function getTagBodyText( } else { return `${emailMatch[1]} ${emailMatch[2]}`; } - case 'example': case 'default': return makeCodeblock(text); }