forked from neild3r/vscode-php-docblocker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.ts
54 lines (46 loc) · 1.81 KB
/
helpers.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
import {TextEditor, TextDocument, WorkspaceConfiguration, workspace, window, Position} from 'vscode';
import * as fs from 'fs';
import TypeUtil from '../src/util/TypeUtil';
import Config from '../src/util/config';
export default class Helper {
static fixturePath = __dirname + '/../../test/fixtures/';
public static loadFixture(fixture:string, callback: (editor:TextEditor, document:TextDocument) => any) {
workspace.openTextDocument(Helper.fixturePath + fixture).then(textDocument => {
window.showTextDocument(textDocument).then(textEditor => {
callback.call(this, textEditor, textDocument);
}, error => {
console.log(error);
});
}, error => {
console.log(error);
});
}
public static getFixturePositions(document:TextDocument):any
{
let testPositions:any = {};
for (let line = 0; line < document.lineCount; line++) {
let lineText = document.lineAt(line);
if (!lineText.isEmptyOrWhitespace) {
let pos = lineText.text.search(/\/\/\/\/=>/);
if (pos !== -1) {
let name = lineText.text.match(/\/\/\/\/=>\s*([a-z0-9-]+)\s*$/);
if (name !== null) {
testPositions[name[1]] = new Position(line, pos);
}
}
}
}
return testPositions;
}
public static getFixtureMap(fixture:string):any {
return JSON.parse(fs.readFileSync(Helper.fixturePath + fixture).toString());
}
public static getConfig():Config {
return Config.instance;
}
public static setConfig(overrides:any) {
Config.instance.load();
Config.instance.live = false;
Config.instance.override(overrides);
}
}