Skip to content

Commit 61b6976

Browse files
committed
test: More tests
1 parent 8779369 commit 61b6976

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

__tests__/lib/infer/augments.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*eslint-disable no-unused-vars*/
2+
var inferAugments = require('../../../src/infer/augments'),
3+
parse = require('../../../src/parsers/javascript');
4+
5+
function toComment(fn, filename) {
6+
return parse(
7+
{
8+
file: filename,
9+
source: fn instanceof Function ? '(' + fn.toString() + ')' : fn
10+
},
11+
{}
12+
)[0];
13+
}
14+
15+
function evaluate(code) {
16+
return inferAugments(toComment(code));
17+
}
18+
19+
test('inferAugments', function() {
20+
expect(evaluate('/** */class A extends B {}').augments).toEqual([
21+
{
22+
name: 'B',
23+
title: 'augments'
24+
}
25+
]);
26+
});

__tests__/lib/infer/properties.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*eslint-disable no-unused-vars*/
2+
var inferProperties = require('../../../src/infer/properties'),
3+
parse = require('../../../src/parsers/javascript');
4+
5+
function toComment(fn, filename) {
6+
return parse(
7+
{
8+
file: filename,
9+
source: fn instanceof Function ? '(' + fn.toString() + ')' : fn
10+
},
11+
{}
12+
)[0];
13+
}
14+
15+
function evaluate(code) {
16+
return inferProperties(toComment(code));
17+
}
18+
19+
test('inferProperties', function() {
20+
expect(evaluate('/** */type a = { b: 1 };').properties).toEqual([
21+
{
22+
lineNumber: 1,
23+
name: 'b',
24+
title: 'property',
25+
type: {
26+
type: 'NumericLiteralType',
27+
value: 1
28+
}
29+
}
30+
]);
31+
32+
expect(
33+
evaluate('/** */interface a { b: 1, c: { d: 2 } };').properties
34+
).toEqual([
35+
{
36+
lineNumber: 1,
37+
name: 'b',
38+
title: 'property',
39+
type: {
40+
type: 'NumericLiteralType',
41+
value: 1
42+
}
43+
},
44+
{
45+
lineNumber: 1,
46+
name: 'c',
47+
title: 'property',
48+
type: {
49+
fields: [
50+
{
51+
key: 'd',
52+
type: 'FieldType',
53+
value: {
54+
type: 'NumericLiteralType',
55+
value: 2
56+
}
57+
}
58+
],
59+
type: 'RecordType'
60+
}
61+
},
62+
{
63+
lineNumber: 1,
64+
name: 'c.d',
65+
title: 'property',
66+
type: {
67+
type: 'NumericLiteralType',
68+
value: 2
69+
}
70+
}
71+
]);
72+
});

0 commit comments

Comments
 (0)