Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions test/test_animations.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
[
Expand Down
21 changes: 11 additions & 10 deletions test/test_divide.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -
Expand Down
10 changes: 6 additions & 4 deletions test/test_flex_props.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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\]|});
Expand Down
11 changes: 2 additions & 9 deletions test/test_interactivity.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
[
Expand Down
9 changes: 2 additions & 7 deletions test/test_scroll.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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]";
Expand Down
3 changes: 3 additions & 0 deletions test/test_scrollbar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 18 additions & 12 deletions test/test_tables.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading