mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-19 01:25:36 -05:00
* Merge from vscode 504f934659740e9d41501cad9f162b54d7745ad9 * delete unused folders * distro * Bump build node version * update chokidar * FIx hygiene errors * distro * Fix extension lint issues * Remove strict-vscode * Add copyright header exemptions * Bump vscode-extension-telemetry to fix webpacking issue with zone.js * distro * Fix failing tests (revert marked.js back to current one until we decide to update) * Skip searchmodel test * Fix mac build * temp debug script loading * Try disabling coverage * log error too * Revert "log error too" This reverts commit af0183e5d4ab458fdf44b88fbfab9908d090526f. * Revert "temp debug script loading" This reverts commit 3d687d541c76db2c5b55626c78ae448d3c25089c. * Add comments explaining coverage disabling * Fix ansi_up loading issue * Merge latest from ads * Use newer option * Fix compile * add debug logging warn * Always log stack * log more * undo debug * Update to use correct base path (+cleanup) * distro * fix compile errors * Remove strict-vscode * Fix sql editors not showing * Show db dropdown input & fix styling * Fix more info in gallery * Fix gallery asset requests * Delete unused workflow * Fix tapable resolutions for smoke test compile error * Fix smoke compile * Disable crash reporting * Disable interactive Co-authored-by: ADS Merger <karlb@microsoft.com>
198 lines
5.1 KiB
TypeScript
198 lines
5.1 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import * as assert from 'assert';
|
|
import 'mocha';
|
|
import * as vscode from 'vscode';
|
|
import MarkdownFoldingProvider from '../features/foldingProvider';
|
|
import { createNewMarkdownEngine } from './engine';
|
|
import { InMemoryDocument } from './inMemoryDocument';
|
|
|
|
|
|
const testFileName = vscode.Uri.file('test.md');
|
|
|
|
suite('markdown.FoldingProvider', () => {
|
|
test('Should not return anything for empty document', async () => {
|
|
const folds = await getFoldsForDocument(``);
|
|
assert.strictEqual(folds.length, 0);
|
|
});
|
|
|
|
test('Should not return anything for document without headers', async () => {
|
|
const folds = await getFoldsForDocument(`a
|
|
**b** afas
|
|
a#b
|
|
a`);
|
|
assert.strictEqual(folds.length, 0);
|
|
});
|
|
|
|
test('Should fold from header to end of document', async () => {
|
|
const folds = await getFoldsForDocument(`a
|
|
# b
|
|
c
|
|
d`);
|
|
assert.strictEqual(folds.length, 1);
|
|
const firstFold = folds[0];
|
|
assert.strictEqual(firstFold.start, 1);
|
|
assert.strictEqual(firstFold.end, 3);
|
|
});
|
|
|
|
test('Should leave single newline before next header', async () => {
|
|
const folds = await getFoldsForDocument(`
|
|
# a
|
|
x
|
|
|
|
# b
|
|
y`);
|
|
assert.strictEqual(folds.length, 2);
|
|
const firstFold = folds[0];
|
|
assert.strictEqual(firstFold.start, 1);
|
|
assert.strictEqual(firstFold.end, 3);
|
|
});
|
|
|
|
test('Should collapse multuple newlines to single newline before next header', async () => {
|
|
const folds = await getFoldsForDocument(`
|
|
# a
|
|
x
|
|
|
|
|
|
|
|
# b
|
|
y`);
|
|
assert.strictEqual(folds.length, 2);
|
|
const firstFold = folds[0];
|
|
assert.strictEqual(firstFold.start, 1);
|
|
assert.strictEqual(firstFold.end, 5);
|
|
});
|
|
|
|
test('Should not collapse if there is no newline before next header', async () => {
|
|
const folds = await getFoldsForDocument(`
|
|
# a
|
|
x
|
|
# b
|
|
y`);
|
|
assert.strictEqual(folds.length, 2);
|
|
const firstFold = folds[0];
|
|
assert.strictEqual(firstFold.start, 1);
|
|
assert.strictEqual(firstFold.end, 2);
|
|
});
|
|
|
|
test('Should fold nested <!-- #region --> markers', async () => {
|
|
const folds = await getFoldsForDocument(`a
|
|
<!-- #region -->
|
|
b
|
|
<!-- #region hello!-->
|
|
b.a
|
|
<!-- #endregion -->
|
|
b
|
|
<!-- #region: foo! -->
|
|
b.b
|
|
<!-- #endregion: foo -->
|
|
b
|
|
<!-- #endregion -->
|
|
a`);
|
|
assert.strictEqual(folds.length, 3);
|
|
const [outer, first, second] = folds.sort((a, b) => a.start - b.start);
|
|
|
|
assert.strictEqual(outer.start, 1);
|
|
assert.strictEqual(outer.end, 11);
|
|
assert.strictEqual(first.start, 3);
|
|
assert.strictEqual(first.end, 5);
|
|
assert.strictEqual(second.start, 7);
|
|
assert.strictEqual(second.end, 9);
|
|
});
|
|
|
|
test('Should fold from list to end of document', async () => {
|
|
const folds = await getFoldsForDocument(`a
|
|
- b
|
|
c
|
|
d`);
|
|
assert.strictEqual(folds.length, 1);
|
|
const firstFold = folds[0];
|
|
assert.strictEqual(firstFold.start, 1);
|
|
assert.strictEqual(firstFold.end, 3);
|
|
});
|
|
|
|
test('lists folds should span multiple lines of content', async () => {
|
|
const folds = await getFoldsForDocument(`a
|
|
- This list item\n spans multiple\n lines.`);
|
|
assert.strictEqual(folds.length, 1);
|
|
const firstFold = folds[0];
|
|
assert.strictEqual(firstFold.start, 1);
|
|
assert.strictEqual(firstFold.end, 3);
|
|
});
|
|
|
|
test('List should leave single blankline before new element', async () => {
|
|
const folds = await getFoldsForDocument(`- a
|
|
a
|
|
|
|
|
|
b`);
|
|
assert.strictEqual(folds.length, 1);
|
|
const firstFold = folds[0];
|
|
assert.strictEqual(firstFold.start, 0);
|
|
assert.strictEqual(firstFold.end, 3);
|
|
});
|
|
|
|
test('Should fold fenced code blocks', async () => {
|
|
const folds = await getFoldsForDocument(`~~~ts
|
|
a
|
|
~~~
|
|
b`);
|
|
assert.strictEqual(folds.length, 1);
|
|
const firstFold = folds[0];
|
|
assert.strictEqual(firstFold.start, 0);
|
|
assert.strictEqual(firstFold.end, 2);
|
|
});
|
|
|
|
test('Should fold fenced code blocks with yaml front matter', async () => {
|
|
const folds = await getFoldsForDocument(`---
|
|
title: bla
|
|
---
|
|
|
|
~~~ts
|
|
a
|
|
~~~
|
|
|
|
a
|
|
a
|
|
b
|
|
a`);
|
|
assert.strictEqual(folds.length, 1);
|
|
const firstFold = folds[0];
|
|
assert.strictEqual(firstFold.start, 4);
|
|
assert.strictEqual(firstFold.end, 6);
|
|
});
|
|
|
|
test('Should fold html blocks', async () => {
|
|
const folds = await getFoldsForDocument(`x
|
|
<div>
|
|
fa
|
|
</div>`);
|
|
assert.strictEqual(folds.length, 1);
|
|
const firstFold = folds[0];
|
|
assert.strictEqual(firstFold.start, 1);
|
|
assert.strictEqual(firstFold.end, 3);
|
|
});
|
|
|
|
test('Should fold html block comments', async () => {
|
|
const folds = await getFoldsForDocument(`x
|
|
<!--
|
|
fa
|
|
-->`);
|
|
assert.strictEqual(folds.length, 1);
|
|
const firstFold = folds[0];
|
|
assert.strictEqual(firstFold.start, 1);
|
|
assert.strictEqual(firstFold.end, 3);
|
|
assert.strictEqual(firstFold.kind, vscode.FoldingRangeKind.Comment);
|
|
});
|
|
});
|
|
|
|
|
|
async function getFoldsForDocument(contents: string) {
|
|
const doc = new InMemoryDocument(testFileName, contents);
|
|
const provider = new MarkdownFoldingProvider(createNewMarkdownEngine());
|
|
return await provider.provideFoldingRanges(doc, {}, new vscode.CancellationTokenSource().token);
|
|
}
|