Path: blob/main/src/vs/base/test/common/htmlContent.test.ts
13397 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/4import assert from 'assert';5import { appendEscapedMarkdownInlineCode, escapeMarkdownLinkLabel } from '../../common/htmlContent.js';6import { ensureNoDisposablesAreLeakedInTestSuite } from './utils.js';78suite('htmlContent', () => {9ensureNoDisposablesAreLeakedInTestSuite();1011suite('appendEscapedMarkdownInlineCode', () => {12test('wraps plain text in single backticks', () => {13assert.strictEqual(appendEscapedMarkdownInlineCode('hello'), '`hello`');14assert.strictEqual(appendEscapedMarkdownInlineCode(''), '``');15assert.strictEqual(appendEscapedMarkdownInlineCode('foo bar'), '`foo bar`');16});1718test('chooses a fence longer than any backtick run in the content', () => {19assert.strictEqual(appendEscapedMarkdownInlineCode('a`b'), '``a`b``');20assert.strictEqual(appendEscapedMarkdownInlineCode('a``b'), '```a``b```');21assert.strictEqual(appendEscapedMarkdownInlineCode('a```b```c'), '````a```b```c````');22});2324test('pads with spaces when the content begins or ends with a backtick', () => {25assert.strictEqual(appendEscapedMarkdownInlineCode('`'), '`` ` ``');26assert.strictEqual(appendEscapedMarkdownInlineCode('`hello'), '`` `hello ``');27assert.strictEqual(appendEscapedMarkdownInlineCode('hello`'), '`` hello` ``');28assert.strictEqual(appendEscapedMarkdownInlineCode('`a`b`'), '`` `a`b` ``');29});3031test('does not pad when backticks are only in the interior', () => {32assert.strictEqual(appendEscapedMarkdownInlineCode('a`b'), '``a`b``');33});3435test('handles content composed entirely of backticks', () => {36assert.strictEqual(appendEscapedMarkdownInlineCode('``'), '``` `` ```');37});38});3940suite('escapeMarkdownLinkLabel', () => {41test('passes plain text through unchanged', () => {42assert.strictEqual(escapeMarkdownLinkLabel('hello'), 'hello');43assert.strictEqual(escapeMarkdownLinkLabel(''), '');44assert.strictEqual(escapeMarkdownLinkLabel('heap-snapshot-analysis'), 'heap-snapshot-analysis');45assert.strictEqual(escapeMarkdownLinkLabel('foo.bar_baz'), 'foo.bar_baz');46});4748test('escapes only `\\` and `]`', () => {49assert.strictEqual(escapeMarkdownLinkLabel('a]b'), 'a\\]b');50assert.strictEqual(escapeMarkdownLinkLabel('a\\b'), 'a\\\\b');51assert.strictEqual(escapeMarkdownLinkLabel(']]'), '\\]\\]');52});5354test('does not escape characters that are safe in link text', () => {55// these would be escaped by escapeMarkdownSyntaxTokens but must56// pass through here since they render literally inside `[...]`.57assert.strictEqual(escapeMarkdownLinkLabel('a*b_c#d-e.f!g~h+i(j)k{l}m'), 'a*b_c#d-e.f!g~h+i(j)k{l}m');58});59});60});616263