Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/emmet/src/test/evaluateMathExpression.test.ts
4774 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 'mocha';
7
import * as assert from 'assert';
8
import { Position, Selection } from 'vscode';
9
import { withRandomFileEditor, closeAllEditors } from './testUtils';
10
import { evaluateMathExpression } from '../evaluateMathExpression';
11
12
suite('Tests for Evaluate Math Expression', () => {
13
teardown(closeAllEditors);
14
15
function testEvaluateMathExpression(fileContents: string, selection: [number, number] | number, expectedFileContents: string): Thenable<boolean> {
16
return withRandomFileEditor(fileContents, 'html', async (editor, _doc) => {
17
const selectionToUse = typeof selection === 'number' ?
18
new Selection(new Position(0, selection), new Position(0, selection)) :
19
new Selection(new Position(0, selection[0]), new Position(0, selection[1]));
20
editor.selection = selectionToUse;
21
22
await evaluateMathExpression();
23
24
assert.strictEqual(editor.document.getText(), expectedFileContents);
25
return Promise.resolve();
26
});
27
}
28
29
test('Selected sanity check', () => {
30
return testEvaluateMathExpression('1 + 2', [0, 5], '3');
31
});
32
33
test('Selected with surrounding text', () => {
34
return testEvaluateMathExpression('test1 + 2test', [4, 9], 'test3test');
35
});
36
37
test('Selected with number not part of selection', () => {
38
return testEvaluateMathExpression('test3 1+2', [6, 9], 'test3 3');
39
});
40
41
test('Non-selected sanity check', () => {
42
return testEvaluateMathExpression('1 + 2', 5, '3');
43
});
44
45
test('Non-selected midway', () => {
46
return testEvaluateMathExpression('1 + 2', 1, '1 + 2');
47
});
48
49
test('Non-selected with surrounding text', () => {
50
return testEvaluateMathExpression('test1 + 3test', 9, 'test4test');
51
});
52
});
53
54