Debian Codegraph @

third_party/rust/derive_more/tests/from_str.rs

raw
1 #![cfg_attr(not(feature = "std"), no_std)]
2 #![allow(dead_code)]
3
4 #[cfg(not(feature = "std"))]
5 extern crate alloc;
6
7 #[cfg(not(feature = "std"))]
8 use alloc::string::ToString;
9
10 use derive_more::FromStr;
11
12 #[derive(FromStr)]
13 struct MyInt(i32);
14
15 #[derive(FromStr)]
16 struct Point1D {
17 x: i32,
18 }
19
20 #[derive(Debug, FromStr, PartialEq, Eq)]
21 enum EnumNoFields {
22 Foo,
23 Bar,
24 Baz,
25 BaZ,
26 }
27
28 #[test]
29 fn enum_test() {
30 assert_eq!("Foo".parse::<EnumNoFields>().unwrap(), EnumNoFields::Foo);
31 assert_eq!("FOO".parse::<EnumNoFields>().unwrap(), EnumNoFields::Foo);
32 assert_eq!("foo".parse::<EnumNoFields>().unwrap(), EnumNoFields::Foo);
33 assert_eq!(
34 "other".parse::<EnumNoFields>().unwrap_err().to_string(),
35 "Invalid `EnumNoFields` string representation",
36 );
37 }
38
39 #[test]
40 fn enum_test_case_sensitive() {
41 assert_eq!("Baz".parse::<EnumNoFields>().unwrap(), EnumNoFields::Baz);
42 assert_eq!("BaZ".parse::<EnumNoFields>().unwrap(), EnumNoFields::BaZ);
43 assert_eq!(
44 "baz".parse::<EnumNoFields>().unwrap_err().to_string(),
45 "Invalid `EnumNoFields` string representation",
46 );
47 }