-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCleanTest.js
72 lines (51 loc) · 1.76 KB
/
CleanTest.js
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
const vscode = require('vscode');
module.exports = class CleanTest {
async clean() {
if (this.activeEditor() === undefined) {
return;
}
let activeDocument = this.activeDocument().uri;
if (activeDocument === undefined) {
return;
}
await this.cleanTest(activeDocument);
}
async cleanTest(activeDocument) {
let doc = await vscode.workspace.openTextDocument(activeDocument);
let startLine = 0;
let endLine = 0;
for (let line = 0; line < doc.lineCount; line++) {
let textLine = doc.lineAt(line).text.trim();
if (/^class .+/.test(textLine)) {
startLine = textLine.endsWith('TestCase') ? line + 2 : line + 1;
break;
}
}
for (let line = doc.lineCount - 1; line > 0; line--) {
let textLine = doc.lineAt(line).text.trim();
if (/}$/.test(textLine)) {
endLine = line;
break;
}
}
let snippet = '\tuse RefreshDatabase;\$1\n';
this.activeEditor().insertSnippet(
new vscode.SnippetString(snippet),
this.range(startLine, endLine)
);
console.log(startLine);
console.log(endLine);
}
range(startLine, endLine) {
return new vscode.Range(new vscode.Position(startLine, 0), new vscode.Position(endLine, 0))
}
activeEditor() {
return vscode.window.activeTextEditor;
}
activeDocument() {
return this.activeEditor().document;
}
config(key) {
return vscode.workspace.getConfiguration('phpTestCreator').get(key);
}
}