Skip to content

Commit

Permalink
fix: trim unused char
Browse files Browse the repository at this point in the history
  • Loading branch information
togami2864 committed Aug 3, 2024
1 parent fc6fcf7 commit f21a2fe
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
10 changes: 5 additions & 5 deletions crates/biome_css_semantic/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ impl SemanticEventExtractor {
if let Some(property_name) = property.first_child() {
if let Some(value) = property_name.next_sibling() {
self.stash.push_back(SemanticEvent::PropertyDeclaration {
property: property_name.text().to_string(),
value: value.text().to_string(),
property: property_name.text().to_string().to_string(),
value: value.text().to_string().trim().to_string(),
property_range: property_name.text_range(),
value_range: value.text_range(),
});
Expand All @@ -69,10 +69,10 @@ impl SemanticEventExtractor {
match selector {
AnyCssSelector::CssComplexSelector(s) => {
if let Ok(l) = s.left() {
self.add_selector_event(l.text().to_string(), l.range());
self.add_selector_event(l.text(), l.range());
}
if let Ok(r) = s.right() {
self.add_selector_event(r.text().to_string(), r.range());
self.add_selector_event(r.text(), r.range());
}
}
AnyCssSelector::CssCompoundSelector(selector) => {
Expand All @@ -86,7 +86,7 @@ impl SemanticEventExtractor {
self.stash.push_back(SemanticEvent::SelectorDeclaration {
name,
range,
specificity: Specificity(0, 0, 0), // TODO: Implement calculate_specificity
specificity: Specificity(0, 0, 0), // TODO: Implement this
});
}

Expand Down
41 changes: 40 additions & 1 deletion crates/biome_css_semantic/src/semantic_model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,46 @@ mod tests {
#[test]
fn test_simple_ruleset() {
let parse = parse_css(
r#"a { b, c { color: pink; } }"#,
r#"p {
font-family: verdana;
font-size: 20px;
}"#,
CssParserOptions::default(),
);

let root = parse.tree();
let model = super::semantic_model(&root);
let rule = model.rules().first().unwrap();

assert_eq!(rule.selectors.len(), 1);
assert_eq!(rule.declarations.len(), 2);
}
#[test]
fn test_nested_selector() {
let parse = parse_css(
r#".parent {
color: blue;
.child {
color: red;
}
}"#,
CssParserOptions::default(),
);

let root = parse.tree();
let model = super::semantic_model(&root);
let rule = model.rules().first().unwrap();

assert_eq!(rule.selectors.len(), 1);
assert_eq!(rule.declarations.len(), 1);
assert_eq!(rule.children.len(), 1);
}

#[test]
fn debug() {
let parse = parse_css(
r#"[a="b"i], [ a="b"i], [ a ="b"i], [ a = "b"i], [ a = "b" i], [ a = "b" i ] {}"#,
CssParserOptions::default(),
);

Expand Down
2 changes: 1 addition & 1 deletion crates/biome_css_semantic/src/semantic_model/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ pub struct Selector {
pub specificity: Specificity,
}

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
pub struct Specificity(pub u32, pub u32, pub u32);

0 comments on commit f21a2fe

Please sign in to comment.