This repository has been archived by the owner on Nov 20, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.mjs
96 lines (79 loc) · 2.14 KB
/
test.mjs
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import assert from "node:assert";
import test from "node:test";
import createSyntaxTree from "./dist/index.mjs";
const syntaxTree = await createSyntaxTree();
test("handlers.bf.parse", () => {
assert.equal(
syntaxTree.handlers.bf.parse("+++"),
"(root (increment), (increment), (increment))\n"
);
});
test("handlers.bf.format", () => {
assert.equal(syntaxTree.handlers.bf.format("+++"), "+++\n");
});
test("handlers.css.parse", () => {
const source = `
.foo {
color: red;
}
`;
const expected = `(css-stylesheet
(style-rule
(selectors
(class-selector (ident-token "foo"))
)
(declarations
(declaration color (ident-token "red"), (semicolon-token))
)
)
)
`;
assert.equal(syntaxTree.handlers.css.parse(source), expected);
});
// test("handlers.css.format", () => {
// const source = ".foo{color:red;}";
// const expected = `.foo {
// color: red;
// }
// `;
// assert.equal(syntaxTree.handlers.css.format(source), expected);
// });
test("handlers.json.parse", () => {
assert.equal(
syntaxTree.handlers.json.parse(`{ "a": "b" }`),
`(root value=(object values={"\\"a\\""=>(string value="\\"b\\"")}))\n`
);
});
test("handlers.json.format", () => {
assert.equal(
syntaxTree.handlers.json.format(`{"a":"b"}`),
`{ "a": "b" }\n`
);
});
test("handlers.haml.parse", () => {
assert.equal(
syntaxTree.handlers.haml.parse("= foo"),
`(root children=[(script text=" foo")])\n`
);
});
test("handlers.haml.format", () => {
assert.equal(syntaxTree.handlers.haml.format("= foo"), "= foo\n");
});
test("handlers.ruby.parse", () => {
assert.equal(
syntaxTree.handlers.ruby.parse("foo"),
`(program (statements ((vcall (ident "foo")))))\n`
);
});
test("handlers.ruby.format", () => {
assert.equal(syntaxTree.handlers.ruby.format("1+1"), "1 + 1\n");
});
test("handlers.xml.parse", () => {
assert.equal(
syntaxTree.handlers.xml.parse("<foo></foo>"),
`(document\n (element (opening_tag "<", "foo", ">"), (closing_tag "</", "foo", ">"))\n)\n`
);
});
test("handlers.xml.format", () => {
assert.equal(syntaxTree.handlers.xml.format("<foo></foo>"), "<foo />\n");
});