aboutsummaryrefslogtreecommitdiffstats
path: root/validator_derive/tests
diff options
context:
space:
mode:
authorVincent Prouillet2017-01-18 21:35:01 +0900
committerVincent Prouillet2017-01-19 13:38:47 +0900
commit1fd1b3d708a2737c2a678df8a37e719c29c754bc (patch)
tree67cb2b347ee2dab46bce64fdcfcb1f77a59e9a19 /validator_derive/tests
parent8f54c9228d8cf8e2bede37ddc9958db7ce4c63a8 (diff)
downloadvalidator-1fd1b3d708a2737c2a678df8a37e719c29c754bc.tar.bz2
Make it work with lifetimes
Diffstat (limited to 'validator_derive/tests')
-rw-r--r--validator_derive/tests/compile-fail/length/wrong_type.rs2
-rw-r--r--validator_derive/tests/run-pass/lifetime.rs19
-rw-r--r--validator_derive/tests/test_derive.rs12
3 files changed, 32 insertions, 1 deletions
diff --git a/validator_derive/tests/compile-fail/length/wrong_type.rs b/validator_derive/tests/compile-fail/length/wrong_type.rs
index e8a28ca..12dbb61 100644
--- a/validator_derive/tests/compile-fail/length/wrong_type.rs
+++ b/validator_derive/tests/compile-fail/length/wrong_type.rs
@@ -6,7 +6,7 @@ use validator::Validate;
#[derive(Validate)]
//~^ ERROR: custom derive attribute panicked
-//~^^ HELP: Invalid attribute #[validate] on field `s`: Validator `length` can only be used on types `String` or `Vec` but found `usize`
+//~^^ HELP: Invalid attribute #[validate] on field `s`: Validator `length` can only be used on types `String`, `&str` or `Vec` but found `usize`
struct Test {
#[validate(length())]
s: usize,
diff --git a/validator_derive/tests/run-pass/lifetime.rs b/validator_derive/tests/run-pass/lifetime.rs
new file mode 100644
index 0000000..8547a1a
--- /dev/null
+++ b/validator_derive/tests/run-pass/lifetime.rs
@@ -0,0 +1,19 @@
+#![feature(attr_literals)]
+
+#[macro_use] extern crate validator_derive;
+extern crate validator;
+use validator::Validate;
+
+#[derive(Validate)]
+struct Test<'a> {
+ #[validate(length(min = 1))]
+ s: &'a str,
+ #[validate(length(min = 1, max = 2))]
+ s2: &'a str,
+ #[validate(length(equal = 1))]
+ s3: &'a str,
+ #[validate(length(max = 1))]
+ s4: &'a str,
+}
+
+fn main() {}
diff --git a/validator_derive/tests/test_derive.rs b/validator_derive/tests/test_derive.rs
index 4e6c088..7ff542b 100644
--- a/validator_derive/tests/test_derive.rs
+++ b/validator_derive/tests/test_derive.rs
@@ -271,3 +271,15 @@ fn test_can_check_regex_validator() {
let s2 = RegexStruct {name: "AL".to_string()};
assert!(s2.validate().is_err());
}
+
+//
+//#[test]
+//fn test_can_validate_option_fields() {
+// #[derive(Debug, Validate)]
+// struct PutStruct<'a> {
+// #[validate(length(min = "1", max = "10"))]
+// name: Option<&'a str>,
+// }
+// let s = PutStruct {name: Some("al")};
+// assert!(s.validate().is_ok());
+//}