Path: blob/main/src/vs/workbench/contrib/emmet/test/browser/emmetAction.test.ts
3296 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*--------------------------------------------------------------------------------------------*/45import { IGrammarContributions, EmmetEditorAction } from '../../browser/emmetActions.js';6import { withTestCodeEditor } from '../../../../../editor/test/browser/testCodeEditor.js';7import assert from 'assert';8import { DisposableStore } from '../../../../../base/common/lifecycle.js';9import { ILanguageService } from '../../../../../editor/common/languages/language.js';10import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';1112class MockGrammarContributions implements IGrammarContributions {13private scopeName: string;1415constructor(scopeName: string) {16this.scopeName = scopeName;17}1819public getGrammar(mode: string): string {20return this.scopeName;21}22}2324suite('Emmet', () => {25test('Get language mode and parent mode for emmet', () => {26withTestCodeEditor([], {}, (editor, viewModel, instantiationService) => {27const languageService = instantiationService.get(ILanguageService);2829const disposables = new DisposableStore();30disposables.add(languageService.registerLanguage({ id: 'markdown' }));31disposables.add(languageService.registerLanguage({ id: 'handlebars' }));32disposables.add(languageService.registerLanguage({ id: 'nunjucks' }));33disposables.add(languageService.registerLanguage({ id: 'laravel-blade' }));3435function testIsEnabled(mode: string, scopeName: string, expectedLanguage?: string, expectedParentLanguage?: string) {36const model = editor.getModel();37if (!model) {38assert.fail('Editor model not found');39}4041model.setLanguage(mode);42const langOutput = EmmetEditorAction.getLanguage(editor, new MockGrammarContributions(scopeName));43if (!langOutput) {44assert.fail('langOutput not found');45}4647assert.strictEqual(langOutput.language, expectedLanguage);48assert.strictEqual(langOutput.parentMode, expectedParentLanguage);49}5051// syntaxes mapped using the scope name of the grammar52testIsEnabled('markdown', 'text.html.markdown', 'markdown', 'html');53testIsEnabled('handlebars', 'text.html.handlebars', 'handlebars', 'html');54testIsEnabled('nunjucks', 'text.html.nunjucks', 'nunjucks', 'html');55testIsEnabled('laravel-blade', 'text.html.php.laravel-blade', 'laravel-blade', 'html');5657// languages that have different Language Id and scopeName58// testIsEnabled('razor', 'text.html.cshtml', 'razor', 'html');59// testIsEnabled('HTML (Eex)', 'text.html.elixir', 'boo', 'html');6061disposables.dispose();6263});64});6566ensureNoDisposablesAreLeakedInTestSuite();67});686970