Skip to content

Commit

Permalink
chore: match css property
Browse files Browse the repository at this point in the history
  • Loading branch information
ilevyor committed Mar 22, 2024
1 parent c8f9160 commit 7b153a5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
22 changes: 22 additions & 0 deletions crates/core/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12725,3 +12725,25 @@ fn go_package_type() {
})
.unwrap();
}

#[test]
fn css_property_value() {
run_test_match(TestArg {
pattern: r#"
|language css
|
|`var($a)`
|"#
.trim_margin()
.unwrap(),
source: r#"
|#some-id {
| some-property: 5px;
| color: var(--red)
| }
|"#
.trim_margin()
.unwrap(),
})
.unwrap();
}
22 changes: 21 additions & 1 deletion crates/language/src/css.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Language for Css {
"CSS"
}
fn snippet_context_strings(&self) -> &[(&'static str, &'static str)] {
&[("", ""), ("GRIT_BLOCK { ", " }")]
&[("", ""), ("GRIT_BLOCK { ", " }"), ("GRIT_BLOCK { GRIT_PROPERTY: ", " }")]
}

fn node_types(&self) -> &[Vec<Field>] {
Expand All @@ -68,3 +68,23 @@ impl Language for Css {
id == self.comment_sort
}
}


#[cfg(test)]
mod tests {
use super::*;
use marzano_util::print_node::print_node;
use crate::language::nodes_from_indices;

#[test]
fn import_variable() {
let snippet = r#"var(--red)"#;
let lang = Css::new(None);
let mut parser = tree_sitter::Parser::new().unwrap();
parser.set_language(lang.get_ts_language()).unwrap();
let snippets = lang.parse_snippet_contexts(snippet);
let nodes = nodes_from_indices(&snippets);
assert!(!nodes.is_empty());
print_node(&nodes[0].node);
}
}

0 comments on commit 7b153a5

Please sign in to comment.