2024-07-25 14:57:58 +00:00
|
|
|
use rocket::request::FromParam;
|
|
|
|
|
2024-08-10 01:44:50 +00:00
|
|
|
#[allow(non_camel_case_types)]
|
2024-07-25 14:57:58 +00:00
|
|
|
#[derive(Debug, FromParam, PartialEq)]
|
|
|
|
enum Test {
|
|
|
|
Test1,
|
|
|
|
Test2,
|
|
|
|
r#for,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn derive_from_param() {
|
2024-08-10 01:44:50 +00:00
|
|
|
assert_eq!(Test::from_param("Test1").unwrap(), Test::Test1);
|
|
|
|
assert_eq!(Test::from_param("Test2").unwrap(), Test::Test2);
|
|
|
|
assert_eq!(Test::from_param("for").unwrap(), Test::r#for);
|
2024-07-25 14:57:58 +00:00
|
|
|
|
2024-08-10 01:44:50 +00:00
|
|
|
let err = Test::from_param("For").unwrap_err();
|
|
|
|
assert_eq!(err.value, "For");
|
|
|
|
assert_eq!(err.options, &["Test1", "Test2", "for"]);
|
|
|
|
|
|
|
|
let err = Test::from_param("not_test").unwrap_err();
|
|
|
|
assert_eq!(err.value, "not_test");
|
|
|
|
assert_eq!(err.options, &["Test1", "Test2", "for"]);
|
2024-07-25 14:57:58 +00:00
|
|
|
|
|
|
|
}
|