Tailwind classes in OCaml
1open Tailwind 2 3let test_tw_combinator () = 4 let classes = Css.tw [ 5 Color.bg (Color.make `Blue ~variant:`V500 ()); 6 Effects.rounded_md; 7 Spacing.(to_class (p (Size.rem 1.0))); 8 ] in 9 let result = to_string classes in 10 Alcotest.(check bool) "contains bg-blue-500" (String.contains_s result "bg-blue-500"); 11 Alcotest.(check bool) "contains rounded-md" (String.contains_s result "rounded-md") 12 13let test_class_list_conditional () = 14 let classes = class_list [ 15 (Color.bg (Color.make `Red ()), true); 16 (Color.text (Color.make `White ()), false); 17 (Effects.shadow_lg, true); 18 ] in 19 let result = to_string classes in 20 Alcotest.(check bool) "contains red background" (String.contains_s result "bg-red"); 21 Alcotest.(check bool) "excludes white text" (not (String.contains_s result "text-white")); 22 Alcotest.(check bool) "contains shadow" (String.contains_s result "shadow-lg") 23 24let test_focus_ring () = 25 let ring = focus_ring () in 26 let result = to_string ring in 27 Alcotest.(check bool) "contains focus styles" (String.contains_s result "focus") 28 29let test_focus_ring_with_color () = 30 let blue = Color.make `Blue ~variant:`V500 () in 31 let ring = focus_ring ~color:blue () in 32 let result = to_string ring in 33 Alcotest.(check bool) "contains focus styles" (String.contains_s result "focus") 34 35let test_sr_only () = 36 let sr = sr_only in 37 let result = to_string sr in 38 Alcotest.(check string) "screen reader only" "sr-only" result 39 40let test_module_integration () = 41 let complex_button = Css.tw [ 42 Color.bg (Color.make `Blue ~variant:`V500 ()); 43 Color.text (Color.make `White ()); 44 Spacing.(to_class (px (Size.rem 1.0))); 45 Spacing.(to_class (py (Size.rem 0.5))); 46 Effects.rounded_md; 47 Effects.shadow_sm; 48 Effects.transition `Colors; 49 Variants.hover (Color.bg (Color.make `Blue ~variant:`V600 ())); 50 ] in 51 let result = to_string complex_button in 52 Alcotest.(check bool) "integration works" (String.length result > 0) 53 54let suite = [ 55 "tw_combinator", `Quick, test_tw_combinator; 56 "class_list_conditional", `Quick, test_class_list_conditional; 57 "focus_ring", `Quick, test_focus_ring; 58 "focus_ring_with_color", `Quick, test_focus_ring_with_color; 59 "sr_only", `Quick, test_sr_only; 60 "module_integration", `Quick, test_module_integration; 61]