Skip to content

Commit

Permalink
docs: add docs about full match (#74)
Browse files Browse the repository at this point in the history
Co-authored-by: Randolf J <19544887-randolf@users.noreply.gitlab.com>
  • Loading branch information
jun-sheaf and Randolf J committed May 15, 2024
1 parent 2a2a1a9 commit f90acfc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ assert_eq!(
);
assert_eq!((subject, object), (Some("name"), Some("Rho")));

// If you want to ensure the entire string matches, you can add `true` to the end of the macro.
assert_eq!(unformat!("{1} is {0}", value, true), None);

// If a type implements `FromStr`, you can use it as a type argument. This
// is written as `{:Type}`.
assert_eq!(
Expand Down
11 changes: 11 additions & 0 deletions tests/unformat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,14 @@ fn test_declmacro() {

test_declmacro!("abc", "abcd");
}

#[test]
fn test_full_match() {
assert_eq!(unformat!("({:u8}, {:u8})", "(1, 2)"), Some((1, 2)));
assert_eq!(unformat!("({:u8}, {:u8})", "(1, 2)bar"), Some((1, 2)));
assert_eq!(unformat!("({:u8}, {:u8})", "foo(1, 2)"), Some((1, 2)));

assert_eq!(unformat!("({:u8}, {:u8})", "(1, 2)", true), Some((1, 2)));
assert_eq!(unformat!("({:u8}, {:u8})", "(1, 2)bar", true), None);
assert_eq!(unformat!("({:u8}, {:u8})", "foo(1, 2)", true), None);
}

0 comments on commit f90acfc

Please sign in to comment.