1
0
mirror of https://github.com/danog/strum.git synced 2024-11-26 12:04:38 +01:00

Add tests for nostd environment (#196)

Co-authored-by: Peter Glotfelty <peter@glotfelty.us>
This commit is contained in:
Peter Glotfelty 2021-11-20 11:30:11 -08:00 committed by GitHub
parent 2ba6b0a9c3
commit 0c80602333
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 4 deletions

View File

@ -2,7 +2,7 @@
members = [
"strum",
"strum_macros",
"strum_tests"
"strum_tests",
"strum_nostd_tests"
]
exclude = [ "strum_tests_rename" ]

View File

@ -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"

View File

@ -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() {}
}

View File

@ -131,7 +131,7 @@ fn lifetime_test() {
#[derive(Debug, Eq, PartialEq, EnumString)]
enum Generic<T: Default> {
Gen(T),
None,
Error,
}
#[test]