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 144
/
Copy pathtree-sitter-spec.js
81 lines (64 loc) · 3.11 KB
/
tree-sitter-spec.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const dedent = require('dedent')
describe('Tree-sitter HTML grammar', () => {
beforeEach(async () => {
atom.config.set('core.useTreeSitterParsers', true)
await atom.packages.activatePackage('language-html')
})
it('tokenizes punctuation in HTML tags and attributes', async () => {
const editor = await atom.workspace.open(`test.html`)
editor.setText(dedent`
<html lang="en">
<head>
<meta charset='utf-8'>
<meta name='"' content="This'll test single and double quotes.">
</head>
<body>
</html>
`)
// Tag punctuation.
expect(editor.scopeDescriptorForBufferPosition([0, 0]).toString()).toBe(
'.text.html.basic .source.html .punctuation.definition.tag.html'
)
expect(editor.scopeDescriptorForBufferPosition([0, 15]).toString()).toBe(
'.text.html.basic .source.html .punctuation.definition.tag.html'
)
expect(editor.scopeDescriptorForBufferPosition([6, 0]).toString()).toBe(
'.text.html.basic .source.html .punctuation.definition.tag.html'
)
expect(editor.scopeDescriptorForBufferPosition([6, 6]).toString()).toBe(
'.text.html.basic .source.html .punctuation.definition.tag.html'
)
// Attribute-value pair punctuation.
expect(editor.scopeDescriptorForBufferPosition([0, 10]).toString()).toBe(
'.text.html.basic .source.html .punctuation.association.pair.attribute-value.html'
)
expect(editor.scopeDescriptorForBufferPosition([2, 18]).toString()).toBe(
'.text.html.basic .source.html .string.quoted.attribute-value.html .punctuation.definition.string.html'
)
expect(editor.scopeDescriptorForBufferPosition([2, 24]).toString()).toBe(
'.text.html.basic .source.html .string.quoted.attribute-value.html .punctuation.definition.string.html'
)
// Ensure an attribute value delimited by single-quotes won't mark a
// double-quote in the value as punctuation.
expect(editor.scopeDescriptorForBufferPosition([3, 15]).toString()).toBe(
'.text.html.basic .source.html .string.quoted.attribute-value.html .punctuation.definition.string.html'
)
expect(editor.scopeDescriptorForBufferPosition([3, 16]).toString()).toBe(
'.text.html.basic .source.html .string.quoted.attribute-value.html'
)
expect(editor.scopeDescriptorForBufferPosition([3, 17]).toString()).toBe(
'.text.html.basic .source.html .string.quoted.attribute-value.html .punctuation.definition.string.html'
)
// Ensure an attribute value delimited by double-quotes won't mark a
// single-quote in the value as punctuation.
expect(editor.scopeDescriptorForBufferPosition([3, 27]).toString()).toBe(
'.text.html.basic .source.html .string.quoted.attribute-value.html .punctuation.definition.string.html'
)
expect(editor.scopeDescriptorForBufferPosition([3, 32]).toString()).toBe(
'.text.html.basic .source.html .string.quoted.attribute-value.html'
)
expect(editor.scopeDescriptorForBufferPosition([3, 66]).toString()).toBe(
'.text.html.basic .source.html .string.quoted.attribute-value.html .punctuation.definition.string.html'
)
})
})