Case insensitive match for ForkName (#2587)

## Issue Addressed

#2583

## Proposed Changes

Case insensitive match on `fork_name` when calling `ForkName::from_str`

## Additional Info

N/A
This commit is contained in:
Mason Stallmo 2021-09-11 06:07:20 +00:00
parent 8d2650fffd
commit 46cd67d519

View File

@ -58,7 +58,7 @@ impl FromStr for ForkName {
type Err = ();
fn from_str(fork_name: &str) -> Result<Self, ()> {
Ok(match fork_name {
Ok(match fork_name.to_lowercase().as_ref() {
"phase0" | "base" => ForkName::Base,
"altair" => ForkName::Altair,
_ => return Err(()),
@ -110,4 +110,22 @@ mod test {
assert_eq!(fork.previous_fork(), Some(prev_fork));
}
}
#[test]
fn fork_name_case_insensitive_match() {
assert_eq!(ForkName::from_str("BASE"), Ok(ForkName::Base));
assert_eq!(ForkName::from_str("BaSe"), Ok(ForkName::Base));
assert_eq!(ForkName::from_str("base"), Ok(ForkName::Base));
assert_eq!(ForkName::from_str("PHASE0"), Ok(ForkName::Base));
assert_eq!(ForkName::from_str("PhAsE0"), Ok(ForkName::Base));
assert_eq!(ForkName::from_str("phase0"), Ok(ForkName::Base));
assert_eq!(ForkName::from_str("ALTAIR"), Ok(ForkName::Altair));
assert_eq!(ForkName::from_str("AlTaIr"), Ok(ForkName::Altair));
assert_eq!(ForkName::from_str("altair"), Ok(ForkName::Altair));
assert_eq!(ForkName::from_str("NO_NAME"), Err(()));
assert_eq!(ForkName::from_str("no_name"), Err(()));
}
}