use unocss_classes::{to_uno, uno}; macro_rules! input { ($($t:tt)*) => { (uno![$($t)*], to_uno![$($t)*]) }; } macro_rules! test_cases { ($($t:tt)*) => { let cases = vec![$($t)*]; for ((uno_result, to_uno_result), expected_result) in cases { assert_eq!(uno_result, expected_result); assert_eq!(to_uno_result, expected_result); } }; } #[test] fn mimics_original_transformer_behavior() { test_cases![ ( input!["hover:(bg-gray-400 font-medium)", "font-(light mono)"], "hover:bg-gray-400 hover:font-medium font-light font-mono", ), // test cases taken from // https://github.com/unocss/unocss/blob/main/test/transformer-variant-group.test.ts ( input!["a1 a2:(b1 b2:(c1 c2-(d1 d2) c3) b3) a3"], "a1 a2:b1 a2:b2:c1 a2:b2:c2-d1 a2:b2:c2-d2 a2:b2:c3 a2:b3 a3", ), ( input!["bg-white font-light sm:hover:(bg-gray-100 font-medium)"], "bg-white font-light sm:hover:bg-gray-100 sm:hover:font-medium", ), ( input!["lt-sm:hover:(p-1 p-2)"], "lt-sm:hover:p-1 lt-sm:hover:p-2", ), (input![", Some("button--disabled".to_string()) ], "button--active button--disabled", ), ( input![ "concatenated".to_string() + "-class", Some("batman").map(|_| "bruce-wayne") ], "concatenated-class bruce-wayne", ), ( input!["button" => true, "button--disabled" => DISABLED, "button--active" => false, "all-the-buttons" => 42 > 3 ], "button button--disabled all-the-buttons", ), ( input!["button" => true, Some("button--disabled"), None::, "button--primary"], "button button--disabled button--primary", ), ( input!["button", "", "button--active"], "button button--active", ), ( input!["button", "".to_string(), "button--active"], "button button--active", ), ( input!["button", Some(""), "button--active"], "button button--active", ), ]; } #[test] fn mixed_scenario() { const BOOL: bool = true; const USIZE: usize = 123; let some_string: Option = Some("text-black".to_string()); test_cases![ ( input!["text-sm".to_string(), "text-(red nowrap)" => BOOL], "text-sm text-red text-nowrap", ), ( input!["text-(red nowrap)" => USIZE == 123, some_string.clone()], "text-red text-nowrap text-black", ), ( input![ "hover:(bg-gray-400 font-medium)", "", None::, "font-(light mono)", "" ], "hover:bg-gray-400 hover:font-medium font-light font-mono", ), ]; }