rbtr-lang-css 2026.7.0.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rbtr_lang_css/__init__.py +1 -0
- rbtr_lang_css/css.scm +24 -0
- rbtr_lang_css/plugin.py +65 -0
- rbtr_lang_css/py.typed +0 -0
- rbtr_lang_css/tests/__init__.py +0 -0
- rbtr_lang_css/tests/__snapshots__/test_samples/test_edges_match_snapshot.json +5 -0
- rbtr_lang_css/tests/__snapshots__/test_samples/test_extraction_matches_snapshot.json +254 -0
- rbtr_lang_css/tests/cases_extraction.py +33 -0
- rbtr_lang_css/tests/samples/css/css.css +36 -0
- rbtr_lang_css/tests/samples/css/reset.css +3 -0
- rbtr_lang_css/tests/samples/css/theme.css +3 -0
- rbtr_lang_css/tests/test_extraction.py +34 -0
- rbtr_lang_css/tests/test_samples.py +82 -0
- rbtr_lang_css-2026.7.0.dev0.dist-info/METADATA +8 -0
- rbtr_lang_css-2026.7.0.dev0.dist-info/RECORD +17 -0
- rbtr_lang_css-2026.7.0.dev0.dist-info/WHEEL +4 -0
- rbtr_lang_css-2026.7.0.dev0.dist-info/entry_points.txt +3 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""CSS language plugin package."""
|
rbtr_lang_css/css.scm
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
; Comments (`/* */`).
|
|
2
|
+
(comment) @comment
|
|
3
|
+
|
|
4
|
+
(rule_set
|
|
5
|
+
(selectors) @_cls_name) @class
|
|
6
|
+
|
|
7
|
+
(media_statement) @class
|
|
8
|
+
|
|
9
|
+
(charset_statement) @config_key
|
|
10
|
+
|
|
11
|
+
(keyframes_statement
|
|
12
|
+
(keyframes_name) @_cls_name) @class
|
|
13
|
+
|
|
14
|
+
(import_statement
|
|
15
|
+
(call_expression
|
|
16
|
+
(arguments
|
|
17
|
+
(string_value (string_content) @_import_module)))) @import
|
|
18
|
+
|
|
19
|
+
(import_statement
|
|
20
|
+
(string_value (string_content) @_import_module)) @import
|
|
21
|
+
|
|
22
|
+
(declaration
|
|
23
|
+
(property_name) @_var_name
|
|
24
|
+
(#match? @_var_name "^--")) @variable
|
rbtr_lang_css/plugin.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""CSS language plugin.
|
|
2
|
+
|
|
3
|
+
Splits CSS into `class` chunks — one per rule set (named by its
|
|
4
|
+
selector) and one per `@media` / `@keyframes` block — via a
|
|
5
|
+
tree-sitter query. `@charset` is captured as a config key,
|
|
6
|
+
`@import` statements as imports for cross-language edges, and
|
|
7
|
+
custom properties as variables.
|
|
8
|
+
|
|
9
|
+
Extracted chunks::
|
|
10
|
+
|
|
11
|
+
body { color: #333; } → class "body", scope ""
|
|
12
|
+
.header { background: blue; } → class ".header", scope ""
|
|
13
|
+
@media (max-width: 600px) {} → class "<anonymous>", scope ""
|
|
14
|
+
@keyframes slide { ... } → class "slide", scope ""
|
|
15
|
+
@charset "utf-8"; → config_key "<anonymous>"
|
|
16
|
+
@import url("reset.css"); → import, metadata {module: "reset.css"}
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
from typing import TYPE_CHECKING
|
|
22
|
+
|
|
23
|
+
from rbtr.languages.registration import (
|
|
24
|
+
LanguageRegistration,
|
|
25
|
+
QueryExtraction,
|
|
26
|
+
ScopeResolver,
|
|
27
|
+
enclosing_nodes_of_type,
|
|
28
|
+
load_query,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
if TYPE_CHECKING:
|
|
32
|
+
from tree_sitter import Node
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def css_nesting_scope(
|
|
36
|
+
_resolver: ScopeResolver, capture_name: str, node: Node, captures: dict[str, list[Node]]
|
|
37
|
+
) -> list[str]:
|
|
38
|
+
"""Scope a chunk under its ancestor rule-set selectors.
|
|
39
|
+
|
|
40
|
+
Shared by the CSS family (CSS/SCSS/Less), whose rule sets nest:
|
|
41
|
+
`.card { .title { … } }` scopes `.title` under `.card`. A rule set
|
|
42
|
+
inside an `@media` block has no rule-set ancestor, so it stays
|
|
43
|
+
unscoped. Segments are outermost-first.
|
|
44
|
+
"""
|
|
45
|
+
segments: list[str] = []
|
|
46
|
+
for ancestor in enclosing_nodes_of_type(node, frozenset({"rule_set"})):
|
|
47
|
+
for child in ancestor.children:
|
|
48
|
+
if child.type == "selectors" and child.text:
|
|
49
|
+
segments.append(child.text.decode("utf-8", errors="replace").strip())
|
|
50
|
+
break
|
|
51
|
+
return segments
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
css = LanguageRegistration(
|
|
55
|
+
id="css",
|
|
56
|
+
extensions=frozenset({".css"}),
|
|
57
|
+
grammar_module="tree_sitter_css",
|
|
58
|
+
extraction=QueryExtraction(
|
|
59
|
+
query=load_query(__package__, "css"),
|
|
60
|
+
),
|
|
61
|
+
import_targets=frozenset({"css"}),
|
|
62
|
+
extraction_serial=4,
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
css.scope_extractor(css_nesting_scope)
|
rbtr_lang_css/py.typed
ADDED
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "0c6600a920da6f7a",
|
|
4
|
+
"blob_sha": "sha1",
|
|
5
|
+
"file_path": "css.css",
|
|
6
|
+
"kind": "comment",
|
|
7
|
+
"name": "<anonymous>",
|
|
8
|
+
"scope": "",
|
|
9
|
+
"language": "css",
|
|
10
|
+
"content": "/* Greeter styles.\n *\n * The CSS plugin extracts rule sets, @media, @charset, and @keyframes\n * as doc sections, and @import statements as imports. */",
|
|
11
|
+
"line_start": 1,
|
|
12
|
+
"line_end": 4,
|
|
13
|
+
"metadata": {
|
|
14
|
+
"module": "",
|
|
15
|
+
"names": "",
|
|
16
|
+
"dots": "",
|
|
17
|
+
"language_hint": ""
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"id": "d38c6f13e7d1f1f6",
|
|
22
|
+
"blob_sha": "sha1",
|
|
23
|
+
"file_path": "css.css",
|
|
24
|
+
"kind": "config_key",
|
|
25
|
+
"name": "<anonymous>",
|
|
26
|
+
"scope": "",
|
|
27
|
+
"language": "css",
|
|
28
|
+
"content": "@charset \"UTF-8\";",
|
|
29
|
+
"line_start": 6,
|
|
30
|
+
"line_end": 6,
|
|
31
|
+
"metadata": {
|
|
32
|
+
"module": "",
|
|
33
|
+
"names": "",
|
|
34
|
+
"dots": "",
|
|
35
|
+
"language_hint": ""
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"id": "57227f716d5abf82",
|
|
40
|
+
"blob_sha": "sha1",
|
|
41
|
+
"file_path": "css.css",
|
|
42
|
+
"kind": "import",
|
|
43
|
+
"name": "@import url(\"reset.css\");",
|
|
44
|
+
"scope": "",
|
|
45
|
+
"language": "css",
|
|
46
|
+
"content": "@import url(\"reset.css\");",
|
|
47
|
+
"line_start": 8,
|
|
48
|
+
"line_end": 8,
|
|
49
|
+
"metadata": {
|
|
50
|
+
"module": "reset.css",
|
|
51
|
+
"names": "",
|
|
52
|
+
"dots": "",
|
|
53
|
+
"language_hint": ""
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"id": "8e8cf908ddfdc18a",
|
|
58
|
+
"blob_sha": "sha1",
|
|
59
|
+
"file_path": "css.css",
|
|
60
|
+
"kind": "import",
|
|
61
|
+
"name": "@import \"theme.css\";",
|
|
62
|
+
"scope": "",
|
|
63
|
+
"language": "css",
|
|
64
|
+
"content": "@import \"theme.css\";",
|
|
65
|
+
"line_start": 9,
|
|
66
|
+
"line_end": 9,
|
|
67
|
+
"metadata": {
|
|
68
|
+
"module": "theme.css",
|
|
69
|
+
"names": "",
|
|
70
|
+
"dots": "",
|
|
71
|
+
"language_hint": ""
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"id": "643120e24579e242",
|
|
76
|
+
"blob_sha": "sha1",
|
|
77
|
+
"file_path": "css.css",
|
|
78
|
+
"kind": "class",
|
|
79
|
+
"name": ":root",
|
|
80
|
+
"scope": "",
|
|
81
|
+
"language": "css",
|
|
82
|
+
"content": ":root {\n --greeting-color: #333;\n}",
|
|
83
|
+
"line_start": 11,
|
|
84
|
+
"line_end": 13,
|
|
85
|
+
"metadata": {
|
|
86
|
+
"module": "",
|
|
87
|
+
"names": "",
|
|
88
|
+
"dots": "",
|
|
89
|
+
"language_hint": ""
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"id": "7927be2ae9966e1c",
|
|
94
|
+
"blob_sha": "sha1",
|
|
95
|
+
"file_path": "css.css",
|
|
96
|
+
"kind": "variable",
|
|
97
|
+
"name": "--greeting-color",
|
|
98
|
+
"scope": ":root",
|
|
99
|
+
"language": "css",
|
|
100
|
+
"content": "--greeting-color: #333;",
|
|
101
|
+
"line_start": 12,
|
|
102
|
+
"line_end": 12,
|
|
103
|
+
"metadata": {
|
|
104
|
+
"module": "",
|
|
105
|
+
"names": "",
|
|
106
|
+
"dots": "",
|
|
107
|
+
"language_hint": ""
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"id": "5d0ae5edc801e00b",
|
|
112
|
+
"blob_sha": "sha1",
|
|
113
|
+
"file_path": "css.css",
|
|
114
|
+
"kind": "class",
|
|
115
|
+
"name": ".greeter",
|
|
116
|
+
"scope": "",
|
|
117
|
+
"language": "css",
|
|
118
|
+
"content": ".greeter {\n color: var(--greeting-color);\n font-weight: bold;\n .greeting-label {\n text-transform: uppercase;\n }\n}",
|
|
119
|
+
"line_start": 15,
|
|
120
|
+
"line_end": 21,
|
|
121
|
+
"metadata": {
|
|
122
|
+
"module": "",
|
|
123
|
+
"names": "",
|
|
124
|
+
"dots": "",
|
|
125
|
+
"language_hint": ""
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"id": "bde2f382ecc89b91",
|
|
130
|
+
"blob_sha": "sha1",
|
|
131
|
+
"file_path": "css.css",
|
|
132
|
+
"kind": "class",
|
|
133
|
+
"name": ".greeting-label",
|
|
134
|
+
"scope": ".greeter",
|
|
135
|
+
"language": "css",
|
|
136
|
+
"content": ".greeting-label {\n text-transform: uppercase;\n }",
|
|
137
|
+
"line_start": 18,
|
|
138
|
+
"line_end": 20,
|
|
139
|
+
"metadata": {
|
|
140
|
+
"module": "",
|
|
141
|
+
"names": "",
|
|
142
|
+
"dots": "",
|
|
143
|
+
"language_hint": ""
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
"id": "c5c45e34a7d10d24",
|
|
148
|
+
"blob_sha": "sha1",
|
|
149
|
+
"file_path": "css.css",
|
|
150
|
+
"kind": "class",
|
|
151
|
+
"name": "<anonymous>",
|
|
152
|
+
"scope": "",
|
|
153
|
+
"language": "css",
|
|
154
|
+
"content": "@media (max-width: 600px) {\n .greeter {\n font-size: 14px;\n }\n}",
|
|
155
|
+
"line_start": 23,
|
|
156
|
+
"line_end": 27,
|
|
157
|
+
"metadata": {
|
|
158
|
+
"module": "",
|
|
159
|
+
"names": "",
|
|
160
|
+
"dots": "",
|
|
161
|
+
"language_hint": ""
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
"id": "901cf6a2b4f1e93a",
|
|
166
|
+
"blob_sha": "sha1",
|
|
167
|
+
"file_path": "css.css",
|
|
168
|
+
"kind": "class",
|
|
169
|
+
"name": ".greeter",
|
|
170
|
+
"scope": "",
|
|
171
|
+
"language": "css",
|
|
172
|
+
"content": ".greeter {\n font-size: 14px;\n }",
|
|
173
|
+
"line_start": 24,
|
|
174
|
+
"line_end": 26,
|
|
175
|
+
"metadata": {
|
|
176
|
+
"module": "",
|
|
177
|
+
"names": "",
|
|
178
|
+
"dots": "",
|
|
179
|
+
"language_hint": ""
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
"id": "0a3a01fd3738a147",
|
|
184
|
+
"blob_sha": "sha1",
|
|
185
|
+
"file_path": "css.css",
|
|
186
|
+
"kind": "class",
|
|
187
|
+
"name": "greeting-fade",
|
|
188
|
+
"scope": "",
|
|
189
|
+
"language": "css",
|
|
190
|
+
"content": "@keyframes greeting-fade {\n from {\n opacity: 0;\n }\n to {\n opacity: 1;\n }\n}",
|
|
191
|
+
"line_start": 29,
|
|
192
|
+
"line_end": 36,
|
|
193
|
+
"metadata": {
|
|
194
|
+
"module": "",
|
|
195
|
+
"names": "",
|
|
196
|
+
"dots": "",
|
|
197
|
+
"language_hint": ""
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
"id": "8d3da5c38b0da34b",
|
|
202
|
+
"blob_sha": "sha1",
|
|
203
|
+
"file_path": "reset.css",
|
|
204
|
+
"kind": "class",
|
|
205
|
+
"name": "*",
|
|
206
|
+
"scope": "",
|
|
207
|
+
"language": "css",
|
|
208
|
+
"content": "* {\n margin: 0;\n}",
|
|
209
|
+
"line_start": 1,
|
|
210
|
+
"line_end": 3,
|
|
211
|
+
"metadata": {
|
|
212
|
+
"module": "",
|
|
213
|
+
"names": "",
|
|
214
|
+
"dots": "",
|
|
215
|
+
"language_hint": ""
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
"id": "99f917f38f753e71",
|
|
220
|
+
"blob_sha": "sha1",
|
|
221
|
+
"file_path": "theme.css",
|
|
222
|
+
"kind": "class",
|
|
223
|
+
"name": ":root",
|
|
224
|
+
"scope": "",
|
|
225
|
+
"language": "css",
|
|
226
|
+
"content": ":root {\n --greeting-color: #333;\n}",
|
|
227
|
+
"line_start": 1,
|
|
228
|
+
"line_end": 3,
|
|
229
|
+
"metadata": {
|
|
230
|
+
"module": "",
|
|
231
|
+
"names": "",
|
|
232
|
+
"dots": "",
|
|
233
|
+
"language_hint": ""
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
"id": "5e10cca1e6d1f2eb",
|
|
238
|
+
"blob_sha": "sha1",
|
|
239
|
+
"file_path": "theme.css",
|
|
240
|
+
"kind": "variable",
|
|
241
|
+
"name": "--greeting-color",
|
|
242
|
+
"scope": ":root",
|
|
243
|
+
"language": "css",
|
|
244
|
+
"content": "--greeting-color: #333;",
|
|
245
|
+
"line_start": 2,
|
|
246
|
+
"line_end": 2,
|
|
247
|
+
"metadata": {
|
|
248
|
+
"module": "",
|
|
249
|
+
"names": "",
|
|
250
|
+
"dots": "",
|
|
251
|
+
"language_hint": ""
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
]
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""CSS extraction test cases.
|
|
2
|
+
|
|
3
|
+
Each `@case` returns test data consumed by `test_extraction.py` via
|
|
4
|
+
`pytest-cases`. See the plugin docstring for the full source→chunk mapping.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from pytest_cases import case
|
|
10
|
+
|
|
11
|
+
type SymbolCase = tuple[str, str, list[tuple[str, str, str]]]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@case(tags=["symbol"])
|
|
15
|
+
def case_css_rule_sets() -> SymbolCase:
|
|
16
|
+
"""CSS splits by rule sets."""
|
|
17
|
+
src = """\
|
|
18
|
+
body {
|
|
19
|
+
color: #333;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.header {
|
|
23
|
+
background: blue;
|
|
24
|
+
}
|
|
25
|
+
"""
|
|
26
|
+
return (
|
|
27
|
+
"css",
|
|
28
|
+
src,
|
|
29
|
+
[
|
|
30
|
+
("class", "body", ""),
|
|
31
|
+
("class", ".header", ""),
|
|
32
|
+
],
|
|
33
|
+
)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/* Greeter styles.
|
|
2
|
+
*
|
|
3
|
+
* The CSS plugin extracts rule sets, @media, @charset, and @keyframes
|
|
4
|
+
* as doc sections, and @import statements as imports. */
|
|
5
|
+
|
|
6
|
+
@charset "UTF-8";
|
|
7
|
+
|
|
8
|
+
@import url("reset.css");
|
|
9
|
+
@import "theme.css";
|
|
10
|
+
|
|
11
|
+
:root {
|
|
12
|
+
--greeting-color: #333;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.greeter {
|
|
16
|
+
color: var(--greeting-color);
|
|
17
|
+
font-weight: bold;
|
|
18
|
+
.greeting-label {
|
|
19
|
+
text-transform: uppercase;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@media (max-width: 600px) {
|
|
24
|
+
.greeter {
|
|
25
|
+
font-size: 14px;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@keyframes greeting-fade {
|
|
30
|
+
from {
|
|
31
|
+
opacity: 0;
|
|
32
|
+
}
|
|
33
|
+
to {
|
|
34
|
+
opacity: 1;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""CSS extraction tests.
|
|
2
|
+
|
|
3
|
+
Symbol cases (`cases_extraction.py`) drive the shared check; the function
|
|
4
|
+
at the end pins CSS's `@import` edge behaviour.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from pytest_cases import parametrize_with_cases
|
|
10
|
+
|
|
11
|
+
from rbtr.git import FileEntry
|
|
12
|
+
from rbtr.index.models import ChunkKind
|
|
13
|
+
from rbtr.languages.extract import extract_file
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@parametrize_with_cases("lang, source, expected", cases=".cases_extraction", has_tag="symbol")
|
|
17
|
+
def test_extracts_expected_symbols(lang: str, source: str, expected: list) -> None:
|
|
18
|
+
"""Each expected (kind, name, scope) tuple appears in the output."""
|
|
19
|
+
chunks = extract_file(FileEntry("input", "sha1", source.encode()), lang)
|
|
20
|
+
symbols = [(c.kind, c.name, c.scope) for c in chunks]
|
|
21
|
+
for exp in expected:
|
|
22
|
+
assert exp in symbols, f"expected {exp} not found in {symbols}"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test_css_import_produces_import_chunk() -> None:
|
|
26
|
+
"""CSS @import url(...) produces an import chunk."""
|
|
27
|
+
src = """\
|
|
28
|
+
@import url("reset.css");
|
|
29
|
+
body { color: #333; }
|
|
30
|
+
"""
|
|
31
|
+
chunks = extract_file(FileEntry("input", "sha1", src.encode()), "css")
|
|
32
|
+
imports = [c for c in chunks if c.kind == ChunkKind.IMPORT]
|
|
33
|
+
assert len(imports) == 1
|
|
34
|
+
assert imports[0].metadata.module == "reset.css"
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"""CSS sample extraction: the `samples/css/` project through the real pipeline.
|
|
2
|
+
|
|
3
|
+
The snapshots are the golden record of what CSS extraction produces.
|
|
4
|
+
Engine-wide invariants are covered once in core.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import TYPE_CHECKING
|
|
11
|
+
|
|
12
|
+
import pytest
|
|
13
|
+
from tree_sitter import Parser
|
|
14
|
+
|
|
15
|
+
from rbtr.git import FileEntry
|
|
16
|
+
from rbtr.index.models import Chunk, ChunkKind, Edge
|
|
17
|
+
from rbtr.languages.edges import build_resolution_map, infer_import_edges
|
|
18
|
+
from rbtr.languages.extract import extract_file
|
|
19
|
+
from rbtr.languages.manager import get_manager
|
|
20
|
+
from rbtr.testing import render_edges
|
|
21
|
+
|
|
22
|
+
if TYPE_CHECKING:
|
|
23
|
+
from syrupy.assertion import SnapshotAssertion
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@pytest.fixture
|
|
27
|
+
def project() -> list[tuple[str, str]]:
|
|
28
|
+
"""The `(relative path, text)` files of the `samples/css/` project."""
|
|
29
|
+
root = Path(__file__).parent / "samples" / "css"
|
|
30
|
+
return [
|
|
31
|
+
(str(p.relative_to(root)), p.read_text()) for p in sorted(root.rglob("*")) if p.is_file()
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@pytest.fixture
|
|
36
|
+
def chunks(project: list[tuple[str, str]]) -> list[Chunk]:
|
|
37
|
+
"""Chunks from every project file, each via the real `extract_file`."""
|
|
38
|
+
manager = get_manager()
|
|
39
|
+
out: list[Chunk] = []
|
|
40
|
+
for path, text in project:
|
|
41
|
+
lang = manager.detect_language(path) or "css"
|
|
42
|
+
out.extend(extract_file(FileEntry(path, "sha1", text.encode()), lang))
|
|
43
|
+
return out
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@pytest.fixture
|
|
47
|
+
def edges(project: list[tuple[str, str]], chunks: list[Chunk]) -> list[Edge]:
|
|
48
|
+
"""Import edges inferred across the project's files."""
|
|
49
|
+
manager = get_manager()
|
|
50
|
+
repo_files = {path for path, _ in project}
|
|
51
|
+
return infer_import_edges(chunks, repo_files, build_resolution_map(manager))
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def test_emits_expected_kinds(chunks: list[Chunk]) -> None:
|
|
55
|
+
"""The sample exercises CSS's class, config-key, import, and variable chunks."""
|
|
56
|
+
kinds = {c.kind for c in chunks}
|
|
57
|
+
assert {
|
|
58
|
+
ChunkKind.CLASS,
|
|
59
|
+
ChunkKind.CONFIG_KEY,
|
|
60
|
+
ChunkKind.IMPORT,
|
|
61
|
+
ChunkKind.VARIABLE,
|
|
62
|
+
ChunkKind.COMMENT,
|
|
63
|
+
} <= kinds
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def test_parses_cleanly(project: list[tuple[str, str]]) -> None:
|
|
67
|
+
"""Every project file is valid source — no tree-sitter ERROR/MISSING nodes."""
|
|
68
|
+
manager = get_manager()
|
|
69
|
+
for path, text in project:
|
|
70
|
+
grammar = manager.grammar(manager.detect_language(path) or "css")
|
|
71
|
+
assert grammar is not None
|
|
72
|
+
assert not Parser(grammar).parse(text.encode()).root_node.has_error, path
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_extraction_matches_snapshot(chunks: list[Chunk], snapshot_json: SnapshotAssertion) -> None:
|
|
76
|
+
assert chunks == snapshot_json
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def test_edges_match_snapshot(
|
|
80
|
+
chunks: list[Chunk], edges: list[Edge], snapshot_json: SnapshotAssertion
|
|
81
|
+
) -> None:
|
|
82
|
+
assert render_edges(edges, chunks) == snapshot_json
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
rbtr_lang_css/__init__.py,sha256=1uVY1xtttuolohffMr2cfNFZjksULsG2fKChf3-vGcs,35
|
|
2
|
+
rbtr_lang_css/css.scm,sha256=x8mYO68jta5BX5slmcyXWSTkSA-vu06jAL8AJk2Wm7g,483
|
|
3
|
+
rbtr_lang_css/plugin.py,sha256=cJbrdz7cUospUPih4HDXMKbEVMyoCx_irgKESCdqfrc,2110
|
|
4
|
+
rbtr_lang_css/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
rbtr_lang_css/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
rbtr_lang_css/tests/__snapshots__/test_samples/test_edges_match_snapshot.json,sha256=KLiJHhBsvJI88-ApBMl6QgxWu8fYByrRyLMAndAvZc0,216
|
|
7
|
+
rbtr_lang_css/tests/__snapshots__/test_samples/test_extraction_matches_snapshot.json,sha256=HWq8QjqL0XLsS8fnGNT8OhJhAv6HepaYNCiiFGdtgrs,5659
|
|
8
|
+
rbtr_lang_css/tests/cases_extraction.py,sha256=nkULQR6ry3ZHmmeBaUtR9M-QzsVBRJJlAennLIjon6Y,628
|
|
9
|
+
rbtr_lang_css/tests/samples/css/css.css,sha256=In9FinjF2042LccNdAOfLehvQ33Zcb1qGd4oFm6PymI,532
|
|
10
|
+
rbtr_lang_css/tests/samples/css/reset.css,sha256=5_P46vzdXnyfKrK_RcVp1_FlXa1QiNmh04Ktl143UZo,19
|
|
11
|
+
rbtr_lang_css/tests/samples/css/theme.css,sha256=W0Xm2vdJ-l-fFZLNun-k3jEVb8e6zWNBYmgHa3jXVkQ,36
|
|
12
|
+
rbtr_lang_css/tests/test_extraction.py,sha256=-_q4V0WVlJB0QuRHhzds0Vbzmn-VCG-BLpcbxdPaefA,1243
|
|
13
|
+
rbtr_lang_css/tests/test_samples.py,sha256=HoDxq-ru9sHGtklinpZeNuoxybecL0Ewqqq1YsHONNE,2772
|
|
14
|
+
rbtr_lang_css-2026.7.0.dev0.dist-info/WHEEL,sha256=CoDSoyhtC_eO_tlxRYzsTraPv1fPJRXFx91k6ISeAvA,81
|
|
15
|
+
rbtr_lang_css-2026.7.0.dev0.dist-info/entry_points.txt,sha256=wmUed7Ru4N63pQp0jRCFQjTFNhKm3FpeJvtNCOEWvsk,49
|
|
16
|
+
rbtr_lang_css-2026.7.0.dev0.dist-info/METADATA,sha256=pwI_smjawsL6NdFKYjoXKHqpjwE_jrElbhV8cSNp_qU,217
|
|
17
|
+
rbtr_lang_css-2026.7.0.dev0.dist-info/RECORD,,
|