Skip to content

Commit 1996ed6

Browse files
committed
Add testcase
1 parent 4f6cc08 commit 1996ed6

5 files changed

Lines changed: 202 additions & 0 deletions

libs/extractor/src/lib.rs

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13925,6 +13925,103 @@ export const Card = () => (
1392513925
<Box styleOrder={5} className={`${enabled ? 'text-green-500' : 'text-blue-500'} p-4`}>
1392613926
hello
1392713927
</Box>
13928+
"#,
13929+
ExtractOption {
13930+
package: "@devup-ui/core".to_string(),
13931+
css_dir: "@devup-ui/core".to_string(),
13932+
single_css: true,
13933+
import_main_css: false,
13934+
import_aliases: HashMap::new()
13935+
}
13936+
)
13937+
.unwrap()
13938+
));
13939+
}
13940+
13941+
#[test]
13942+
#[serial]
13943+
fn style_order_coverage_additional() {
13944+
// Coverage: visit.rs:241 — non-object 2nd argument in call expression
13945+
// When 2nd arg is a variable (not ObjectExpression), pre-scan should return None
13946+
reset_class_map();
13947+
reset_file_map();
13948+
assert_debug_snapshot!(ToBTreeSet::from(
13949+
extract(
13950+
"test.mjs",
13951+
r#"import { jsx as e } from "react/jsx-runtime";
13952+
import { Box as o } from "@devup-ui/react";
13953+
function c() {
13954+
return e(o, someVariable);
13955+
}
13956+
export { c as Lib };"#,
13957+
ExtractOption {
13958+
package: "@devup-ui/react".to_string(),
13959+
css_dir: "@devup-ui/react".to_string(),
13960+
single_css: true,
13961+
import_main_css: false,
13962+
import_aliases: HashMap::new()
13963+
}
13964+
)
13965+
.unwrap()
13966+
));
13967+
13968+
// Coverage: visit.rs:492 — non-conditional _ branch in JSX with static styleOrder
13969+
// Ensures the `_ =>` (non-Conditional) match arm in visit_jsx_element is hit
13970+
// with an explicit static styleOrder value
13971+
reset_class_map();
13972+
reset_file_map();
13973+
assert_debug_snapshot!(ToBTreeSet::from(
13974+
extract(
13975+
"test.jsx",
13976+
r#"import {Box} from '@devup-ui/core'
13977+
<Box styleOrder={5} bg="red" p={4} />
13978+
"#,
13979+
ExtractOption {
13980+
package: "@devup-ui/core".to_string(),
13981+
css_dir: "@devup-ui/core".to_string(),
13982+
single_css: true,
13983+
import_main_css: false,
13984+
import_aliases: HashMap::new()
13985+
}
13986+
)
13987+
.unwrap()
13988+
));
13989+
13990+
// Coverage: visit.rs:259,262 — ParsedStyleOrder::None fallback with static styleOrder
13991+
// via call expression where pre-scan finds styleOrder=5 (static), so extract_style_from_expression
13992+
// also returns style_order=Some(5), but the pre-scan already resolved it to Static(5)
13993+
// This ensures the full `ParsedStyleOrder::None => match style_order` path in visit_call_expression
13994+
reset_class_map();
13995+
reset_file_map();
13996+
assert_debug_snapshot!(ToBTreeSet::from(
13997+
extract(
13998+
"test.mjs",
13999+
r#"import { jsx as e } from "react/jsx-runtime";
14000+
import { Box as o } from "@devup-ui/react";
14001+
function c() {
14002+
return e(o, { styleOrder: 5, bg: "red", p: 4 });
14003+
}
14004+
export { c as Lib };"#,
14005+
ExtractOption {
14006+
package: "@devup-ui/react".to_string(),
14007+
css_dir: "@devup-ui/react".to_string(),
14008+
single_css: true,
14009+
import_main_css: false,
14010+
import_aliases: HashMap::new()
14011+
}
14012+
)
14013+
.unwrap()
14014+
));
14015+
14016+
// Coverage: lib.rs:55 — MemberExpression clone_in with conditional styleOrder
14017+
// (also verified in style_order_conditional_coverage but included here for explicit coverage)
14018+
reset_class_map();
14019+
reset_file_map();
14020+
assert_debug_snapshot!(ToBTreeSet::from(
14021+
extract(
14022+
"test.jsx",
14023+
r#"import {Box} from '@devup-ui/core'
14024+
<Box styleOrder={a ? 1 : 2} bg={theme.colors.primary} />
1392814025
"#,
1392914026
ExtractOption {
1393014027
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.jsx\",\nr#\"import {Box} from '@devup-ui/core'\n<Box styleOrder={5} bg=\"red\" p={4} />\n\"#,\nExtractOption\n{\n package: \"@devup-ui/core\".to_string(), css_dir:\n \"@devup-ui/core\".to_string(), single_css: true, import_main_css: false,\n import_aliases: HashMap::new()\n}).unwrap())"
4+
---
5+
ToBTreeSet {
6+
styles: {
7+
Static(
8+
ExtractStaticStyle {
9+
property: "background",
10+
value: "red",
11+
level: 0,
12+
selector: None,
13+
style_order: Some(
14+
5,
15+
),
16+
layer: None,
17+
},
18+
),
19+
Static(
20+
ExtractStaticStyle {
21+
property: "padding",
22+
value: "16px",
23+
level: 0,
24+
selector: None,
25+
style_order: Some(
26+
5,
27+
),
28+
layer: None,
29+
},
30+
),
31+
},
32+
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a b\" />;\n",
33+
}
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.mjs\",\nr#\"import { jsx as e } from \"react/jsx-runtime\";\nimport { Box as o } from \"@devup-ui/react\";\nfunction c() {\n return e(o, { styleOrder: 5, bg: \"red\", p: 4 });\n}\nexport { c as Lib };\"#,\nExtractOption\n{\n package: \"@devup-ui/react\".to_string(), css_dir:\n \"@devup-ui/react\".to_string(), single_css: true, import_main_css: false,\n import_aliases: HashMap::new()\n}).unwrap())"
4+
---
5+
ToBTreeSet {
6+
styles: {
7+
Static(
8+
ExtractStaticStyle {
9+
property: "background",
10+
value: "red",
11+
level: 0,
12+
selector: None,
13+
style_order: Some(
14+
5,
15+
),
16+
layer: None,
17+
},
18+
),
19+
Static(
20+
ExtractStaticStyle {
21+
property: "padding",
22+
value: "16px",
23+
level: 0,
24+
selector: None,
25+
style_order: Some(
26+
5,
27+
),
28+
layer: None,
29+
},
30+
),
31+
},
32+
code: "import \"@devup-ui/react/devup-ui.css\";\nimport { jsx as e } from \"react/jsx-runtime\";\nfunction c() {\n\treturn e(\"div\", { className: \"a b\" });\n}\nexport { c as Lib };\n",
33+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
source: libs/extractor/src/lib.rs
3+
expression: "ToBTreeSet::from(extract(\"test.jsx\",\nr#\"import {Box} from '@devup-ui/core'\n<Box styleOrder={a ? 1 : 2} bg={theme.colors.primary} />\n\"#,\nExtractOption\n{\n package: \"@devup-ui/core\".to_string(), css_dir:\n \"@devup-ui/core\".to_string(), single_css: true, import_main_css: false,\n import_aliases: HashMap::new()\n}).unwrap())"
4+
---
5+
ToBTreeSet {
6+
styles: {
7+
Dynamic(
8+
ExtractDynamicStyle {
9+
property: "background",
10+
level: 0,
11+
identifier: "theme.colors.primary",
12+
selector: None,
13+
style_order: Some(
14+
1,
15+
),
16+
},
17+
),
18+
Dynamic(
19+
ExtractDynamicStyle {
20+
property: "background",
21+
level: 0,
22+
identifier: "theme.colors.primary",
23+
selector: None,
24+
style_order: Some(
25+
2,
26+
),
27+
},
28+
),
29+
},
30+
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className={a ? \"a\" : \"c\"} style={{ \"--b\": theme.colors.primary }} />;\n",
31+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
source: libs/extractor/src/lib.rs
3+
expression: "ToBTreeSet::from(extract(\"test.mjs\",\nr#\"import { jsx as e } from \"react/jsx-runtime\";\nimport { Box as o } from \"@devup-ui/react\";\nfunction c() {\n return e(o, someVariable);\n}\nexport { c as Lib };\"#,\nExtractOption\n{\n package: \"@devup-ui/react\".to_string(), css_dir:\n \"@devup-ui/react\".to_string(), single_css: true, import_main_css: false,\n import_aliases: HashMap::new()\n}).unwrap())"
4+
---
5+
ToBTreeSet {
6+
styles: {},
7+
code: "import { jsx as e } from \"react/jsx-runtime\";\nfunction c() {\n\treturn e(\"div\", someVariable);\n}\nexport { c as Lib };\n",
8+
}

0 commit comments

Comments
 (0)