diff --git a/garde/tests/rules/inner.rs b/garde/tests/rules/inner.rs index 4eb8975..803ebbe 100644 --- a/garde/tests/rules/inner.rs +++ b/garde/tests/rules/inner.rs @@ -26,3 +26,96 @@ fn alphanumeric_invalid() { &() ) } + +#[derive(Debug, garde::Validate)] +struct NotNestedOption<'a> { + #[garde(inner(alphanumeric))] + inner: Option<&'a str>, +} + +#[derive(Debug, garde::Validate)] +struct NestedSliceInsideOption<'a> { + #[garde(inner(inner(alphanumeric)))] + inner: Option<&'a [&'a str]>, +} + +#[derive(Debug, garde::Validate)] +struct DoubleNestedSliceInsideOption<'a> { + #[garde(inner(inner(inner(alphanumeric))))] + inner: Option<&'a [&'a [&'a str]]>, +} + +#[derive(Debug, garde::Validate)] +struct OptionInsideSlice<'a> { + #[garde(inner(inner(alphanumeric)))] + inner: &'a [Option<&'a str>], +} + +#[test] +fn alphanumeric_some_valid() { + util::check_ok( + &[NotNestedOption { + inner: Some("abcd0123"), + }], + &(), + ); + util::check_ok( + &[NestedSliceInsideOption { + inner: Some(&["abcd0123"]), + }], + &(), + ); + util::check_ok( + &[DoubleNestedSliceInsideOption { + inner: Some(&[&["abcd0123"]]), + }], + &(), + ); + util::check_ok( + &[OptionInsideSlice { + inner: &[Some("abcd0123")], + }], + &(), + ) +} + +#[test] +fn alphanumeric_some_invalid() { + util::check_fail!( + &[NotNestedOption { + inner: Some("!!!!"), + }], + &(), + ); + util::check_fail!( + &[NestedSliceInsideOption { + inner: Some(&["!!!!"]), + }], + &(), + ); + util::check_fail!( + &[DoubleNestedSliceInsideOption { + inner: Some(&[&["!!!!"]]), + }], + &(), + ); + util::check_fail!( + &[OptionInsideSlice { + inner: &[Some("!!!!")], + }], + &(), + ) +} + +#[test] +fn alphanumeric_none_valid() { + util::check_ok(&[NotNestedOption { inner: None }], &()); + util::check_ok(&[NestedSliceInsideOption { inner: None }], &()); + util::check_ok(&[DoubleNestedSliceInsideOption { inner: None }], &()); + util::check_ok( + &[OptionInsideSlice { + inner: &[None, None], + }], + &(), + ) +} diff --git a/garde/tests/rules/snapshots/rules__rules__inner__alphanumeric_some_invalid-2.snap b/garde/tests/rules/snapshots/rules__rules__inner__alphanumeric_some_invalid-2.snap new file mode 100644 index 0000000..9a9b892 --- /dev/null +++ b/garde/tests/rules/snapshots/rules__rules__inner__alphanumeric_some_invalid-2.snap @@ -0,0 +1,15 @@ +--- +source: garde/tests/./rules/inner.rs +assertion_line: 90 +expression: snapshot +--- +NestedSliceInsideOption { + inner: Some( + [ + "!!!!", + ], + ), +} +inner[0]: not alphanumeric + + diff --git a/garde/tests/rules/snapshots/rules__rules__inner__alphanumeric_some_invalid-3.snap b/garde/tests/rules/snapshots/rules__rules__inner__alphanumeric_some_invalid-3.snap new file mode 100644 index 0000000..ec85bff --- /dev/null +++ b/garde/tests/rules/snapshots/rules__rules__inner__alphanumeric_some_invalid-3.snap @@ -0,0 +1,17 @@ +--- +source: garde/tests/./rules/inner.rs +assertion_line: 96 +expression: snapshot +--- +DoubleNestedSliceInsideOption { + inner: Some( + [ + [ + "!!!!", + ], + ], + ), +} +inner[0][0]: not alphanumeric + + diff --git a/garde/tests/rules/snapshots/rules__rules__inner__alphanumeric_some_invalid-4.snap b/garde/tests/rules/snapshots/rules__rules__inner__alphanumeric_some_invalid-4.snap new file mode 100644 index 0000000..c85d607 --- /dev/null +++ b/garde/tests/rules/snapshots/rules__rules__inner__alphanumeric_some_invalid-4.snap @@ -0,0 +1,15 @@ +--- +source: garde/tests/./rules/inner.rs +assertion_line: 102 +expression: snapshot +--- +OptionInsideSlice { + inner: [ + Some( + "!!!!", + ), + ], +} +inner[0]: not alphanumeric + + diff --git a/garde/tests/rules/snapshots/rules__rules__inner__alphanumeric_some_invalid.snap b/garde/tests/rules/snapshots/rules__rules__inner__alphanumeric_some_invalid.snap new file mode 100644 index 0000000..e692b6a --- /dev/null +++ b/garde/tests/rules/snapshots/rules__rules__inner__alphanumeric_some_invalid.snap @@ -0,0 +1,13 @@ +--- +source: garde/tests/./rules/inner.rs +assertion_line: 84 +expression: snapshot +--- +NotNestedOption { + inner: Some( + "!!!!", + ), +} +inner: not alphanumeric + +