-
Notifications
You must be signed in to change notification settings - Fork 77
/
reference_test.js
61 lines (49 loc) · 1.78 KB
/
reference_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import assert from "assert";
import {join} from "path";
import {readdir} from "fs";
import {readfile} from "./util";
import {FluentParser} from "../src";
const fixtures = join(__dirname, "fixtures_reference");
readdir(fixtures, function(err, filenames) {
if (err) {
throw err;
}
const ftlnames = filenames.filter(
filename => filename.endsWith(".ftl")
);
// XXX This suite is not ideal. We ignore Junk and skip a number of fixtures.
suite("Reference tests", function() {
const parser = new FluentParser({withSpans: false});
// The following fixtures produce different ASTs in the tooling parser than
// in the reference parser. Skip them for now.
const skips = [
// Broken Attributes break the entire Entry right now.
// https://github.com/projectfluent/fluent.js/issues/237
"leading_dots.ftl",
"variant_lists.ftl"
];
for (const filename of ftlnames) {
// Skip the known AST incompatibilities.
if (skips.includes(filename)) {
test.skip(filename);
continue;
}
const ftlpath = join(fixtures, filename);
const astpath = ftlpath.replace(/ftl$/, "json");
test(filename, async function() {
const [ftl, expected] = await Promise.all(
[ftlpath, astpath].map(readfile));
const ref = JSON.parse(expected)
const ast = parser.parse(ftl);
// Only compare Junk content and ignore annotations, which carry error
// messages and positions. The reference parser doesn't produce
// annotations at the moment.
ast.body = ast.body.map(entry => entry.type === "Junk" ?
{...entry, annotations: []} : entry);
assert.deepEqual(
ast, ref,
"Parsed AST doesn't match the expected one");
});
}
});
});