-
-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
77f2f67
commit cb2cf61
Showing
8 changed files
with
115 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,20 +172,58 @@ fn test_tuple_variant() { | |
|
||
#[derive(Debug, PartialEq, validator::Validate, Deserialize)] | ||
#[serde(validate = "validator::Validate::validate")] | ||
struct ValidatorDemo { | ||
struct ValidateStruct { | ||
#[validate(email)] | ||
mail: String, | ||
} | ||
|
||
#[derive(Debug, PartialEq, validator::Validate, Deserialize)] | ||
#[serde(validator)] | ||
struct ValidatorStruct { | ||
#[validate(email)] | ||
mail: String, | ||
} | ||
|
||
#[test] | ||
fn test_validate_struct() { | ||
assert_de_tokens( | ||
&ValidateStruct { | ||
mail: "[email protected]".into(), | ||
}, | ||
&[ | ||
Token::Struct { | ||
name: "ValidateStruct", | ||
len: 1, | ||
}, | ||
Token::Str("mail"), | ||
Token::Str("[email protected]"), | ||
Token::StructEnd, | ||
], | ||
); | ||
|
||
assert_de_tokens_error::<ValidateStruct>( | ||
&[ | ||
Token::Struct { | ||
name: "ValidateStruct", | ||
len: 1, | ||
}, | ||
Token::Str("mail"), | ||
Token::Str("email.example.com"), | ||
Token::StructEnd, | ||
], | ||
"mail: Validation error: email [{\"value\": String(\"email.example.com\")}]", | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_validator_demo() { | ||
fn test_validator_struct() { | ||
assert_de_tokens( | ||
&ValidatorDemo { | ||
&ValidatorStruct { | ||
mail: "[email protected]".into(), | ||
}, | ||
&[ | ||
Token::Struct { | ||
name: "ValidatorDemo", | ||
name: "ValidatorStruct", | ||
len: 1, | ||
}, | ||
Token::Str("mail"), | ||
|
@@ -194,10 +232,10 @@ fn test_validator_demo() { | |
], | ||
); | ||
|
||
assert_de_tokens_error::<ValidatorDemo>( | ||
assert_de_tokens_error::<ValidatorStruct>( | ||
&[ | ||
Token::Struct { | ||
name: "ValidatorDemo", | ||
name: "ValidatorStruct", | ||
len: 1, | ||
}, | ||
Token::Str("mail"), | ||
|
11 changes: 11 additions & 0 deletions
11
test_suite/tests/ui/validate/both_validator_and_validate.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use serde_derive::Deserialize; | ||
|
||
#[derive(validator::Validate, Deserialize)] | ||
#[serde(validate = "validator::Validate::validate")] | ||
#[serde(validator)] | ||
struct ValidatorStruct { | ||
#[validate(email)] | ||
mail: String, | ||
} | ||
|
||
fn main() {} |
5 changes: 5 additions & 0 deletions
5
test_suite/tests/ui/validate/both_validator_and_validate.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: can not define both `validator` and `validate` | ||
--> tests/ui/validate/both_validator_and_validate.rs:4:20 | ||
| | ||
4 | #[serde(validate = "validator::Validate::validate")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use serde_derive::Deserialize; | ||
|
||
#[derive(Deserialize)] | ||
#[serde(validator)] | ||
struct ValidatorStruct { | ||
mail: String, | ||
} | ||
|
||
fn main() {} |
17 changes: 17 additions & 0 deletions
17
test_suite/tests/ui/validate/validator_unimplemented.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
error[E0277]: the trait bound `ValidatorStruct: Validate` is not satisfied | ||
--> tests/ui/validate/validator_unimplemented.rs:3:10 | ||
| | ||
3 | #[derive(Deserialize)] | ||
| ^^^^^^^^^^^ the trait `Validate` is not implemented for `ValidatorStruct` | ||
| | ||
= help: the following other types implement trait `Validate`: | ||
&BTreeMap<K, V> | ||
&HashMap<K, V, S> | ||
&T | ||
BTreeSet<T> | ||
BinaryHeap<T> | ||
HashSet<T> | ||
LinkedList<T> | ||
Vec<T> | ||
and $N others | ||
= note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info) |