Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
Add tests for nostd environment (Peternator7#196)
Browse files Browse the repository at this point in the history
Co-authored-by: Peter Glotfelty <[email protected]>
  • Loading branch information
Peternator7 and Peter Glotfelty authored Nov 20, 2021
1 parent 2ba6b0a commit 0c80602
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
members = [
"strum",
"strum_macros",
"strum_tests"
"strum_tests",
"strum_nostd_tests"
]

exclude = [ "strum_tests_rename" ]

13 changes: 13 additions & 0 deletions strum_nostd_tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 changes: 37 additions & 0 deletions strum_nostd_tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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() {}
}
2 changes: 1 addition & 1 deletion strum_tests/tests/from_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ fn lifetime_test() {
#[derive(Debug, Eq, PartialEq, EnumString)]
enum Generic<T: Default> {
Gen(T),
None,
Error,
}

#[test]
Expand Down

0 comments on commit 0c80602

Please sign in to comment.