Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is this expected behavior (combining EnumStrings with multiple serializes and ascii_case_insensitive with VariantNames)? #366

Open
andrewsuperlegit opened this issue Jun 22, 2024 · 0 comments

Comments

@andrewsuperlegit
Copy link

andrewsuperlegit commented Jun 22, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant