rbtr-lang-css 2026.9.0.dev1__tar.gz
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-2026.9.0.dev1/LICENSE +21 -0
- rbtr_lang_css-2026.9.0.dev1/PKG-INFO +73 -0
- rbtr_lang_css-2026.9.0.dev1/README.md +47 -0
- rbtr_lang_css-2026.9.0.dev1/pyproject.toml +57 -0
- rbtr_lang_css-2026.9.0.dev1/pyproject.toml.orig +61 -0
- rbtr_lang_css-2026.9.0.dev1/src/rbtr_lang_css/__init__.py +1 -0
- rbtr_lang_css-2026.9.0.dev1/src/rbtr_lang_css/css.scm +24 -0
- rbtr_lang_css-2026.9.0.dev1/src/rbtr_lang_css/plugin.py +65 -0
- rbtr_lang_css-2026.9.0.dev1/src/rbtr_lang_css/py.typed +0 -0
- rbtr_lang_css-2026.9.0.dev1/src/rbtr_lang_css/tests/__init__.py +0 -0
- rbtr_lang_css-2026.9.0.dev1/src/rbtr_lang_css/tests/__snapshots__/test_samples/test_edges_match_snapshot.json +8 -0
- rbtr_lang_css-2026.9.0.dev1/src/rbtr_lang_css/tests/__snapshots__/test_samples/test_extraction_matches_snapshot.json +382 -0
- rbtr_lang_css-2026.9.0.dev1/src/rbtr_lang_css/tests/cases_extraction.py +33 -0
- rbtr_lang_css-2026.9.0.dev1/src/rbtr_lang_css/tests/samples/css/css.css +38 -0
- rbtr_lang_css-2026.9.0.dev1/src/rbtr_lang_css/tests/samples/css/partials/dark.css +7 -0
- rbtr_lang_css-2026.9.0.dev1/src/rbtr_lang_css/tests/samples/css/partials/palette.css +4 -0
- rbtr_lang_css-2026.9.0.dev1/src/rbtr_lang_css/tests/samples/css/reset.css +3 -0
- rbtr_lang_css-2026.9.0.dev1/src/rbtr_lang_css/tests/samples/css/theme.css +3 -0
- rbtr_lang_css-2026.9.0.dev1/src/rbtr_lang_css/tests/test_extraction.py +34 -0
- rbtr_lang_css-2026.9.0.dev1/src/rbtr_lang_css/tests/test_samples.py +82 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alejandro Giacometti
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rbtr-lang-css
|
|
3
|
+
Version: 2026.9.0.dev1
|
|
4
|
+
Summary: rbtr — CSS language plugin
|
|
5
|
+
Keywords: code-search,code-index,tree-sitter,static-analysis,semantic-search,developer-tools,css
|
|
6
|
+
Author: Alejandro Giacometti
|
|
7
|
+
Author-email: Alejandro Giacometti <alejandro.giacometti@gmail.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
15
|
+
Classifier: Topic :: Text Processing :: Indexing
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Dist: rbtr==2026.9.0.dev1
|
|
18
|
+
Requires-Dist: tree-sitter-css
|
|
19
|
+
Requires-Python: >=3.13
|
|
20
|
+
Project-URL: Homepage, https://github.com/janrito/rbtr
|
|
21
|
+
Project-URL: Repository, https://github.com/janrito/rbtr
|
|
22
|
+
Project-URL: Documentation, https://github.com/janrito/rbtr/tree/main/packages/rbtr-lang-css#readme
|
|
23
|
+
Project-URL: Issues, https://github.com/janrito/rbtr/issues
|
|
24
|
+
Project-URL: Changelog, https://github.com/janrito/rbtr/releases
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# rbtr-lang-css
|
|
28
|
+
|
|
29
|
+
CSS support for [rbtr]. Optional plugin — install with
|
|
30
|
+
`pip install rbtr[css]`.
|
|
31
|
+
|
|
32
|
+
[rbtr]: https://github.com/janrito/rbtr/tree/main/packages/rbtr#readme
|
|
33
|
+
|
|
34
|
+
## What it ingests
|
|
35
|
+
|
|
36
|
+
One chunk per top-level rule set, keyed by its selector. A rule set is a
|
|
37
|
+
named collection of property declarations, so it maps to a **class** (the
|
|
38
|
+
same shape SQL's `CREATE TABLE` takes) — as do `@media` and `@keyframes`
|
|
39
|
+
blocks. `@charset` becomes a config key, `@import` statements become imports
|
|
40
|
+
(for cross-language edges), and custom properties become variables.
|
|
41
|
+
|
|
42
|
+
- **Rule sets & at-rule blocks** — `body { … }`, `.header { … }`, `@media`,
|
|
43
|
+
`@keyframes` → classes (named by selector; `@media` carries no name).
|
|
44
|
+
- **Directives** — `@charset` → config key.
|
|
45
|
+
- **Imports** — `@import url("reset.css")` → an import chunk carrying the
|
|
46
|
+
referenced path, so an edge links to the imported stylesheet.
|
|
47
|
+
- **Custom properties** — `--brand: #333;` → variables.
|
|
48
|
+
|
|
49
|
+
## Chunks produced
|
|
50
|
+
|
|
51
|
+
`name` is the selector; `scope` is the ancestor rule-set selectors for a
|
|
52
|
+
nested rule set (CSS nesting), else empty.
|
|
53
|
+
|
|
54
|
+
```css
|
|
55
|
+
body { color: #333; } /* class "body", scope "" */
|
|
56
|
+
.header { background: blue; } /* class ".header", scope "" */
|
|
57
|
+
.card { .title { … } } /* class ".title", scope ".card" */
|
|
58
|
+
@media (max-width: 600px) { … } /* class, unnamed */
|
|
59
|
+
@keyframes slide { … } /* class "slide" */
|
|
60
|
+
@import url("reset.css"); /* import, metadata {module: reset.css} */
|
|
61
|
+
:root { --brand: #333; } /* variable "--brand" */
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Embedded / injected chunks
|
|
65
|
+
|
|
66
|
+
None. CSS does not embed other languages (it is itself embedded by HTML and
|
|
67
|
+
the SFC plugins).
|
|
68
|
+
|
|
69
|
+
## Grammar & dependencies
|
|
70
|
+
|
|
71
|
+
Uses the `tree-sitter-css` grammar. No dependency on other language plugins;
|
|
72
|
+
its `css_nesting_scope` helper is public API that the `scss` and `less`
|
|
73
|
+
plugins reuse.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# rbtr-lang-css
|
|
2
|
+
|
|
3
|
+
CSS support for [rbtr]. Optional plugin — install with
|
|
4
|
+
`pip install rbtr[css]`.
|
|
5
|
+
|
|
6
|
+
[rbtr]: https://github.com/janrito/rbtr/tree/main/packages/rbtr#readme
|
|
7
|
+
|
|
8
|
+
## What it ingests
|
|
9
|
+
|
|
10
|
+
One chunk per top-level rule set, keyed by its selector. A rule set is a
|
|
11
|
+
named collection of property declarations, so it maps to a **class** (the
|
|
12
|
+
same shape SQL's `CREATE TABLE` takes) — as do `@media` and `@keyframes`
|
|
13
|
+
blocks. `@charset` becomes a config key, `@import` statements become imports
|
|
14
|
+
(for cross-language edges), and custom properties become variables.
|
|
15
|
+
|
|
16
|
+
- **Rule sets & at-rule blocks** — `body { … }`, `.header { … }`, `@media`,
|
|
17
|
+
`@keyframes` → classes (named by selector; `@media` carries no name).
|
|
18
|
+
- **Directives** — `@charset` → config key.
|
|
19
|
+
- **Imports** — `@import url("reset.css")` → an import chunk carrying the
|
|
20
|
+
referenced path, so an edge links to the imported stylesheet.
|
|
21
|
+
- **Custom properties** — `--brand: #333;` → variables.
|
|
22
|
+
|
|
23
|
+
## Chunks produced
|
|
24
|
+
|
|
25
|
+
`name` is the selector; `scope` is the ancestor rule-set selectors for a
|
|
26
|
+
nested rule set (CSS nesting), else empty.
|
|
27
|
+
|
|
28
|
+
```css
|
|
29
|
+
body { color: #333; } /* class "body", scope "" */
|
|
30
|
+
.header { background: blue; } /* class ".header", scope "" */
|
|
31
|
+
.card { .title { … } } /* class ".title", scope ".card" */
|
|
32
|
+
@media (max-width: 600px) { … } /* class, unnamed */
|
|
33
|
+
@keyframes slide { … } /* class "slide" */
|
|
34
|
+
@import url("reset.css"); /* import, metadata {module: reset.css} */
|
|
35
|
+
:root { --brand: #333; } /* variable "--brand" */
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Embedded / injected chunks
|
|
39
|
+
|
|
40
|
+
None. CSS does not embed other languages (it is itself embedded by HTML and
|
|
41
|
+
the SFC plugins).
|
|
42
|
+
|
|
43
|
+
## Grammar & dependencies
|
|
44
|
+
|
|
45
|
+
Uses the `tree-sitter-css` grammar. No dependency on other language plugins;
|
|
46
|
+
its `css_nesting_scope` helper is public API that the `scss` and `less`
|
|
47
|
+
plugins reuse.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["uv_build>=0.11.26,<1"]
|
|
3
|
+
build-backend = "uv_build"
|
|
4
|
+
|
|
5
|
+
[tool.uv.build-backend]
|
|
6
|
+
module-name = "rbtr_lang_css"
|
|
7
|
+
|
|
8
|
+
[tool.uv.sources.rbtr]
|
|
9
|
+
workspace = true
|
|
10
|
+
|
|
11
|
+
[project]
|
|
12
|
+
name = "rbtr-lang-css"
|
|
13
|
+
version = "2026.9.0-dev1"
|
|
14
|
+
description = "rbtr — CSS language plugin"
|
|
15
|
+
readme = "README.md"
|
|
16
|
+
license = "MIT"
|
|
17
|
+
license-files = ["LICENSE"]
|
|
18
|
+
keywords = [
|
|
19
|
+
"code-search",
|
|
20
|
+
"code-index",
|
|
21
|
+
"tree-sitter",
|
|
22
|
+
"static-analysis",
|
|
23
|
+
"semantic-search",
|
|
24
|
+
"developer-tools",
|
|
25
|
+
"css",
|
|
26
|
+
]
|
|
27
|
+
classifiers = [
|
|
28
|
+
"Development Status :: 4 - Beta",
|
|
29
|
+
"Intended Audience :: Developers",
|
|
30
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
31
|
+
"Programming Language :: Python :: 3.13",
|
|
32
|
+
"Topic :: Software Development :: Libraries",
|
|
33
|
+
"Topic :: Text Processing :: Indexing",
|
|
34
|
+
"Typing :: Typed",
|
|
35
|
+
]
|
|
36
|
+
requires-python = ">=3.13"
|
|
37
|
+
dependencies = [
|
|
38
|
+
"rbtr==2026.9.0-dev1",
|
|
39
|
+
"tree-sitter-css",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[[project.authors]]
|
|
43
|
+
name = "Alejandro Giacometti"
|
|
44
|
+
email = "alejandro.giacometti@gmail.com"
|
|
45
|
+
|
|
46
|
+
[project.urls]
|
|
47
|
+
Homepage = "https://github.com/janrito/rbtr"
|
|
48
|
+
Repository = "https://github.com/janrito/rbtr"
|
|
49
|
+
Documentation = "https://github.com/janrito/rbtr/tree/main/packages/rbtr-lang-css#readme"
|
|
50
|
+
Issues = "https://github.com/janrito/rbtr/issues"
|
|
51
|
+
Changelog = "https://github.com/janrito/rbtr/releases"
|
|
52
|
+
|
|
53
|
+
[project.entry-points."rbtr.languages"]
|
|
54
|
+
css = "rbtr_lang_css.plugin:css"
|
|
55
|
+
|
|
56
|
+
[dependency-groups]
|
|
57
|
+
dev = ["rbtr[test]"]
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["uv_build>=0.11.26,<1"]
|
|
3
|
+
build-backend = "uv_build"
|
|
4
|
+
|
|
5
|
+
[tool.uv.build-backend]
|
|
6
|
+
module-name = "rbtr_lang_css"
|
|
7
|
+
# No source-exclude: the plugin's tests, samples, and snapshots ship
|
|
8
|
+
# with the wheel (they are the language's golden record), and css.scm
|
|
9
|
+
# ships as package data.
|
|
10
|
+
|
|
11
|
+
[project]
|
|
12
|
+
name = "rbtr-lang-css"
|
|
13
|
+
version = "2026.9.0-dev1"
|
|
14
|
+
description = "rbtr — CSS language plugin"
|
|
15
|
+
readme = "README.md"
|
|
16
|
+
license = "MIT"
|
|
17
|
+
license-files = ["LICENSE"]
|
|
18
|
+
authors = [
|
|
19
|
+
{ name = "Alejandro Giacometti", email = "alejandro.giacometti@gmail.com" },
|
|
20
|
+
]
|
|
21
|
+
keywords = [
|
|
22
|
+
"code-search",
|
|
23
|
+
"code-index",
|
|
24
|
+
"tree-sitter",
|
|
25
|
+
"static-analysis",
|
|
26
|
+
"semantic-search",
|
|
27
|
+
"developer-tools",
|
|
28
|
+
"css",
|
|
29
|
+
]
|
|
30
|
+
classifiers = [
|
|
31
|
+
"Development Status :: 4 - Beta",
|
|
32
|
+
"Intended Audience :: Developers",
|
|
33
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
34
|
+
"Programming Language :: Python :: 3.13",
|
|
35
|
+
"Topic :: Software Development :: Libraries",
|
|
36
|
+
"Topic :: Text Processing :: Indexing",
|
|
37
|
+
"Typing :: Typed",
|
|
38
|
+
]
|
|
39
|
+
requires-python = ">=3.13"
|
|
40
|
+
dependencies = [
|
|
41
|
+
"rbtr==2026.9.0-dev1",
|
|
42
|
+
"tree-sitter-css",
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
[project.urls]
|
|
46
|
+
Homepage = "https://github.com/janrito/rbtr"
|
|
47
|
+
Repository = "https://github.com/janrito/rbtr"
|
|
48
|
+
Documentation = "https://github.com/janrito/rbtr/tree/main/packages/rbtr-lang-css#readme"
|
|
49
|
+
Issues = "https://github.com/janrito/rbtr/issues"
|
|
50
|
+
Changelog = "https://github.com/janrito/rbtr/releases"
|
|
51
|
+
|
|
52
|
+
[project.entry-points."rbtr.languages"]
|
|
53
|
+
# The value resolves to the language's `LanguageRegistration` (named by its
|
|
54
|
+
# id) — see the rbtr ARCHITECTURE "External plugins" note.
|
|
55
|
+
css = "rbtr_lang_css.plugin:css"
|
|
56
|
+
|
|
57
|
+
[tool.uv.sources]
|
|
58
|
+
rbtr = { workspace = true }
|
|
59
|
+
|
|
60
|
+
[dependency-groups]
|
|
61
|
+
dev = ["rbtr[test]"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""CSS language plugin package."""
|
|
@@ -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
|
|
@@ -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, unnamed, scope ""
|
|
14
|
+
@keyframes slide { ... } → class "slide", scope ""
|
|
15
|
+
@charset "utf-8"; → config_key, unnamed
|
|
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)
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
[
|
|
2
|
+
"css.css::@import \"partials/dark.css\"; -> partials/dark.css::.greeting--dark [imports]",
|
|
3
|
+
"css.css::@import \"theme.css\"; -> theme.css::--greeting-color [imports]",
|
|
4
|
+
"css.css::@import \"theme.css\"; -> theme.css:::root [imports]",
|
|
5
|
+
"css.css::@import url(\"reset.css\"); -> reset.css::* [imports]",
|
|
6
|
+
"partials/dark.css::@import \"palette.css\"; -> partials/palette.css::--ink [imports]",
|
|
7
|
+
"partials/dark.css::@import \"palette.css\"; -> partials/palette.css:::root [imports]"
|
|
8
|
+
]
|
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"blob_sha": "sha1",
|
|
4
|
+
"file_path": "css.css",
|
|
5
|
+
"kind": "comment",
|
|
6
|
+
"name": "",
|
|
7
|
+
"scope": "",
|
|
8
|
+
"language": "css",
|
|
9
|
+
"file_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
|
+
"id": "9a0889317229f181"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"blob_sha": "sha1",
|
|
23
|
+
"file_path": "css.css",
|
|
24
|
+
"kind": "config_key",
|
|
25
|
+
"name": "",
|
|
26
|
+
"scope": "",
|
|
27
|
+
"language": "css",
|
|
28
|
+
"file_language": "css",
|
|
29
|
+
"content": "@charset \"UTF-8\";",
|
|
30
|
+
"line_start": 6,
|
|
31
|
+
"line_end": 6,
|
|
32
|
+
"metadata": {
|
|
33
|
+
"module": "",
|
|
34
|
+
"names": "",
|
|
35
|
+
"dots": "",
|
|
36
|
+
"language_hint": ""
|
|
37
|
+
},
|
|
38
|
+
"id": "201b42fa975466e2"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"blob_sha": "sha1",
|
|
42
|
+
"file_path": "css.css",
|
|
43
|
+
"kind": "import",
|
|
44
|
+
"name": "@import url(\"reset.css\");",
|
|
45
|
+
"scope": "",
|
|
46
|
+
"language": "css",
|
|
47
|
+
"file_language": "css",
|
|
48
|
+
"content": "@import url(\"reset.css\");",
|
|
49
|
+
"line_start": 8,
|
|
50
|
+
"line_end": 8,
|
|
51
|
+
"metadata": {
|
|
52
|
+
"module": "reset.css",
|
|
53
|
+
"names": "",
|
|
54
|
+
"dots": "",
|
|
55
|
+
"language_hint": ""
|
|
56
|
+
},
|
|
57
|
+
"id": "cbf97254020d81bd"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"blob_sha": "sha1",
|
|
61
|
+
"file_path": "css.css",
|
|
62
|
+
"kind": "import",
|
|
63
|
+
"name": "@import \"theme.css\";",
|
|
64
|
+
"scope": "",
|
|
65
|
+
"language": "css",
|
|
66
|
+
"file_language": "css",
|
|
67
|
+
"content": "@import \"theme.css\";",
|
|
68
|
+
"line_start": 9,
|
|
69
|
+
"line_end": 9,
|
|
70
|
+
"metadata": {
|
|
71
|
+
"module": "theme.css",
|
|
72
|
+
"names": "",
|
|
73
|
+
"dots": "",
|
|
74
|
+
"language_hint": ""
|
|
75
|
+
},
|
|
76
|
+
"id": "832cecbb8b3403fe"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"blob_sha": "sha1",
|
|
80
|
+
"file_path": "css.css",
|
|
81
|
+
"kind": "class",
|
|
82
|
+
"name": ":root",
|
|
83
|
+
"scope": "",
|
|
84
|
+
"language": "css",
|
|
85
|
+
"file_language": "css",
|
|
86
|
+
"content": ":root {\n --greeting-color: #333;\n}",
|
|
87
|
+
"line_start": 11,
|
|
88
|
+
"line_end": 13,
|
|
89
|
+
"metadata": {
|
|
90
|
+
"module": "",
|
|
91
|
+
"names": "",
|
|
92
|
+
"dots": "",
|
|
93
|
+
"language_hint": ""
|
|
94
|
+
},
|
|
95
|
+
"id": "e62985770721d590"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"blob_sha": "sha1",
|
|
99
|
+
"file_path": "css.css",
|
|
100
|
+
"kind": "variable",
|
|
101
|
+
"name": "--greeting-color",
|
|
102
|
+
"scope": ":root",
|
|
103
|
+
"language": "css",
|
|
104
|
+
"file_language": "css",
|
|
105
|
+
"content": "--greeting-color: #333;",
|
|
106
|
+
"line_start": 12,
|
|
107
|
+
"line_end": 12,
|
|
108
|
+
"metadata": {
|
|
109
|
+
"module": "",
|
|
110
|
+
"names": "",
|
|
111
|
+
"dots": "",
|
|
112
|
+
"language_hint": ""
|
|
113
|
+
},
|
|
114
|
+
"id": "b90cc82662414f51"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"blob_sha": "sha1",
|
|
118
|
+
"file_path": "css.css",
|
|
119
|
+
"kind": "class",
|
|
120
|
+
"name": ".greeter",
|
|
121
|
+
"scope": "",
|
|
122
|
+
"language": "css",
|
|
123
|
+
"file_language": "css",
|
|
124
|
+
"content": ".greeter {\n color: var(--greeting-color);\n font-weight: bold;\n .greeting-label {\n text-transform: uppercase;\n }\n}",
|
|
125
|
+
"line_start": 15,
|
|
126
|
+
"line_end": 21,
|
|
127
|
+
"metadata": {
|
|
128
|
+
"module": "",
|
|
129
|
+
"names": "",
|
|
130
|
+
"dots": "",
|
|
131
|
+
"language_hint": ""
|
|
132
|
+
},
|
|
133
|
+
"id": "0e53178978ed3263"
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"blob_sha": "sha1",
|
|
137
|
+
"file_path": "css.css",
|
|
138
|
+
"kind": "class",
|
|
139
|
+
"name": ".greeting-label",
|
|
140
|
+
"scope": ".greeter",
|
|
141
|
+
"language": "css",
|
|
142
|
+
"file_language": "css",
|
|
143
|
+
"content": ".greeting-label {\n text-transform: uppercase;\n }",
|
|
144
|
+
"line_start": 18,
|
|
145
|
+
"line_end": 20,
|
|
146
|
+
"metadata": {
|
|
147
|
+
"module": "",
|
|
148
|
+
"names": "",
|
|
149
|
+
"dots": "",
|
|
150
|
+
"language_hint": ""
|
|
151
|
+
},
|
|
152
|
+
"id": "32e37f98d1abb442"
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
"blob_sha": "sha1",
|
|
156
|
+
"file_path": "css.css",
|
|
157
|
+
"kind": "class",
|
|
158
|
+
"name": "",
|
|
159
|
+
"scope": "",
|
|
160
|
+
"language": "css",
|
|
161
|
+
"file_language": "css",
|
|
162
|
+
"content": "@media (max-width: 600px) {\n .greeter {\n font-size: 14px;\n }\n}",
|
|
163
|
+
"line_start": 23,
|
|
164
|
+
"line_end": 27,
|
|
165
|
+
"metadata": {
|
|
166
|
+
"module": "",
|
|
167
|
+
"names": "",
|
|
168
|
+
"dots": "",
|
|
169
|
+
"language_hint": ""
|
|
170
|
+
},
|
|
171
|
+
"id": "139fd08b20e2104e"
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
"blob_sha": "sha1",
|
|
175
|
+
"file_path": "css.css",
|
|
176
|
+
"kind": "class",
|
|
177
|
+
"name": ".greeter",
|
|
178
|
+
"scope": "",
|
|
179
|
+
"language": "css",
|
|
180
|
+
"file_language": "css",
|
|
181
|
+
"content": ".greeter {\n font-size: 14px;\n }",
|
|
182
|
+
"line_start": 24,
|
|
183
|
+
"line_end": 26,
|
|
184
|
+
"metadata": {
|
|
185
|
+
"module": "",
|
|
186
|
+
"names": "",
|
|
187
|
+
"dots": "",
|
|
188
|
+
"language_hint": ""
|
|
189
|
+
},
|
|
190
|
+
"id": "bc40befb59eb6693"
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
"blob_sha": "sha1",
|
|
194
|
+
"file_path": "css.css",
|
|
195
|
+
"kind": "class",
|
|
196
|
+
"name": "greeting-fade",
|
|
197
|
+
"scope": "",
|
|
198
|
+
"language": "css",
|
|
199
|
+
"file_language": "css",
|
|
200
|
+
"content": "@keyframes greeting-fade {\n from {\n opacity: 0;\n }\n to {\n opacity: 1;\n }\n}",
|
|
201
|
+
"line_start": 29,
|
|
202
|
+
"line_end": 36,
|
|
203
|
+
"metadata": {
|
|
204
|
+
"module": "",
|
|
205
|
+
"names": "",
|
|
206
|
+
"dots": "",
|
|
207
|
+
"language_hint": ""
|
|
208
|
+
},
|
|
209
|
+
"id": "ac5a0c0be7138359"
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
"blob_sha": "sha1",
|
|
213
|
+
"file_path": "css.css",
|
|
214
|
+
"kind": "import",
|
|
215
|
+
"name": "@import \"partials/dark.css\";",
|
|
216
|
+
"scope": "",
|
|
217
|
+
"language": "css",
|
|
218
|
+
"file_language": "css",
|
|
219
|
+
"content": "@import \"partials/dark.css\";",
|
|
220
|
+
"line_start": 38,
|
|
221
|
+
"line_end": 38,
|
|
222
|
+
"metadata": {
|
|
223
|
+
"module": "partials/dark.css",
|
|
224
|
+
"names": "",
|
|
225
|
+
"dots": "",
|
|
226
|
+
"language_hint": ""
|
|
227
|
+
},
|
|
228
|
+
"id": "8b2906e0d46c28e6"
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
"blob_sha": "sha1",
|
|
232
|
+
"file_path": "partials/dark.css",
|
|
233
|
+
"kind": "comment",
|
|
234
|
+
"name": "",
|
|
235
|
+
"scope": "",
|
|
236
|
+
"language": "css",
|
|
237
|
+
"file_language": "css",
|
|
238
|
+
"content": "/* Imported by css.css. Imports its own sibling by bare name, which only\n resolves relative to this directory. */",
|
|
239
|
+
"line_start": 1,
|
|
240
|
+
"line_end": 2,
|
|
241
|
+
"metadata": {
|
|
242
|
+
"module": "",
|
|
243
|
+
"names": "",
|
|
244
|
+
"dots": "",
|
|
245
|
+
"language_hint": ""
|
|
246
|
+
},
|
|
247
|
+
"id": "30e3b78720e6932b"
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
"blob_sha": "sha1",
|
|
251
|
+
"file_path": "partials/dark.css",
|
|
252
|
+
"kind": "import",
|
|
253
|
+
"name": "@import \"palette.css\";",
|
|
254
|
+
"scope": "",
|
|
255
|
+
"language": "css",
|
|
256
|
+
"file_language": "css",
|
|
257
|
+
"content": "@import \"palette.css\";",
|
|
258
|
+
"line_start": 3,
|
|
259
|
+
"line_end": 3,
|
|
260
|
+
"metadata": {
|
|
261
|
+
"module": "palette.css",
|
|
262
|
+
"names": "",
|
|
263
|
+
"dots": "",
|
|
264
|
+
"language_hint": ""
|
|
265
|
+
},
|
|
266
|
+
"id": "11011a8ec682e572"
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
"blob_sha": "sha1",
|
|
270
|
+
"file_path": "partials/dark.css",
|
|
271
|
+
"kind": "class",
|
|
272
|
+
"name": ".greeting--dark",
|
|
273
|
+
"scope": "",
|
|
274
|
+
"language": "css",
|
|
275
|
+
"file_language": "css",
|
|
276
|
+
"content": ".greeting--dark {\n color: var(--ink);\n}",
|
|
277
|
+
"line_start": 5,
|
|
278
|
+
"line_end": 7,
|
|
279
|
+
"metadata": {
|
|
280
|
+
"module": "",
|
|
281
|
+
"names": "",
|
|
282
|
+
"dots": "",
|
|
283
|
+
"language_hint": ""
|
|
284
|
+
},
|
|
285
|
+
"id": "7beceb826171befc"
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
"blob_sha": "sha1",
|
|
289
|
+
"file_path": "partials/palette.css",
|
|
290
|
+
"kind": "class",
|
|
291
|
+
"name": ":root",
|
|
292
|
+
"scope": "",
|
|
293
|
+
"language": "css",
|
|
294
|
+
"file_language": "css",
|
|
295
|
+
"content": "/* Imported by partials/dark.css as a bare sibling. */\n:root {\n --ink: #eeeeee;\n}",
|
|
296
|
+
"line_start": 1,
|
|
297
|
+
"line_end": 4,
|
|
298
|
+
"metadata": {
|
|
299
|
+
"module": "",
|
|
300
|
+
"names": "",
|
|
301
|
+
"dots": "",
|
|
302
|
+
"language_hint": ""
|
|
303
|
+
},
|
|
304
|
+
"id": "acdf532d0945bb9d"
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
"blob_sha": "sha1",
|
|
308
|
+
"file_path": "partials/palette.css",
|
|
309
|
+
"kind": "variable",
|
|
310
|
+
"name": "--ink",
|
|
311
|
+
"scope": ":root",
|
|
312
|
+
"language": "css",
|
|
313
|
+
"file_language": "css",
|
|
314
|
+
"content": "--ink: #eeeeee;",
|
|
315
|
+
"line_start": 3,
|
|
316
|
+
"line_end": 3,
|
|
317
|
+
"metadata": {
|
|
318
|
+
"module": "",
|
|
319
|
+
"names": "",
|
|
320
|
+
"dots": "",
|
|
321
|
+
"language_hint": ""
|
|
322
|
+
},
|
|
323
|
+
"id": "ec54218724ce0cb6"
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
"blob_sha": "sha1",
|
|
327
|
+
"file_path": "reset.css",
|
|
328
|
+
"kind": "class",
|
|
329
|
+
"name": "*",
|
|
330
|
+
"scope": "",
|
|
331
|
+
"language": "css",
|
|
332
|
+
"file_language": "css",
|
|
333
|
+
"content": "* {\n margin: 0;\n}",
|
|
334
|
+
"line_start": 1,
|
|
335
|
+
"line_end": 3,
|
|
336
|
+
"metadata": {
|
|
337
|
+
"module": "",
|
|
338
|
+
"names": "",
|
|
339
|
+
"dots": "",
|
|
340
|
+
"language_hint": ""
|
|
341
|
+
},
|
|
342
|
+
"id": "f3d13f9312e11df2"
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
"blob_sha": "sha1",
|
|
346
|
+
"file_path": "theme.css",
|
|
347
|
+
"kind": "class",
|
|
348
|
+
"name": ":root",
|
|
349
|
+
"scope": "",
|
|
350
|
+
"language": "css",
|
|
351
|
+
"file_language": "css",
|
|
352
|
+
"content": ":root {\n --greeting-color: #333;\n}",
|
|
353
|
+
"line_start": 1,
|
|
354
|
+
"line_end": 3,
|
|
355
|
+
"metadata": {
|
|
356
|
+
"module": "",
|
|
357
|
+
"names": "",
|
|
358
|
+
"dots": "",
|
|
359
|
+
"language_hint": ""
|
|
360
|
+
},
|
|
361
|
+
"id": "53ac44be42ab8233"
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
"blob_sha": "sha1",
|
|
365
|
+
"file_path": "theme.css",
|
|
366
|
+
"kind": "variable",
|
|
367
|
+
"name": "--greeting-color",
|
|
368
|
+
"scope": ":root",
|
|
369
|
+
"language": "css",
|
|
370
|
+
"file_language": "css",
|
|
371
|
+
"content": "--greeting-color: #333;",
|
|
372
|
+
"line_start": 2,
|
|
373
|
+
"line_end": 2,
|
|
374
|
+
"metadata": {
|
|
375
|
+
"module": "",
|
|
376
|
+
"names": "",
|
|
377
|
+
"dots": "",
|
|
378
|
+
"language_hint": ""
|
|
379
|
+
},
|
|
380
|
+
"id": "dfc190708e8af07c"
|
|
381
|
+
}
|
|
382
|
+
]
|
|
@@ -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,38 @@
|
|
|
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
|
+
}
|
|
37
|
+
|
|
38
|
+
@import "partials/dark.css";
|
|
@@ -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.domain.models import ChunkKind
|
|
12
|
+
from rbtr.git import FileEntry
|
|
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.domain.models import Chunk, ChunkKind, Edge
|
|
16
|
+
from rbtr.git import FileEntry
|
|
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
|