This repository was archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathtree-sitter-html-spec.js
More file actions
74 lines (64 loc) · 2.95 KB
/
tree-sitter-html-spec.js
File metadata and controls
74 lines (64 loc) · 2.95 KB
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
const dedent = require("dedent");
const {expectTokensToEqual, toHaveScopesAtPosition, nextHighlightingUpdate} = require('./tree-sitter-helpers')
describe("Tree-sitter PHP grammar", () => {
var editor;
beforeEach(async () => {
atom.config.set("core.useTreeSitterParsers", true);
await atom.packages.activatePackage("language-php");
await atom.packages.activatePackage("language-html");
editor = await atom.workspace.open("foo.php");
});
beforeEach(function () {
this.addMatchers({ toHaveScopesAtPosition });
});
describe("loading the grammar", () => {
it('loads the wrapper HTML grammar', () => {
embeddingGrammar = atom.grammars.grammarForScopeName("text.html.php");
expect(embeddingGrammar).toBeTruthy();
expect(embeddingGrammar.scopeName).toBe("text.html.php");
expect(embeddingGrammar.constructor.name).toBe("TreeSitterGrammar");
// FIXME how to test that all selectors were loaded correctly? Invalid
// selectors may generate errors and it would be great to catch those here.
// injections
expect(embeddingGrammar.injectionPointsByType.template).toBeTruthy();
expect(embeddingGrammar.injectionPointsByType.php).toBeTruthy();
})
});
describe("shebang", () => {
it("recognises shebang on the first line of document", () => {
editor.setText(dedent`
#!/usr/bin/env php
<?php echo "test"; ?>
`);
// expect(editor).toHaveScopesAtPosition([0, 0], "#!", ["text.html.php", "comment.line.shebang.php", "punctuation.definition.comment.php"], true);
expect(editor).toHaveScopesAtPosition([0, 1], "#!", ["text.html.php", "comment.line.shebang.php",
// FIXME following scopes differ from TM
'source.html'
], true);
expect(editor).toHaveScopesAtPosition([0, 2], "/usr/bin/env php", ["text.html.php", "comment.line.shebang.php",
// FIXME following scopes differ from TM
'source.html'
], true);
expect(editor).toHaveScopesAtPosition([1, 0], "<?php", ["text.html.php",
// "meta.embedded.line.php", "punctuation.section.embedded.begin.php"
], true);
expect(editor).toHaveScopesAtPosition([1, 1], "<?php", ["text.html.php", "meta.embedded.line.php", "punctuation.section.embedded.begin.php",
// FIXME following scopes differ from TM
'source.php'
], true);
});
it("does not recognize shebang on any of the other lines", () => {
editor.setText(dedent`
#!/usr/bin/env php
<?php echo "test"; ?>
`);
expect(editor).toHaveScopesAtPosition([1, 0], "#!", ["text.html.php"], true);
expect(editor).toHaveScopesAtPosition([1, 1], "#!", ["text.html.php",
// FIXME following scopes differ from TM
'meta.embedded.line.php',
'source.php',
'punctuation.section.embedded.begin.php'
], true);
});
});
});