mirror of
https://github.com/danog/strum.git
synced 2024-11-26 20:14:40 +01:00
Add tests for nostd environment
This commit is contained in:
parent
1e3acb64a7
commit
6ffee88d10
@ -2,7 +2,7 @@
|
||||
members = [
|
||||
"strum",
|
||||
"strum_macros",
|
||||
"strum_tests"
|
||||
"strum_tests",
|
||||
"strum_nostd_tests"
|
||||
]
|
||||
|
||||
exclude = [ "strum_tests_rename" ]
|
13
strum_nostd_tests/Cargo.toml
Normal file
13
strum_nostd_tests/Cargo.toml
Normal 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"
|
37
strum_nostd_tests/src/lib.rs
Normal file
37
strum_nostd_tests/src/lib.rs
Normal 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() {}
|
||||
}
|
@ -131,7 +131,7 @@ fn lifetime_test() {
|
||||
#[derive(Debug, Eq, PartialEq, EnumString)]
|
||||
enum Generic<T: Default> {
|
||||
Gen(T),
|
||||
None,
|
||||
Error,
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user