Skip to content

Commit 87ebd4b

Browse files
committed
Fix coverage issue
1 parent ffbad17 commit 87ebd4b

File tree

4 files changed

+83
-23
lines changed

4 files changed

+83
-23
lines changed

libs/extractor/src/css_utils.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,11 +470,20 @@ mod tests {
470470
("50%", vec![("color", "red"), ("background", "blue")]),
471471
],
472472
)]
473+
// error case
474+
#[case(
475+
"50% { color: red ; background: blue ",
476+
vec![
477+
],
478+
)]
473479
fn test_keyframes_to_keyframes_style(
474480
#[case] input: &str,
475481
#[case] expected: Vec<(&str, Vec<(&str, &str)>)>,
476482
) {
477483
let styles = keyframes_to_keyframes_style(input);
484+
if styles.len() != expected.len() {
485+
panic!("styles.len() != expected.len()");
486+
}
478487
for (expected_key, expected_styles) in styles.iter() {
479488
let styles = expected_styles;
480489
let mut result: Vec<(&str, &str)> = styles

libs/extractor/src/gen_style.rs

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,25 @@ fn gen_style<'a>(
3232
let mut properties = vec![];
3333
match style {
3434
ExtractStyleProp::Static(st) => {
35-
if let Some(ex) = st.extract() {
36-
match ex {
37-
StyleProperty::ClassName(_) => {}
38-
StyleProperty::Variable {
39-
variable_name,
40-
identifier,
41-
..
42-
} => {
43-
properties.push(ast_builder.object_property_kind_object_property(
44-
SPAN,
45-
PropertyKind::Init,
46-
PropertyKey::StringLiteral(ast_builder.alloc_string_literal(
47-
SPAN,
48-
ast_builder.atom(&variable_name),
49-
None,
50-
)),
51-
ast_builder.expression_identifier(SPAN, ast_builder.atom(&identifier)),
52-
false,
53-
false,
54-
false,
55-
));
56-
}
57-
}
35+
if let Some(StyleProperty::Variable {
36+
variable_name,
37+
identifier,
38+
..
39+
}) = st.extract()
40+
{
41+
properties.push(ast_builder.object_property_kind_object_property(
42+
SPAN,
43+
PropertyKind::Init,
44+
PropertyKey::StringLiteral(ast_builder.alloc_string_literal(
45+
SPAN,
46+
ast_builder.atom(&variable_name),
47+
None,
48+
)),
49+
ast_builder.expression_identifier(SPAN, ast_builder.atom(&identifier)),
50+
false,
51+
false,
52+
false,
53+
));
5854
}
5955
}
6056
ExtractStyleProp::StaticArray(res) => {

libs/extractor/src/lib.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4981,6 +4981,28 @@ keyframes({
49814981
[`50%`]: { opacity: 0.5 },
49824982
[`100%`]: { opacity: 1 }
49834983
})
4984+
"#,
4985+
ExtractOption {
4986+
package: "@devup-ui/core".to_string(),
4987+
css_file: None
4988+
}
4989+
)
4990+
.unwrap()
4991+
));
4992+
}
4993+
#[test]
4994+
#[serial]
4995+
fn extract_wrong_keyframs() {
4996+
reset_class_map();
4997+
assert_debug_snapshot!(ToBTreeSet::from(
4998+
extract(
4999+
"test.tsx",
5000+
r#"import { keyframes } from "@devup-ui/core";
5001+
keyframes({
5002+
from: { opacity: 0 },
5003+
[true]: { opacity: 0.5 },
5004+
to: { opacity: 1, color: dy }
5005+
})
49845006
"#,
49855007
ExtractOption {
49865008
package: "@devup-ui/core".to_string(),
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
source: libs/extractor/src/lib.rs
3+
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import { keyframes } from \"@devup-ui/core\";\nkeyframes({\n from: { opacity: 0 },\n [true]: { opacity: 0.5 },\n to: { opacity: 1 }\n})\n\"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap())"
4+
---
5+
ToBTreeSet {
6+
styles: {
7+
Keyframes(
8+
ExtractKeyframes {
9+
keyframes: {
10+
"from": [
11+
ExtractStaticStyle {
12+
property: "opacity",
13+
value: "0",
14+
level: 0,
15+
selector: None,
16+
style_order: None,
17+
},
18+
],
19+
"to": [
20+
ExtractStaticStyle {
21+
property: "opacity",
22+
value: "1",
23+
level: 0,
24+
selector: None,
25+
style_order: None,
26+
},
27+
],
28+
},
29+
},
30+
),
31+
},
32+
code: "import \"@devup-ui/core/devup-ui.css\";\n\"k0\";\n",
33+
}

0 commit comments

Comments
 (0)