Add test mechanism
parent
fa97df9064
commit
e3c6aced03
|
@ -1,5 +1,7 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const argv = require('optimist')
|
||||
|
|
|
@ -25,7 +25,10 @@
|
|||
"babylon": "^6.18.0",
|
||||
"optimist": "^0.6.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jsondiffpatch": "^0.2.5"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
"test": "tests/do"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const jsondiffpatch = require('jsondiffpatch');
|
||||
|
||||
const generate = require('..');
|
||||
|
||||
const runner = path.basename(__filename);
|
||||
|
||||
const list = fs.readdirSync(__dirname)
|
||||
.filter(fname => fname !== runner)
|
||||
.map(fname => path.relative('.', path.join(__dirname, fname)));
|
||||
|
||||
for (const fpath of list) {
|
||||
const code = fs.readFileSync(fpath, 'utf8');
|
||||
|
||||
const actual = generate(code);
|
||||
const expected = eval(code.split('// ###')[1]);
|
||||
|
||||
const delta = jsondiffpatch.diff(actual, expected);
|
||||
|
||||
console.log(`${fpath}...`);
|
||||
|
||||
if (delta) {
|
||||
jsondiffpatch.console.log(delta);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
type Type = {
|
||||
a: string,
|
||||
b: number,
|
||||
c: boolean,
|
||||
d: null,
|
||||
};
|
||||
|
||||
interface Interface {
|
||||
a: string;
|
||||
b: number;
|
||||
c: boolean;
|
||||
d: null;
|
||||
};
|
||||
|
||||
class Class {
|
||||
a: string;
|
||||
b: number;
|
||||
c: boolean;
|
||||
d: null;
|
||||
}
|
||||
|
||||
// ###
|
||||
({
|
||||
Type: {
|
||||
type: 'record',
|
||||
name: 'Type',
|
||||
fields: [
|
||||
{name: 'a', type: 'string'},
|
||||
{name: 'b', type: 'double'},
|
||||
{name: 'c', type: 'boolean'},
|
||||
{name: 'd', type: 'null'},
|
||||
],
|
||||
},
|
||||
Interface: {
|
||||
type: 'record',
|
||||
name: 'Interface',
|
||||
fields: [
|
||||
{name: 'a', type: 'string'},
|
||||
{name: 'b', type: 'double'},
|
||||
{name: 'c', type: 'boolean'},
|
||||
{name: 'd', type: 'null'},
|
||||
],
|
||||
},
|
||||
Class: {
|
||||
type: 'record',
|
||||
name: 'Class',
|
||||
fields: [
|
||||
{name: 'a', type: 'string'},
|
||||
{name: 'b', type: 'double'},
|
||||
{name: 'c', type: 'boolean'},
|
||||
{name: 'd', type: 'null'},
|
||||
],
|
||||
},
|
||||
});
|
Loading…
Reference in New Issue