Skip to content

Commit 0d35311

Browse files
committed
glayzzle#152 - fixtures
1 parent 7941406 commit 0d35311

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

test/fixture.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const fs = require("fs");
2+
const fixtures = __dirname + "/fixtures/";
3+
const parser = require("../src/index");
4+
5+
describe('fixtures', () => {
6+
fs.readdirSync(fixtures).forEach((name) => {
7+
describe("Testing " + name, () => {
8+
fs.readdirSync(fixtures + name).forEach((file) => {
9+
if (file.substring(file.length - 4) === ".php") {
10+
it("check " + file.substring(0, file.length - 4), () => {
11+
const filename = fixtures + name + '/' + file;
12+
const buffer = fs.readFileSync(filename).toString();
13+
let options = {};
14+
// read custom options
15+
if (buffer[0] === '{') {
16+
let offset = buffer.indexOf('\n}');
17+
if (offset > 0) {
18+
options = JSON.parse(buffer.substring(0, offset + 2));
19+
}
20+
}
21+
let original, ast;
22+
try {
23+
// parse the file
24+
ast = parser.parseCode(buffer, filename, options);
25+
ast = JSON.stringify(ast, null, 2);
26+
} catch(e) {
27+
console.error(e);
28+
// convert error to JSON
29+
ast = JSON.stringify(e);
30+
}
31+
try {
32+
original = fs.readFileSync(filename + '.json').toString();
33+
} catch(e) {
34+
console.log('Generating ' + filename + ' (' + e.message + ')')
35+
// GENERATE THE OUTPUT (IF FILE DOES NOT EXISTS)
36+
original = ast;
37+
fs.writeFileSync(filename + '.json', original);
38+
}
39+
original.should.be.exactly(ast, "Fail " + filename);
40+
});
41+
}
42+
});
43+
});
44+
});
45+
});

0 commit comments

Comments
 (0)