/
tabconverter.test.ts
102 lines (86 loc) · 2.86 KB
/
tabconverter.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//
// Note: This example test is leveraging the Mocha test framework.
// Please refer to their documentation on https://mochajs.org/ for help.
//
// The module 'assert' provides assertion methods from node
import * as assert from 'assert';
// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import {window, Selection, Position} from 'vscode';
import TabConverter from '../src/tabconverter';
suite("Tabconverter.convertTabToSpace Tests", () => {
// Defines a Mocha unit test
test("convertTabToSpace", () => {
// Arrange
let editor = window.activeTextEditor,
selection = editor.selections,
tabconverter = new TabConverter(),
startPos = new Position(0, 0),
endPos = new Position(0, 1);
editor.edit(edit => {
edit.insert(startPos, '\t');
editor.selection = new Selection(startPos, endPos);
console.log(editor.document.getText().match(/t/));
}).then(bool => {
// Act
tabconverter.convertTabToSpace();
// this test isn't beautifull. Becouse this is Environment-dependent.
// I don't have good idea now
setTimeout(function() {
// Assert
let text = editor.document.getText();
assert.equal(text.search(/\t/), -1);
}, 500);
});
});
});
suite("Tabconverter.convertSpaceToTab Tests", () => {
// Defines a Mocha unit test
test("convertSpaceToTab", () => {
// Arrange
let editor = window.activeTextEditor,
selection = editor.selections,
tabconverter = new TabConverter(),
startPos = new Position(0, 0),
endPos = new Position(0, 1),
tabSize = window.activeTextEditor.options.tabSize,
spaces = "";
editor.edit(edit => {
for (let i = 0; i < tabSize ; i++) {
spaces += " ";
}
edit.insert(startPos, spaces);
editor.selection = new Selection(startPos, endPos);
console.log(editor.document.getText().match(spaces));
}).then(bool => {
// Act
tabconverter.convertSpaceToTab();
// this test isn't beautifull. Becouse this is Environment-dependent.
// I don't have good idea now
setTimeout(function() {
// Assert
let text = editor.document.getText();
let regSpaces = new RegExp(spaces, "g");
assert.equal(text.search(regSpaces), -1);
}, 1000);
});
});
});
suite("Tabconverter.toggleTabSpace Tests", () => {
// Defines a Mocha unit test
test("toggle", () => {
// Arrange
let options = window.activeTextEditor.options,
defaultInsertSpaces = options.insertSpaces,
defaultTabSize = options.tabSize,
tabconverter = new TabConverter();
// Act
tabconverter.toggleTabSpace();
// Assert
let afterOptions = window.activeTextEditor.options,
afterTabSize = afterOptions.tabSize,
afterInsertSpaces = afterOptions.insertSpaces;
assert.notEqual(defaultInsertSpaces, afterInsertSpaces);
assert.equal(defaultTabSize, afterTabSize);
});
});