Skip to content

Commit

Permalink
Merge pull request #95 from greyblake/mut-sanitizer-test
Browse files Browse the repository at this point in the history
Add a test for untyped mut sanitize
  • Loading branch information
greyblake authored Oct 15, 2023
2 parents 80b069f + 4435bba commit 561e77b
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion test_suite/tests/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ mod traits {
}

#[test]
fn test_sanitize_and_validate_with_untyped_closures() {
fn test_sanitize_and_validate_with_untyped_closure() {
#[nutype(
derive(Debug),
sanitize(with = |p| {
Expand All @@ -342,6 +342,22 @@ fn test_sanitize_and_validate_with_untyped_closures() {
assert_eq!(pos.into_inner(), Point::new(100, 91))
}

#[test]
fn test_sanitize_with_untyped_mut_closure() {
#[nutype(
derive(Debug),
sanitize(with = |mut p| {
p.x = p.x.clamp(0, 100);
p.y = p.y.clamp(0, 100);
p
}),
)]
pub struct Pos(Point);

let pos = Pos::new(Point::new(123, 91));
assert_eq!(pos.into_inner(), Point::new(100, 91))
}

#[cfg(test)]
#[cfg(feature = "new_unchecked")]
mod new_unchecked {
Expand Down

0 comments on commit 561e77b

Please sign in to comment.