From 2853fb56a02f59009846158744afe53320884742 Mon Sep 17 00:00:00 2001 From: Nico Burniske Date: Fri, 12 Apr 2024 10:48:07 -0400 Subject: [PATCH] add unit test and update readme --- README.md | 24 +++++++++++++++++++++--- fuse/src/core/join.rs | 7 ++++++- fuse/src/lib.rs | 24 +++++++++++++++++++++--- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e0dc780..698fe7d 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ cargo add tailwind-fuse You can use [`tw_join!`] to join Tailwind classes, and [`tw_merge!`] to merge Tailwind Classes handling conflicts. -You can use anything that implements [`AsRef`] or [`AsTailwindClass`] +You can use anything that implements [`AsTailwindClass`] ```rust use tailwind_fuse::*; @@ -46,12 +46,30 @@ assert_eq!( // Conflict resolution // Right most class takes precedence -assert_eq!("p-4", tw_merge!("py-2 px-4", "p-4")); +assert_eq!( + "p-4", + tw_merge!("py-2 px-4", "p-4") +); // Refinements are permitted -assert_eq!("p-4 py-2", tw_merge!("p-4", "py-2")); +assert_eq!( + "p-4 py-2", + tw_merge!("p-4", "py-2") +); +``` + +You can use Options to exclude certain classes from being merged + +```rust +use tailwind_fuse::*; + +assert_eq!( + "flex justify-center", + tw_join!("flex", (false).then_some("items-center"), (true).then_some("justify-center")) +) ``` + ## Usage: Variants Useful for building components with first class support for tailwind. By default, conflicts are merged using [`tw_merge()`]. diff --git a/fuse/src/core/join.rs b/fuse/src/core/join.rs index c118f75..892479c 100644 --- a/fuse/src/core/join.rs +++ b/fuse/src/core/join.rs @@ -106,7 +106,7 @@ macro_rules! tw_join { } #[test] -fn test_tw() { +fn join() { assert_eq!(tw_join!("a"), "a"); assert_eq!(tw_join!("a", "b"), "a b"); assert_eq!(tw_join!("a", "b", "c"), "a b c"); @@ -119,4 +119,9 @@ fn test_tw() { "one two three" ); assert_eq!(tw_join!("a", " ", "b", "c", " "), "a b c"); + + assert_eq!( + tw_join!("a", (false).then_some("b"), (true).then_some("c")), + "a c" + ) } diff --git a/fuse/src/lib.rs b/fuse/src/lib.rs index b883b0b..49a214a 100644 --- a/fuse/src/lib.rs +++ b/fuse/src/lib.rs @@ -33,7 +33,7 @@ //! You can use [`tw_join!`] to join Tailwind classes, and [`tw_merge!`] to merge Tailwind Classes handling conflicts. //! //! -//! You can use anything that implements [`AsRef`] or [`AsTailwindClass`] +//! You can use anything that implements [`AsTailwindClass`] //! //! ``` //! use tailwind_fuse::*; @@ -46,12 +46,30 @@ //! //! // Conflict resolution //! // Right most class takes precedence -//! assert_eq!("p-4", tw_merge!("py-2 px-4", "p-4")); +//! assert_eq!( +//! "p-4", +//! tw_merge!("py-2 px-4", "p-4") +//! ); //! //! // Refinements are permitted -//! assert_eq!("p-4 py-2", tw_merge!("p-4", "py-2")); +//! assert_eq!( +//! "p-4 py-2", +//! tw_merge!("p-4", "py-2") +//! ); +//! ``` +//! +//! You can use Options to exclude certain classes from being merged +//! +//! ``` +//! use tailwind_fuse::*; +//! +//! assert_eq!( +//! "flex justify-center", +//! tw_join!("flex", (false).then_some("items-center"), (true).then_some("justify-center")) +//! ) //! ``` //! +//! //! ## Usage: Variants //! //! Useful for building components with first class support for tailwind. By default, conflicts are merged using [`tw_merge()`].