Path: blob/main/extensions/emmet/src/test/incrementDecrement.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 { Selection } from 'vscode';8import { withRandomFileEditor, closeAllEditors } from './testUtils';9import { incrementDecrement as incrementDecrementImpl } from '../incrementDecrement';1011function incrementDecrement(delta: number): Thenable<boolean> {12const result = incrementDecrementImpl(delta);13assert.ok(result);14return result!;15}1617suite('Tests for Increment/Decrement Emmet Commands', () => {18teardown(closeAllEditors);1920const contents = `21hello 123.43 there22hello 999.9 there23hello 100 there24`;2526test('incrementNumberByOne', function (): any {27return withRandomFileEditor(contents, 'txt', async (editor, doc) => {28editor.selections = [new Selection(1, 7, 1, 10), new Selection(2, 7, 2, 10)];29await incrementDecrement(1);30assert.strictEqual(doc.getText(), contents.replace('123', '124').replace('999', '1000'));31return Promise.resolve();32});33});3435test('incrementNumberByTen', function (): any {36return withRandomFileEditor(contents, 'txt', async (editor, doc) => {37editor.selections = [new Selection(1, 7, 1, 10), new Selection(2, 7, 2, 10)];38await incrementDecrement(10);39assert.strictEqual(doc.getText(), contents.replace('123', '133').replace('999', '1009'));40return Promise.resolve();41});42});4344test('incrementNumberByOneTenth', function (): any {45return withRandomFileEditor(contents, 'txt', async (editor, doc) => {46editor.selections = [new Selection(1, 7, 1, 13), new Selection(2, 7, 2, 12)];47await incrementDecrement(0.1);48assert.strictEqual(doc.getText(), contents.replace('123.43', '123.53').replace('999.9', '1000'));49return Promise.resolve();50});51});5253test('decrementNumberByOne', function (): any {54return withRandomFileEditor(contents, 'txt', async (editor, doc) => {55editor.selections = [new Selection(1, 7, 1, 10), new Selection(3, 7, 3, 10)];56await incrementDecrement(-1);57assert.strictEqual(doc.getText(), contents.replace('123', '122').replace('100', '99'));58return Promise.resolve();59});60});6162test('decrementNumberByTen', function (): any {63return withRandomFileEditor(contents, 'txt', async (editor, doc) => {64editor.selections = [new Selection(1, 7, 1, 10), new Selection(3, 7, 3, 10)];65await incrementDecrement(-10);66assert.strictEqual(doc.getText(), contents.replace('123', '113').replace('100', '90'));67return Promise.resolve();68});69});7071test('decrementNumberByOneTenth', function (): any {72return withRandomFileEditor(contents, 'txt', async (editor, doc) => {73editor.selections = [new Selection(1, 7, 1, 13), new Selection(3, 7, 3, 10)];74await incrementDecrement(-0.1);75assert.strictEqual(doc.getText(), contents.replace('123.43', '123.33').replace('100', '99.9'));76return Promise.resolve();77});78});79});808182