Skip to content

Commit df0e94b

Browse files
committed
Fix test
1 parent b30c6d4 commit df0e94b

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

libs/extractor/src/css_utils.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -350,14 +350,9 @@ pub fn css_to_style(
350350
}
351351
}
352352

353-
if selector_idx < parts.len() {
354-
let (props, sel) = parts.split_at(selector_idx);
355-
(props.join(";"), sel.join(";"))
356-
} else {
357-
// All parts contain ':', so treat the last one as selector
358-
let (props, sel) = parts.split_at(parts.len() - 1);
359-
(props.join(";"), sel.join(";"))
360-
}
353+
// Math.min
354+
let (props, sel) = parts.split_at(parts.len().min(selector_idx));
355+
(props.join(";"), sel.join(";"))
361356
} else {
362357
("".to_string(), before_brace.to_string())
363358
};
@@ -863,6 +858,13 @@ mod tests {
863858
#[case("`width: ${func(1)}px;`", vec![("width", "`${func(1)}px`", None)])]
864859
#[case("`width: ${func(1)}${2}px;`", vec![("width", "`${func(1)}${2}px`", None)])]
865860
#[case("`width: ${1}${2}px;`", vec![("width", "12px", None)])]
861+
// wrong cases
862+
#[case(
863+
"`@media (min-width: 768px) {
864+
& {
865+
`",
866+
vec![]
867+
)]
866868
fn test_css_to_style_literal(
867869
#[case] input: &str,
868870
#[case] expected: Vec<(&str, &str, Option<StyleSelector>)>,

0 commit comments

Comments
 (0)