aboutsummaryrefslogtreecommitdiffstats
path: root/validator_derive/tests
diff options
context:
space:
mode:
authorCaroline Glassberg-Powell2019-04-28 18:45:40 +0100
committerCaroline Glassberg-Powell2019-04-28 19:01:08 +0100
commit6e8effdaa2b47f4056a00d301a9e7a5a1a2fd8dc (patch)
tree781b99ec57192adb777681243b8161fd37a10bae /validator_derive/tests
parent4b9fe3939b106c151bff11e490a41212559f9a4a (diff)
downloadvalidator-6e8effdaa2b47f4056a00d301a9e7a5a1a2fd8dc.tar.bz2
Issue #69: Change `range` to require only one arg
Currently range is hard-coded to take both max and min. This is unhelpful in cases where we may only want to check one of the bounds. Update so that it behaves more like the `length` validator and can take either max or min, as well as both. Also ensure that at least one of them is supplied.
Diffstat (limited to 'validator_derive/tests')
-rw-r--r--validator_derive/tests/compile-fail/range/missing_arg.rs15
-rw-r--r--validator_derive/tests/compile-fail/range/no_args.rs2
-rw-r--r--validator_derive/tests/run-pass/range.rs4
3 files changed, 5 insertions, 16 deletions
diff --git a/validator_derive/tests/compile-fail/range/missing_arg.rs b/validator_derive/tests/compile-fail/range/missing_arg.rs
deleted file mode 100644
index 3aed1f0..0000000
--- a/validator_derive/tests/compile-fail/range/missing_arg.rs
+++ /dev/null
@@ -1,15 +0,0 @@
-#![feature(attr_literals)]
-
-#[macro_use] extern crate validator_derive;
-extern crate validator;
-use validator::Validate;
-
-#[derive(Validate)]
-//~^ ERROR: proc-macro derive panicked
-//~^^ HELP: Invalid attribute #[validate] on field `s`: Validator `range` requires 2 arguments: `min` and `max`
-struct Test {
- #[validate(range(min = 2.0))]
- s: i32,
-}
-
-fn main() {}
diff --git a/validator_derive/tests/compile-fail/range/no_args.rs b/validator_derive/tests/compile-fail/range/no_args.rs
index c2bdd03..b097b0a 100644
--- a/validator_derive/tests/compile-fail/range/no_args.rs
+++ b/validator_derive/tests/compile-fail/range/no_args.rs
@@ -4,7 +4,7 @@ use validator::Validate;
#[derive(Validate)]
//~^ ERROR: proc-macro derive panicked
-//~^^ HELP: Invalid attribute #[validate] on field `s`: Validator `range` requires 2 arguments: `min` and `max`
+//~^^ HELP: Invalid attribute #[validate] on field `s`: Validator `range` requires at least 1 argument out of `min` and `max`
struct Test {
#[validate(range())]
s: i32,
diff --git a/validator_derive/tests/run-pass/range.rs b/validator_derive/tests/run-pass/range.rs
index e35f3df..520dd64 100644
--- a/validator_derive/tests/run-pass/range.rs
+++ b/validator_derive/tests/run-pass/range.rs
@@ -24,6 +24,10 @@ struct Test {
s8: u8,
#[validate(range(min = 18.0, max = 22))]
s9: Option<u8>,
+ #[validate(range(min = 18.0))]
+ s10: Option<u8>,
+ #[validate(range(max = 18.0))]
+ s11: Option<u8>,
}
fn main() {}