Skip to content

Commit

Permalink
add unit test and update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburniske committed Apr 12, 2024
1 parent 52056c2 commit 2853fb5
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<str>`] or [`AsTailwindClass`]
You can use anything that implements [`AsTailwindClass`]

```rust
use tailwind_fuse::*;
Expand All @@ -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()`].
Expand Down
7 changes: 6 additions & 1 deletion fuse/src/core/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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"
)
}
24 changes: 21 additions & 3 deletions fuse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<str>`] or [`AsTailwindClass`]
//! You can use anything that implements [`AsTailwindClass`]
//!
//! ```
//! use tailwind_fuse::*;
Expand All @@ -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()`].
Expand Down

0 comments on commit 2853fb5

Please sign in to comment.