Skip to content

Commit 344a4d4

Browse files
committed
Add testcase
1 parent 6c55753 commit 344a4d4

5 files changed

Lines changed: 231 additions & 0 deletions

libs/extractor/src/lib.rs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4825,6 +4825,66 @@ export default function Card({
48254825
"test.tsx",
48264826
r#"import { Box } from "@devup-ui/core";
48274827
<Box padding={[1,,null][1]} />;
4828+
"#,
4829+
ExtractOption {
4830+
package: "@devup-ui/core".to_string(),
4831+
css_dir: "@devup-ui/core".to_string(),
4832+
single_css: true,
4833+
import_main_css: false,
4834+
import_aliases: HashMap::new()
4835+
}
4836+
)
4837+
.unwrap()
4838+
));
4839+
4840+
// Array with spread + numeric index (spread captured, element found after spread)
4841+
reset_class_map();
4842+
reset_file_map();
4843+
assert_debug_snapshot!(ToBTreeSet::from(
4844+
extract(
4845+
"test.tsx",
4846+
r#"import { Flex } from "@devup-ui/core";
4847+
<Flex opacity={[...arr, 1][1]} />;
4848+
"#,
4849+
ExtractOption {
4850+
package: "@devup-ui/core".to_string(),
4851+
css_dir: "@devup-ui/core".to_string(),
4852+
single_css: true,
4853+
import_main_css: false,
4854+
import_aliases: HashMap::new()
4855+
}
4856+
)
4857+
.unwrap()
4858+
));
4859+
4860+
// Array with spread + numeric index out of range (etc Some fallback)
4861+
reset_class_map();
4862+
reset_file_map();
4863+
assert_debug_snapshot!(ToBTreeSet::from(
4864+
extract(
4865+
"test.tsx",
4866+
r#"import { Flex } from "@devup-ui/core";
4867+
<Flex opacity={[...arr, 1][5]} />;
4868+
"#,
4869+
ExtractOption {
4870+
package: "@devup-ui/core".to_string(),
4871+
css_dir: "@devup-ui/core".to_string(),
4872+
single_css: true,
4873+
import_main_css: false,
4874+
import_aliases: HashMap::new()
4875+
}
4876+
)
4877+
.unwrap()
4878+
));
4879+
4880+
// Array with spread + dynamic index
4881+
reset_class_map();
4882+
reset_file_map();
4883+
assert_debug_snapshot!(ToBTreeSet::from(
4884+
extract(
4885+
"test.tsx",
4886+
r#"import { Flex } from "@devup-ui/core";
4887+
<Flex opacity={[...arr, 1][idx]} />;
48284888
"#,
48294889
ExtractOption {
48304890
package: "@devup-ui/core".to_string(),
@@ -5052,6 +5112,26 @@ export default function Card({
50525112
)
50535113
.unwrap()
50545114
));
5115+
5116+
// Object with spread + string literal key not matching (etc Some fallback)
5117+
reset_class_map();
5118+
reset_file_map();
5119+
assert_debug_snapshot!(ToBTreeSet::from(
5120+
extract(
5121+
"test.tsx",
5122+
r#"import {Flex} from '@devup-ui/core'
5123+
<Flex opacity={{...rest, a:1, b:0.5}["nonexistent"]} />
5124+
"#,
5125+
ExtractOption {
5126+
package: "@devup-ui/core".to_string(),
5127+
css_dir: "@devup-ui/core".to_string(),
5128+
single_css: true,
5129+
import_main_css: false,
5130+
import_aliases: HashMap::new()
5131+
}
5132+
)
5133+
.unwrap()
5134+
));
50555135
}
50565136

50575137
#[test]
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.tsx\",\nr#\"import { Flex } from \"@devup-ui/core\";\n<Flex opacity={[...arr, 1][1]} />;\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: "display",
10+
value: "flex",
11+
level: 0,
12+
selector: None,
13+
style_order: Some(
14+
0,
15+
),
16+
layer: None,
17+
},
18+
),
19+
Static(
20+
ExtractStaticStyle {
21+
property: "opacity",
22+
value: "1",
23+
level: 0,
24+
selector: None,
25+
style_order: None,
26+
layer: None,
27+
},
28+
),
29+
},
30+
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a b\" />;\n",
31+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
source: libs/extractor/src/lib.rs
3+
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import { Flex } from \"@devup-ui/core\";\n<Flex opacity={[...arr, 1][5]} />;\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: "display",
10+
value: "flex",
11+
level: 0,
12+
selector: None,
13+
style_order: Some(
14+
0,
15+
),
16+
layer: None,
17+
},
18+
),
19+
Dynamic(
20+
ExtractDynamicStyle {
21+
property: "opacity",
22+
level: 0,
23+
identifier: "arr[5]",
24+
selector: None,
25+
style_order: None,
26+
},
27+
),
28+
},
29+
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a b\" style={{ \"--c\": arr[5] }} />;\n",
30+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
source: libs/extractor/src/lib.rs
3+
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import { Flex } from \"@devup-ui/core\";\n<Flex opacity={[...arr, 1][idx]} />;\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: "display",
10+
value: "flex",
11+
level: 0,
12+
selector: None,
13+
style_order: Some(
14+
0,
15+
),
16+
layer: None,
17+
},
18+
),
19+
Static(
20+
ExtractStaticStyle {
21+
property: "opacity",
22+
value: "1",
23+
level: 0,
24+
selector: None,
25+
style_order: None,
26+
layer: None,
27+
},
28+
),
29+
Dynamic(
30+
ExtractDynamicStyle {
31+
property: "opacity",
32+
level: 0,
33+
identifier: "arr[idx]",
34+
selector: None,
35+
style_order: None,
36+
},
37+
),
38+
},
39+
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className={`a ${{\n\t\"0\": \"b\",\n\t\"1\": \"d\"\n}[idx] || \"\"}`} style={{ \"--c\": arr[idx] }} />;\n",
40+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
source: libs/extractor/src/lib.rs
3+
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import {Flex} from '@devup-ui/core'\n <Flex opacity={{...rest, a:1, b:0.5}[\"nonexistent\"]} />\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: "display",
10+
value: "flex",
11+
level: 0,
12+
selector: None,
13+
style_order: Some(
14+
0,
15+
),
16+
layer: None,
17+
},
18+
),
19+
Static(
20+
ExtractStaticStyle {
21+
property: "opacity",
22+
value: ".5",
23+
level: 0,
24+
selector: None,
25+
style_order: None,
26+
layer: None,
27+
},
28+
),
29+
Static(
30+
ExtractStaticStyle {
31+
property: "opacity",
32+
value: "1",
33+
level: 0,
34+
selector: None,
35+
style_order: None,
36+
layer: None,
37+
},
38+
),
39+
Dynamic(
40+
ExtractDynamicStyle {
41+
property: "opacity",
42+
level: 0,
43+
identifier: "rest[`nonexistent`]",
44+
selector: None,
45+
style_order: None,
46+
},
47+
),
48+
},
49+
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className={`a b ${{\n\t\"a\": \"d\",\n\t\"b\": \"e\"\n}[\"nonexistent\"]}`} style={{ \"--c\": rest[`nonexistent`] }} />;\n",
50+
}

0 commit comments

Comments
 (0)