Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/emmet/test/browser/emmetAction.test.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { IGrammarContributions, EmmetEditorAction } from '../../browser/emmetActions.js';
7
import { withTestCodeEditor } from '../../../../../editor/test/browser/testCodeEditor.js';
8
import assert from 'assert';
9
import { DisposableStore } from '../../../../../base/common/lifecycle.js';
10
import { ILanguageService } from '../../../../../editor/common/languages/language.js';
11
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';
12
13
class MockGrammarContributions implements IGrammarContributions {
14
private scopeName: string;
15
16
constructor(scopeName: string) {
17
this.scopeName = scopeName;
18
}
19
20
public getGrammar(mode: string): string {
21
return this.scopeName;
22
}
23
}
24
25
suite('Emmet', () => {
26
test('Get language mode and parent mode for emmet', () => {
27
withTestCodeEditor([], {}, (editor, viewModel, instantiationService) => {
28
const languageService = instantiationService.get(ILanguageService);
29
30
const disposables = new DisposableStore();
31
disposables.add(languageService.registerLanguage({ id: 'markdown' }));
32
disposables.add(languageService.registerLanguage({ id: 'handlebars' }));
33
disposables.add(languageService.registerLanguage({ id: 'nunjucks' }));
34
disposables.add(languageService.registerLanguage({ id: 'laravel-blade' }));
35
36
function testIsEnabled(mode: string, scopeName: string, expectedLanguage?: string, expectedParentLanguage?: string) {
37
const model = editor.getModel();
38
if (!model) {
39
assert.fail('Editor model not found');
40
}
41
42
model.setLanguage(mode);
43
const langOutput = EmmetEditorAction.getLanguage(editor, new MockGrammarContributions(scopeName));
44
if (!langOutput) {
45
assert.fail('langOutput not found');
46
}
47
48
assert.strictEqual(langOutput.language, expectedLanguage);
49
assert.strictEqual(langOutput.parentMode, expectedParentLanguage);
50
}
51
52
// syntaxes mapped using the scope name of the grammar
53
testIsEnabled('markdown', 'text.html.markdown', 'markdown', 'html');
54
testIsEnabled('handlebars', 'text.html.handlebars', 'handlebars', 'html');
55
testIsEnabled('nunjucks', 'text.html.nunjucks', 'nunjucks', 'html');
56
testIsEnabled('laravel-blade', 'text.html.php.laravel-blade', 'laravel-blade', 'html');
57
58
// languages that have different Language Id and scopeName
59
// testIsEnabled('razor', 'text.html.cshtml', 'razor', 'html');
60
// testIsEnabled('HTML (Eex)', 'text.html.elixir', 'boo', 'html');
61
62
disposables.dispose();
63
64
});
65
});
66
67
ensureNoDisposablesAreLeakedInTestSuite();
68
});
69
70