Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/emmet/src/test/incrementDecrement.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 { Selection } from 'vscode';
9
import { withRandomFileEditor, closeAllEditors } from './testUtils';
10
import { incrementDecrement as incrementDecrementImpl } from '../incrementDecrement';
11
12
function incrementDecrement(delta: number): Thenable<boolean> {
13
const result = incrementDecrementImpl(delta);
14
assert.ok(result);
15
return result!;
16
}
17
18
suite('Tests for Increment/Decrement Emmet Commands', () => {
19
teardown(closeAllEditors);
20
21
const contents = `
22
hello 123.43 there
23
hello 999.9 there
24
hello 100 there
25
`;
26
27
test('incrementNumberByOne', function (): any {
28
return withRandomFileEditor(contents, 'txt', async (editor, doc) => {
29
editor.selections = [new Selection(1, 7, 1, 10), new Selection(2, 7, 2, 10)];
30
await incrementDecrement(1);
31
assert.strictEqual(doc.getText(), contents.replace('123', '124').replace('999', '1000'));
32
return Promise.resolve();
33
});
34
});
35
36
test('incrementNumberByTen', function (): any {
37
return withRandomFileEditor(contents, 'txt', async (editor, doc) => {
38
editor.selections = [new Selection(1, 7, 1, 10), new Selection(2, 7, 2, 10)];
39
await incrementDecrement(10);
40
assert.strictEqual(doc.getText(), contents.replace('123', '133').replace('999', '1009'));
41
return Promise.resolve();
42
});
43
});
44
45
test('incrementNumberByOneTenth', function (): any {
46
return withRandomFileEditor(contents, 'txt', async (editor, doc) => {
47
editor.selections = [new Selection(1, 7, 1, 13), new Selection(2, 7, 2, 12)];
48
await incrementDecrement(0.1);
49
assert.strictEqual(doc.getText(), contents.replace('123.43', '123.53').replace('999.9', '1000'));
50
return Promise.resolve();
51
});
52
});
53
54
test('decrementNumberByOne', function (): any {
55
return withRandomFileEditor(contents, 'txt', async (editor, doc) => {
56
editor.selections = [new Selection(1, 7, 1, 10), new Selection(3, 7, 3, 10)];
57
await incrementDecrement(-1);
58
assert.strictEqual(doc.getText(), contents.replace('123', '122').replace('100', '99'));
59
return Promise.resolve();
60
});
61
});
62
63
test('decrementNumberByTen', function (): any {
64
return withRandomFileEditor(contents, 'txt', async (editor, doc) => {
65
editor.selections = [new Selection(1, 7, 1, 10), new Selection(3, 7, 3, 10)];
66
await incrementDecrement(-10);
67
assert.strictEqual(doc.getText(), contents.replace('123', '113').replace('100', '90'));
68
return Promise.resolve();
69
});
70
});
71
72
test('decrementNumberByOneTenth', function (): any {
73
return withRandomFileEditor(contents, 'txt', async (editor, doc) => {
74
editor.selections = [new Selection(1, 7, 1, 13), new Selection(3, 7, 3, 10)];
75
await incrementDecrement(-0.1);
76
assert.strictEqual(doc.getText(), contents.replace('123.43', '123.33').replace('100', '99.9'));
77
return Promise.resolve();
78
});
79
});
80
});
81
82