stylex_transform/shared/utils/css/tests/
split_value_test.rs1#[cfg(test)]
2mod ensure_css_values_are_split_correctly {
3 use crate::shared::utils::css::common::split_value;
4
5 #[test]
6 fn simple_space_separated_numbers() {
7 assert_eq!(
8 split_value(Some("0 1 2 3")),
9 (
10 "0".into(),
11 Some("1".into()),
12 Some("2".into()),
13 Some("3".into())
14 )
15 );
16 }
17
18 #[test]
19 fn simple_space_separated_lengths() {
20 assert_eq!(
21 split_value(Some("0px 1rem 2% 3em")),
22 (
23 "0px".into(),
24 Some("1rem".into()),
25 Some("2%".into()),
26 Some("3em".into())
27 )
28 );
29 }
30
31 #[test]
32 fn simple_comma_separated_numbers() {
33 assert_eq!(
34 split_value(Some("0, 1, 2, 3")),
35 (
36 "0".into(),
37 Some("1".into()),
38 Some("2".into()),
39 Some("3".into())
40 )
41 );
42 }
43
44 #[test]
45 fn simple_comma_separated_lengths() {
46 assert_eq!(
47 split_value(Some("0px, 1rem, 2%, 3em")),
48 (
49 "0px".into(),
50 Some("1rem".into()),
51 Some("2%".into()),
52 Some("3em".into())
53 )
54 );
55 }
56
57 #[test]
58 fn does_not_lists_within_functions() {
59 assert_eq!(
60 split_value(Some("rgb(255 200 0)")),
61 ("rgb(255 200 0)".into(), None, None, None)
62 );
63
64 assert_eq!(
65 split_value(Some("rgb(255 200 / 0.5)")),
66 ("rgb(255 200/0.5)".into(), None, None, None)
67 );
68 }
69
70 #[test]
71 fn does_not_lists_within_calc() {
72 assert_eq!(
73 split_value(Some("calc((100% - 50px) * 0.5)")),
74 ("calc((100% - 50px) * 0.5)".into(), None, None, None)
75 );
76
77 assert_eq!(
78 split_value(Some("calc((100% - 50px) * 0.5) var(--rightpadding, 20px)")),
79 (
80 "calc((100% - 50px) * 0.5)".into(),
81 Some("var(--rightpadding,20px)".into()),
82 None,
83 None
84 )
85 );
86 }
87}