1 | 'use strict';
|
2 |
|
3 | var fs = require('fs');
|
4 | var assert = require('assert');
|
5 | var getRepo = require('get-repo');
|
6 | var parse = require('../');
|
7 |
|
8 | var testCases = fs.readdirSync(__dirname + '/cases').filter(function (name) {
|
9 | return /\.tokens\.json$/.test(name);
|
10 | });
|
11 |
|
12 | function parseNewlineJson(str) {
|
13 | return str.split('\n').filter(Boolean).map(JSON.parse)
|
14 | }
|
15 |
|
16 | function read(path) {
|
17 | return fs.readFileSync(__dirname + '/cases/' + path, 'utf8');
|
18 | }
|
19 | function write(path, body) {
|
20 | return fs.writeFileSync(__dirname + '/cases/' + path, body);
|
21 | }
|
22 |
|
23 | testCases.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 |
|
31 | console.log('tests passed'); |
\ | No newline at end of file |