#![cfg_attr(not(feature = "std"), no_std)] #![allow(dead_code)] // some code is tested for type checking only #[cfg(not(feature = "std"))] extern crate alloc; #[cfg(not(feature = "std"))] use alloc::string::ToString; use derive_more::FromStr; #[derive(FromStr)] struct MyInt(i32); #[derive(FromStr)] struct Point1D { x: i32, } #[derive(Debug, FromStr, PartialEq, Eq)] enum EnumNoFields { Foo, Bar, Baz, BaZ, } #[test] fn enum_test() { assert_eq!("Foo".parse::().unwrap(), EnumNoFields::Foo); assert_eq!("FOO".parse::().unwrap(), EnumNoFields::Foo); assert_eq!("foo".parse::().unwrap(), EnumNoFields::Foo); assert_eq!( "other".parse::().unwrap_err().to_string(), "Invalid `EnumNoFields` string representation", ); } #[test] fn enum_test_case_sensitive() { assert_eq!("Baz".parse::().unwrap(), EnumNoFields::Baz); assert_eq!("BaZ".parse::().unwrap(), EnumNoFields::BaZ); assert_eq!( "baz".parse::().unwrap_err().to_string(), "Invalid `EnumNoFields` string representation", ); }