stylex_transform/shared/utils/css/tests/
transform_value_test.rs1#[cfg(test)]
2mod transform_value_content_property_tests {
3 use crate::shared::structures::state_manager::StateManager;
4 use crate::shared::utils::css::common::transform_value;
5 use stylex_structures::stylex_options::StyleXOptions;
6
7 #[test]
8 fn preserves_css_functions_without_quotes() {
9 let functions = vec![
10 "counters(div, \".\")",
11 "counter(chapter)",
12 "counter(chapter, upper-roman)",
13 "attr(href)",
14 "url(image.jpg)",
15 "linear-gradient(#e66465, #9198e5)",
16 "image-set(\"image1x.png\" 1x, \"image2x.png\" 2x)",
17 "\"prefix\"attr(href)",
18 "url(foo.jpg)attr(alt)",
19 "var(--test)",
20 "var(--test, \"default\")",
21 ];
22
23 let state_manager = StateManager::new(StyleXOptions::default());
24
25 for input in functions {
26 let output = transform_value("content", input, &state_manager);
27 assert_eq!(output, input);
28 }
29 }
30
31 #[test]
32 fn preserves_css_keywords_without_quotes() {
33 let keywords = vec![
34 "normal",
35 "none",
36 "open-quote",
37 "close-quote",
38 "no-open-quote",
39 "no-close-quote",
40 "inherit",
41 "initial",
42 "revert",
43 "revert-layer",
44 "unset",
45 ];
46
47 let state_manager = StateManager::new(StyleXOptions::default());
48
49 for keyword in keywords {
50 let output = transform_value("content", keyword, &state_manager);
51 assert_eq!(output, keyword);
52 }
53 }
54
55 #[test]
56 fn handles_mixed_content_values() {
57 let mixed_values = vec![
58 "open-quote counter(chapter)",
59 "\"prefix\"url(image.jpg)",
60 "url(\"test.png\")/\"Alt text\"",
61 "open-quotecounter(chapter)close-quote",
62 "attr(href)normal",
63 "\"text\"attr(href)\"more text\"",
64 "counter(x)\"text\"counter(y)",
65 ];
66
67 let state_manager = StateManager::new(StyleXOptions::default());
68
69 for input in mixed_values {
70 let output = transform_value("content", input, &state_manager);
71 assert_eq!(output, input);
72 }
73 }
74
75 #[test]
76 fn adds_quotes_to_plain_strings() {
77 let strings = vec![
78 ("Hello world", "\"Hello world\""),
79 ("Simple text", "\"Simple text\""),
80 ("123", "\"123px\""),
81 ];
82
83 let state_manager = StateManager::new(StyleXOptions::default());
84
85 for (input, expected) in strings {
86 let output = transform_value("content", input, &state_manager);
87 assert_eq!(output, expected);
88 }
89 }
90
91 #[test]
92 fn preserve_units_in_zero_values_css_variables() {
93 let variables = vec![
94 ("--test", "0px", "0px"),
96 ("--test", "0vdh", "0vdh"),
97 ("transform", "0rad", "0deg"),
99 ("animation-duration", "0ms", "0s"),
100 ("grid-template-rows", "0fr", "0fr"),
102 ("width", "0%", "0%"),
104 ("margin", "0px", "0"),
106 ];
107
108 let state_manager = StateManager::new(StyleXOptions::default());
109
110 for (key, value, expected) in variables {
111 let output = transform_value(key, value, &state_manager);
112 assert_eq!(
113 output, expected,
114 "Failed for property '{}' with value '{}': expected '{}', got '{}'",
115 key, value, expected, output
116 );
117 }
118 }
119}