|
| 1 | +import { createContextMapperDslServices } from '../../src/language/ContextMapperDslModule.js' |
| 2 | +import { FoldingRangeProvider } from 'langium/lsp' |
| 3 | +import { clearDocuments, parseHelper } from 'langium/test' |
| 4 | +import { ContextMappingModel } from '../../src/language/generated/ast.js' |
| 5 | +import { EmptyFileSystem, LangiumDocument } from 'langium' |
| 6 | +import { afterEach, beforeAll, describe, expect, test } from 'vitest' |
| 7 | +import { parseValidInput } from '../ParsingTestHelper.js' |
| 8 | +import { FoldingRangeParams } from 'vscode-languageserver' |
| 9 | + |
| 10 | +let services: ReturnType<typeof createContextMapperDslServices> |
| 11 | +let foldingRangeProvider: FoldingRangeProvider |
| 12 | +let parse: ReturnType<typeof parseHelper<ContextMappingModel>> |
| 13 | +let document: LangiumDocument<ContextMappingModel> | undefined |
| 14 | + |
| 15 | +beforeAll(async () => { |
| 16 | + services = createContextMapperDslServices(EmptyFileSystem) |
| 17 | + foldingRangeProvider = services.ContextMapperDsl.lsp.FoldingRangeProvider! |
| 18 | + parse = parseHelper<ContextMappingModel>(services.ContextMapperDsl) |
| 19 | +}) |
| 20 | + |
| 21 | +afterEach(async () => { |
| 22 | + document && await clearDocuments(services.shared, [document]) |
| 23 | +}) |
| 24 | + |
| 25 | +describe('Comment block folding tests', () => { |
| 26 | + test('check folding range of comment block', async () => { |
| 27 | + document = await parseValidInput(parse, ` |
| 28 | + /* |
| 29 | + This is a comment block |
| 30 | + */ |
| 31 | + BoundedContext TestContext |
| 32 | + `) |
| 33 | + |
| 34 | + const params = createFoldingRangeParams(document) |
| 35 | + const foldingRanges = await foldingRangeProvider.getFoldingRanges(document, params) |
| 36 | + expect(foldingRanges).toHaveLength(1) |
| 37 | + expect(foldingRanges[0].startLine).toEqual(1) |
| 38 | + expect(foldingRanges[0].startCharacter).toEqual(8) |
| 39 | + expect(foldingRanges[0].endLine).toEqual(3) |
| 40 | + expect(foldingRanges[0].endCharacter).toEqual(0) |
| 41 | + }) |
| 42 | + |
| 43 | + test('check folding range of multiline comment', async () => { |
| 44 | + document = await parseValidInput(parse, ` |
| 45 | + BoundedContext TestContext { |
| 46 | + /* This is a |
| 47 | + looooonger |
| 48 | + multiline comment |
| 49 | + */ |
| 50 | + Aggregate TestAggregate |
| 51 | + } |
| 52 | + `) |
| 53 | + |
| 54 | + const params = createFoldingRangeParams(document) |
| 55 | + const foldingRanges = await foldingRangeProvider.getFoldingRanges(document, params) |
| 56 | + expect(foldingRanges).toHaveLength(2) |
| 57 | + expect(foldingRanges[1].startLine).toEqual(2) |
| 58 | + expect(foldingRanges[1].startCharacter).toEqual(20) |
| 59 | + expect(foldingRanges[1].endLine).toEqual(5) |
| 60 | + expect(foldingRanges[1].endCharacter).toEqual(0) |
| 61 | + }) |
| 62 | + |
| 63 | + test('check folding range of single-line comment', async () => { |
| 64 | + document = await parseValidInput(parse, ` |
| 65 | + // This is a single-line comment |
| 66 | + BoundedContext TestContext |
| 67 | + `) |
| 68 | + |
| 69 | + const params = createFoldingRangeParams(document) |
| 70 | + const foldingRanges = await foldingRangeProvider.getFoldingRanges(document, params) |
| 71 | + expect(foldingRanges).toHaveLength(0) |
| 72 | + }) |
| 73 | + |
| 74 | + test('check folding range of single line comment block', async () => { |
| 75 | + document = await parseValidInput(parse, ` |
| 76 | + /* This is a single-line comment */ |
| 77 | + BoundedContext TestContext |
| 78 | + `) |
| 79 | + |
| 80 | + const params = createFoldingRangeParams(document) |
| 81 | + const foldingRanges = await foldingRangeProvider.getFoldingRanges(document, params) |
| 82 | + expect(foldingRanges).toHaveLength(0) |
| 83 | + }) |
| 84 | +}) |
| 85 | + |
| 86 | +function createFoldingRangeParams (document: LangiumDocument<ContextMappingModel>): FoldingRangeParams { |
| 87 | + return { |
| 88 | + textDocument: { |
| 89 | + uri: document.uri.path |
| 90 | + } |
| 91 | + } |
| 92 | +} |
0 commit comments