Skip to content

Commit

Permalink
test: More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed Sep 15, 2017
1 parent 8779369 commit 61b6976
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
26 changes: 26 additions & 0 deletions __tests__/lib/infer/augments.js
@@ -0,0 +1,26 @@
/*eslint-disable no-unused-vars*/
var inferAugments = require('../../../src/infer/augments'),
parse = require('../../../src/parsers/javascript');

function toComment(fn, filename) {
return parse(
{
file: filename,
source: fn instanceof Function ? '(' + fn.toString() + ')' : fn
},
{}
)[0];
}

function evaluate(code) {
return inferAugments(toComment(code));
}

test('inferAugments', function() {
expect(evaluate('/** */class A extends B {}').augments).toEqual([
{
name: 'B',
title: 'augments'
}
]);
});
72 changes: 72 additions & 0 deletions __tests__/lib/infer/properties.js
@@ -0,0 +1,72 @@
/*eslint-disable no-unused-vars*/
var inferProperties = require('../../../src/infer/properties'),
parse = require('../../../src/parsers/javascript');

function toComment(fn, filename) {
return parse(
{
file: filename,
source: fn instanceof Function ? '(' + fn.toString() + ')' : fn
},
{}
)[0];
}

function evaluate(code) {
return inferProperties(toComment(code));
}

test('inferProperties', function() {
expect(evaluate('/** */type a = { b: 1 };').properties).toEqual([
{
lineNumber: 1,
name: 'b',
title: 'property',
type: {
type: 'NumericLiteralType',
value: 1
}
}
]);

expect(
evaluate('/** */interface a { b: 1, c: { d: 2 } };').properties
).toEqual([
{
lineNumber: 1,
name: 'b',
title: 'property',
type: {
type: 'NumericLiteralType',
value: 1
}
},
{
lineNumber: 1,
name: 'c',
title: 'property',
type: {
fields: [
{
key: 'd',
type: 'FieldType',
value: {
type: 'NumericLiteralType',
value: 2
}
}
],
type: 'RecordType'
}
},
{
lineNumber: 1,
name: 'c.d',
title: 'property',
type: {
type: 'NumericLiteralType',
value: 2
}
}
]);
});

0 comments on commit 61b6976

Please sign in to comment.