diff --git a/Cargo.toml b/Cargo.toml index 619d955..094b6e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ members = [ "strum", "strum_macros", - "strum_tests" + "strum_tests", + "strum_nostd_tests" ] - -exclude = [ "strum_tests_rename" ] \ No newline at end of file + \ No newline at end of file diff --git a/strum_nostd_tests/Cargo.toml b/strum_nostd_tests/Cargo.toml new file mode 100644 index 0000000..9e44e16 --- /dev/null +++ b/strum_nostd_tests/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "strum_nostd_tests" +version = "0.23.1" +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +strum = { path = "../strum", features = ["derive"] } +strum_macros = { path = "../strum_macros", features = [] } + +[dev-dependencies] +rustversion = "1.0" \ No newline at end of file diff --git a/strum_nostd_tests/src/lib.rs b/strum_nostd_tests/src/lib.rs new file mode 100644 index 0000000..816c073 --- /dev/null +++ b/strum_nostd_tests/src/lib.rs @@ -0,0 +1,37 @@ +#![no_std] + +#[cfg(test)] +mod tests { + use core::str::FromStr; + use strum::EnumString; + + #[derive(Debug, Eq, PartialEq, EnumString)] + enum Color { + Red, + Blue { + hue: usize, + }, + #[strum(serialize = "y", serialize = "yellow")] + Yellow, + #[strum(to_string = "purp")] + Purple, + #[strum(serialize = "blk", serialize = "Black", ascii_case_insensitive)] + Black, + } + + #[test] + fn from_str_no_std() { + assert_eq!(Color::Yellow, Color::from_str("yellow").unwrap()); + } + + #[test] + #[rustversion::since(1.34)] + fn try_from_str_no_std() { + use core::convert::TryFrom; + assert_eq!(Color::Yellow, Color::try_from("yellow").unwrap()); + } + + #[test] + #[rustversion::before(1.34)] + fn try_from_str_no_std() {} +} diff --git a/strum_tests/tests/from_str.rs b/strum_tests/tests/from_str.rs index 463e3b5..845768c 100644 --- a/strum_tests/tests/from_str.rs +++ b/strum_tests/tests/from_str.rs @@ -131,7 +131,7 @@ fn lifetime_test() { #[derive(Debug, Eq, PartialEq, EnumString)] enum Generic { Gen(T), - None, + Error, } #[test]