|
| 1 | +import * as assert from "assert"; |
| 2 | +import * as path from "path"; |
| 3 | +import * as vscode from "vscode"; |
| 4 | +import { DocumentSelector } from "vscode-languageclient"; |
| 5 | +import * as folding from "../../src/features/Folding"; |
| 6 | +import { MockLogger } from "../test_utils"; |
| 7 | + |
| 8 | +const fixturePath = path.join(__dirname, "..", "..", "..", "test", "fixtures"); |
| 9 | + |
| 10 | +function assertFoldingRegions(result, expected): void { |
| 11 | + assert.equal(result.length, expected.length); |
| 12 | + |
| 13 | + for (let i = 0; i < expected.length; i++) { |
| 14 | + const failMessage = `expected ${JSON.stringify(expected[i])}, actual ${JSON.stringify(result[i])}`; |
| 15 | + assert.equal(result[i].start, expected[i].start, failMessage); |
| 16 | + assert.equal(result[i].end, expected[i].end, failMessage); |
| 17 | + assert.equal(result[i].kind, expected[i].kind, failMessage); |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +suite("Features", () => { |
| 22 | + |
| 23 | + suite("Folding Provider", () => { |
| 24 | + const logger: MockLogger = new MockLogger(); |
| 25 | + const mockSelector: DocumentSelector = [ |
| 26 | + { language: "powershell", scheme: "file" }, |
| 27 | + ]; |
| 28 | + const psGrammar = (new folding.FoldingFeature(logger, mockSelector)).grammar(logger); |
| 29 | + const provider = (new folding.FoldingProvider(psGrammar)); |
| 30 | + |
| 31 | + test("Can detect the PowerShell Grammar", () => { |
| 32 | + assert.notEqual(psGrammar, null); |
| 33 | + }); |
| 34 | + |
| 35 | + test("Can detect all of the foldable regions in a document", async () => { |
| 36 | + // Integration test against the test fixture 'folding.ps1' that contains |
| 37 | + // all of the different types of folding available |
| 38 | + const uri = vscode.Uri.file(path.join(fixturePath, "folding.ps1")); |
| 39 | + const document = await vscode.workspace.openTextDocument(uri); |
| 40 | + const result = await provider.provideFoldingRanges(document, null, null); |
| 41 | + |
| 42 | + const expected = [ |
| 43 | + { start: 1, end: 6, kind: 1 }, |
| 44 | + { start: 7, end: 46, kind: 3 }, |
| 45 | + { start: 8, end: 13, kind: 1 }, |
| 46 | + { start: 14, end: 17, kind: 3 }, |
| 47 | + { start: 21, end: 23, kind: 1 }, |
| 48 | + { start: 25, end: 35, kind: 3 }, |
| 49 | + { start: 27, end: 31, kind: 3 }, |
| 50 | + { start: 37, end: 39, kind: 3 }, |
| 51 | + { start: 42, end: 45, kind: 3 }, |
| 52 | + ]; |
| 53 | + |
| 54 | + assertFoldingRegions(result, expected); |
| 55 | + }); |
| 56 | + }); |
| 57 | +}); |
0 commit comments