Path: blob/main/extensions/emmet/src/test/evaluateMathExpression.test.ts
4774 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 'mocha';6import * as assert from 'assert';7import { Position, Selection } from 'vscode';8import { withRandomFileEditor, closeAllEditors } from './testUtils';9import { evaluateMathExpression } from '../evaluateMathExpression';1011suite('Tests for Evaluate Math Expression', () => {12teardown(closeAllEditors);1314function testEvaluateMathExpression(fileContents: string, selection: [number, number] | number, expectedFileContents: string): Thenable<boolean> {15return withRandomFileEditor(fileContents, 'html', async (editor, _doc) => {16const selectionToUse = typeof selection === 'number' ?17new Selection(new Position(0, selection), new Position(0, selection)) :18new Selection(new Position(0, selection[0]), new Position(0, selection[1]));19editor.selection = selectionToUse;2021await evaluateMathExpression();2223assert.strictEqual(editor.document.getText(), expectedFileContents);24return Promise.resolve();25});26}2728test('Selected sanity check', () => {29return testEvaluateMathExpression('1 + 2', [0, 5], '3');30});3132test('Selected with surrounding text', () => {33return testEvaluateMathExpression('test1 + 2test', [4, 9], 'test3test');34});3536test('Selected with number not part of selection', () => {37return testEvaluateMathExpression('test3 1+2', [6, 9], 'test3 3');38});3940test('Non-selected sanity check', () => {41return testEvaluateMathExpression('1 + 2', 5, '3');42});4344test('Non-selected midway', () => {45return testEvaluateMathExpression('1 + 2', 1, '1 + 2');46});4748test('Non-selected with surrounding text', () => {49return testEvaluateMathExpression('test1 + 3test', 9, 'test4test');50});51});525354