UNPKG

938 BJavaScriptView Raw
1'use strict';
2
3var fs = require('fs');
4var assert = require('assert');
5var getRepo = require('get-repo');
6var parse = require('../');
7
8var testCases = fs.readdirSync(__dirname + '/cases').filter(function (name) {
9 return /\.tokens\.json$/.test(name);
10});
11
12function parseNewlineJson(str) {
13 return str.split('\n').filter(Boolean).map(JSON.parse)
14}
15
16function read(path) {
17 return fs.readFileSync(__dirname + '/cases/' + path, 'utf8');
18}
19function write(path, body) {
20 return fs.writeFileSync(__dirname + '/cases/' + path, body);
21}
22
23testCases.forEach(function (filename) {
24 console.dir(filename);
25 var expectedAst = JSON.parse(read(filename.replace(/\.tokens\.json$/, '.expected.json')));
26 var actualAst = parse(parseNewlineJson(read(filename)), filename);
27 write(filename.replace(/\.tokens\.json$/, '.actual.json'), JSON.stringify(actualAst, null, ' '));
28 assert.deepEqual(actualAst, expectedAst);
29});
30
31console.log('tests passed');
\No newline at end of file