Skip to content

Commit

Permalink
Add tests for example tag rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit0 committed Sep 18, 2021
1 parent 8f9ee00 commit 0c486c8
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}`
Expand All @@ -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 {`,
Expand Down Expand Up @@ -111,4 +111,3 @@ suite('TypeScript References', () => {
function getCodeLenses(document: vscode.Uri): Thenable<readonly vscode.CodeLens[] | undefined> {
return vscode.commands.executeCommand<readonly vscode.CodeLens[]>('vscode.executeCodeLensProvider', document, 100);
}

Original file line number Diff line number Diff line change
Expand Up @@ -87,45 +87,92 @@ 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 <caption>', () => {
assert.strictEqual(
tagsMarkdownPreview([
{
name: 'example',
text: '<caption>Not code</caption>\ncode();'
}
], noopToResource),
'*@example* \nNot code\n```\ncode();\n```'
);
});

test('Should not render @example blocks as code if they contain a <caption> and a codeblock', () => {
assert.strictEqual(
tagsMarkdownPreview([
{
name: 'example',
text: '<caption>Not code</caption>\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');
});

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

Original file line number Diff line number Diff line change
Expand Up @@ -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>(.*?)<\/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]+)>/);
Expand All @@ -58,7 +66,6 @@ function getTagBodyText(
} else {
return `${emailMatch[1]} ${emailMatch[2]}`;
}
case 'example':
case 'default':
return makeCodeblock(text);
}
Expand Down

0 comments on commit 0c486c8

Please sign in to comment.