forked from neild3r/vscode-php-docblocker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTypeUtil.test.ts
77 lines (65 loc) · 2.83 KB
/
TypeUtil.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
import * as assert from 'assert';
import TypeUtil from "../src/util/TypeUtil";
import { window, workspace, TextDocument, Position, TextEditor } from 'vscode';
import Helper from './helpers';
import FunctionBlock from '../src/block/function';
suite("TypeUtil tests: ", () => {
let editor:TextEditor;
let head:string;
suiteSetup(function(done) {
workspace.openTextDocument(Helper.fixturePath+'namespace.php').then(doc => {
window.showTextDocument(doc).then(textEditor => {
editor = textEditor;
let block = new FunctionBlock(new Position(0, 0), editor);
head = block.getClassHead();
done();
}, error => {
console.log(error);
})
}, error => {
console.log(error);
});
});
test("Ensure typehint is not mismatched", () => {
let type = new TypeUtil;
Helper.setConfig({qualifyClassNames: true});
assert.equal(type.getFullyQualifiedType('Example', head), 'Example');
});
test("Fully qualify typehint from namespace", () => {
let type = new TypeUtil;
Helper.setConfig({qualifyClassNames: true});
assert.equal(type.getFullyQualifiedType('FilterInterface', head), '\\App\\Test\\Model\\FilterInterface');
});
test("Fully qualify typehint from namespace with prefix", () => {
let type = new TypeUtil;
Helper.setConfig({qualifyClassNames: true});
assert.equal(type.getFullyQualifiedType('StreamHandler', head), '\\Monolog\\Handler\\StreamHandler');
});
test("Fully qualify typehint from namespace use with alias", () => {
let type = new TypeUtil;
Helper.setConfig({qualifyClassNames: true});
assert.equal(type.getFullyQualifiedType('BaseExample', head), '\\App\\Test\\Model\\Example');
});
test("With default settings the integer type formatted is integer", () => {
let type = new TypeUtil;
assert.equal(type.getFormattedTypeByName('int'), 'integer');
});
test("With default settings the boolean type formatted is boolean", () => {
let type = new TypeUtil;
assert.equal(type.getFormattedTypeByName('bool'), 'boolean');
});
test('With special settings the integer type formatted is int', () => {
let type = new TypeUtil;
Helper.setConfig({useShortNames: true});
assert.equal(type.getFormattedTypeByName('int'), 'int');
})
test('With special settings the boolean type formatted is bool', () => {
let type = new TypeUtil;
Helper.setConfig({useShortNames: true});
assert.equal(type.getFormattedTypeByName('bool'), 'bool');
})
test("Unknown types won't be touched", () => {
let type = new TypeUtil;
assert.equal(type.getFormattedTypeByName('helloWorld'), 'helloWorld');
});
});