I'm pretty new to rust and decided to implement my own magic the gathering implementation so i have to match a bunch of different cases and stuff and some of this isn't behaving how I'm expecting it to, so i just want to sanity check:
#[derive(Debug, PartialEq, EnumString, Clone, Hash, Eq, VariantNames, VariantArray)]
#[strum(serialize_all="lowercase")]
enum Color {
#[strum(serialize="G", serialize="{green}", ascii_case_insensitive)]
Green
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn color_accepts_lowercase(){ // <----- This test fails. but.. should it? because i'm serializing all to lowercase AND using case insensitivity
let _green = Color::Green;
let green = Color::from_str("green");
assert_eq!(_green, green.unwrap()); // <-- called `Result::unwrap()` on an `Err` value: VariantNotFound
}
#[test]
fn color_accepts_single_letter(){
let green = Color::Green;
let g = Color::from_str("g");
assert_eq!(green, g.unwrap());
}
#[test]
fn color_accepts_single_letter_uppercase(){
let green = Color::Green;
let G = Color::from_str("G");
assert_eq!(green, G.unwrap());
}
#[test]
fn color_accepts_brackets(){
let green = Color::Green;
let G = Color::from_str("{green}");
assert_eq!(green, G.unwrap());
}
}
All the other tests work fine, but I'm also a bit confused by the Color::VARIANTS behavior-
I assumed that it would be ALL of the at least named variants-
So...
Green, G, {green}
but for some reason if i println it, i only get:
["{green}", ascii_case_insensitive]
but all my tests pass. Is that the expected behavior for the Color::VARIANTS?
I'm pretty new to rust and decided to implement my own magic the gathering implementation so i have to match a bunch of different cases and stuff and some of this isn't behaving how I'm expecting it to, so i just want to sanity check:
All the other tests work fine, but I'm also a bit confused by the Color::VARIANTS behavior-
I assumed that it would be ALL of the at least named variants-
So...
Green, G, {green}
but for some reason if i println it, i only get: ["{green}", ascii_case_insensitive]
but all my tests pass. Is that the expected behavior for the Color::VARIANTS?