diff --git a/test/test_animations.ml b/test/test_animations.ml index 2da8b23fc..f4be7d943 100644 --- a/test/test_animations.ml +++ b/test/test_animations.ml @@ -200,15 +200,9 @@ let test_theme_animation_sorts_by_name () = space, so a keyframe name carrying an underscore of its own is written [\_] and keeps the character. *) let test_shorthand_underscore_escape () = - let css cls = - match Tw.of_string cls with - | Ok u -> Tw.to_css ~base:false [ u ] |> Tw.Css.to_string - | Error (`Msg m) -> Alcotest.failf "%s: %s" cls m - in - Alcotest.(check bool) - "an escaped underscore stays in the keyframe name" true - (Astring.String.is_infix ~affix:"animation: wiggle_x 1s infinite" - (css {|animate-[wiggle\_x_1s_infinite]|})) + Test_helpers.check_declarations ~minify:false + {|animate-[wiggle\_x_1s_infinite]|} + [ "animation: wiggle_x 1s infinite" ] let tests = [ diff --git a/test/test_divide.ml b/test/test_divide.ml index f72e92651..05ba89496 100644 --- a/test/test_divide.ml +++ b/test/test_divide.ml @@ -56,20 +56,21 @@ let test_arbitrary_width_roundtrip () = check "divide-x-[1rem]"; check "divide-y-[0.5rem]"; check "divide-x-[0.5rem]"; - let selector cls = + (* The whole selector. An affix of it says the class name appears somewhere, + which [.divide-x-\[1rem\]x] would satisfy too; what this test is about is + that each width names its own rule. *) + let selects cls sel = match Tw.of_string cls with - | Ok u -> Tw.to_css ~base:false [ u ] |> Tw.Css.to_string ~minify:true | Error (`Msg m) -> Alcotest.failf "%s: %s" cls m + | Ok u -> + Alcotest.(check bool) + (cls ^ " selects the class the author wrote") + true + (List.mem sel (Test_helpers.selectors_of_utility u)) in - Alcotest.(check bool) - "divide-x-[1rem] selects the class the author wrote" true - (Astring.String.is_infix ~affix:".divide-x-\\[1rem\\]" - (selector "divide-x-[1rem]")); + selects "divide-x-[1rem]" {|:where(.divide-x-\[1rem\] > :not(:last-child))|}; (* Two rem widths are two class names, not one. *) - Alcotest.(check bool) - "divide-x-[2rem] is its own class" true - (Astring.String.is_infix ~affix:".divide-x-\\[2rem\\]" - (selector "divide-x-[2rem]")) + selects "divide-x-[2rem]" {|:where(.divide-x-\[2rem\] > :not(:last-child))|} (* The typed constructor spells the width itself, and builds exactly the classes the bracket reader accepts. Tailwind takes a line-width keyword there - diff --git a/test/test_flex_props.ml b/test/test_flex_props.ml index 767841b5f..e965c572a 100644 --- a/test/test_flex_props.ml +++ b/test/test_flex_props.ml @@ -150,10 +150,12 @@ let test_basis_arbitrary_keeps_the_authored_spelling () = | Error (`Msg m) -> Alcotest.failf "%s: %s" cls m | Ok u -> Alcotest.(check string) "class round-trips" cls (Tw.pp u); - let css = Tw.to_css ~base:false [ u ] |> Tw.Css.to_string in - Alcotest.(check bool) - (cls ^ " selects itself") true - (Astring.String.is_infix ~affix:escaped css)) + (* The whole selector list, which is where "names its rule with the + bracket text" is said: an affix of the selector is satisfied by a + longer one that starts the same way. *) + Alcotest.(check (list string)) + (cls ^ " selects itself") [ escaped ] + (Test_helpers.selectors_of_utility u)) [ ("basis-[0.5ch]", {|.basis-\[0\.5ch\]|}); ("basis-[0.0]", {|.basis-\[0\.0\]|}); diff --git a/test/test_interactivity.ml b/test/test_interactivity.ml index c28915ccf..8b97ca399 100644 --- a/test/test_interactivity.ml +++ b/test/test_interactivity.ml @@ -115,15 +115,8 @@ let test_invalid_arbitrary_will_change () = The arbitrary value spells that one [\_], so the class both parses and keeps the character. *) let test_will_change_underscore_escape () = - let css cls = - match Tw.of_string cls with - | Ok u -> Tw.to_css ~base:false [ u ] |> Tw.Css.to_string - | Error (`Msg m) -> Alcotest.failf "%s: %s" cls m - in - Alcotest.(check bool) - "an escaped underscore stays in the property name" true - (Astring.String.is_infix ~affix:"will-change: a_b" - (css {|will-change-[a\_b]|})) + Test_helpers.check_declarations ~minify:false {|will-change-[a\_b]|} + [ "will-change: a_b" ] let tests = [ diff --git a/test/test_scroll.ml b/test/test_scroll.ml index d6dc2e26d..00cf3b69d 100644 --- a/test/test_scroll.ml +++ b/test/test_scroll.ml @@ -46,13 +46,8 @@ let test_typed_prime () = is not a utility: it used to be reinterpreted as a variable name, so [scroll-m-[2vh]] emitted [scroll-margin: var(--2vh)]. *) let test_arbitrary_length () = - let css cls = - match Tw.of_string cls with - | Ok u -> Tw.to_css ~base:false [ u ] |> Tw.Css.to_string - | Error (`Msg m) -> Alcotest.failf "%s: %s" cls m - in - let emits affix cls = - Alcotest.(check bool) cls true (Astring.String.is_infix ~affix (css cls)) + let emits decl cls = + Test_helpers.check_declarations ~minify:false cls [ decl ] in emits "scroll-margin: 2vh" "scroll-m-[2vh]"; emits "scroll-padding-top: 3ch" "scroll-pt-[3ch]"; diff --git a/test/test_scrollbar.ml b/test/test_scrollbar.ml index 2950e77be..edaca89c3 100644 --- a/test/test_scrollbar.ml +++ b/test/test_scrollbar.ml @@ -79,6 +79,9 @@ let test_transparent_keeps_its_keyword () = |> Tw.Css.to_string ~minify:true | Error (`Msg m) -> Alcotest.failf "scrollbar-thumb-transparent: %s" m in + (* The whole declaration, and it stays a search over this sheet rather than an + exact list: what is under test is what the optimizer above leaves, which + declarations_of_class does not run. *) Alcotest.(check bool) "the utility keeps the transparent keyword" true (Astring.String.is_infix ~affix:"--tw-scrollbar-thumb:transparent" css) diff --git a/test/test_tables.ml b/test/test_tables.ml index 53fcd2e90..1c8024275 100644 --- a/test/test_tables.ml +++ b/test/test_tables.ml @@ -19,20 +19,26 @@ let border_spacing_prime () = every other unit unparsed, and the class-name printer had a placeholder waiting to stand in for whatever it could not spell. *) let arbitrary_border_spacing () = - let css cls = - match Tw.of_string cls with - | Ok u -> Tw.to_css ~base:false [ u ] |> Tw.Css.to_string ~minify:true - | Error (`Msg m) -> Alcotest.failf "%s: %s" cls m + let shorthand = + "border-spacing:var(--tw-border-spacing-x) var(--tw-border-spacing-y)" in - let emits cls affix = - Alcotest.(check bool) cls true (Astring.String.is_infix ~affix (css cls)) + (* The whole list. The affixes named one axis of a utility that sets both, and + never the shorthand that reads them. *) + let both cls value = + Test_helpers.check_declarations cls + [ + "--tw-border-spacing-x:" ^ value; + "--tw-border-spacing-y:" ^ value; + shorthand; + ] in - emits "border-spacing-[123px]" "--tw-border-spacing-x:123px"; - emits "border-spacing-[1rem]" "--tw-border-spacing-y:1rem"; - emits "border-spacing-x-[2em]" "--tw-border-spacing-x:2em"; - emits "border-spacing-y-[1.5vw]" "--tw-border-spacing-y:1.5vw"; - emits "border-spacing-[calc(1rem_+_2px)]" - "--tw-border-spacing-x:calc(1rem + 2px)"; + both "border-spacing-[123px]" "123px"; + both "border-spacing-[1rem]" "1rem"; + both "border-spacing-[calc(1rem_+_2px)]" "calc(1rem + 2px)"; + Test_helpers.check_declarations "border-spacing-x-[2em]" + [ "--tw-border-spacing-x:2em"; shorthand ]; + Test_helpers.check_declarations "border-spacing-y-[1.5vw]" + [ "--tw-border-spacing-y:1.5vw"; shorthand ]; List.iter (fun cls -> Alcotest.(check string)