Skip to content

Commit

Permalink
Update Space ToString impl + add Space str UT
Browse files Browse the repository at this point in the history
Breaking change.

0.7 wheee
  • Loading branch information
Beinsezii committed Dec 30, 2023
1 parent 4c7817d commit 2075933
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,17 @@ impl TryFrom<&str> for Space {
type Error = ();
fn try_from(value: &str) -> Result<Self, ()> {
match value.to_ascii_lowercase().trim() {
"srgb" | "srgba" => Ok(Space::SRGB),
"hsv" | "hsva" => Ok(Space::HSV),
"lrgb" | "lrgba" | "rgb" | "rgba" => Ok(Space::LRGB),
"xyz" | "xyza" | "cie xyz" => Ok(Space::XYZ),
"lab" | "laba" | "cie l*a*b*" => Ok(Space::LAB),
"lch" | "lcha" | "cie l*c*hab" => Ok(Space::LCH),
"oklab" | "oklaba" => Ok(Space::OKLAB),
"oklch" | "oklcha" => Ok(Space::OKLCH),
"srgb" => Ok(Space::SRGB),
"hsv" => Ok(Space::HSV),
"lrgb" | "rgb" => Ok(Space::LRGB),
"xyz" | "cie xyz" | "ciexyz" => Ok(Space::XYZ),
// extra values so you can move to/from str
"lab" | "cie lab" | "cielab" | "cie l*a*b*" => Ok(Space::LAB),
"lch" | "cie lch" | "cielch" | "cie l*c*hab" => Ok(Space::LCH),
"oklab" => Ok(Space::OKLAB),
"oklch" => Ok(Space::OKLCH),
"jzazbz" => Ok(Space::JZAZBZ),
"jzczhz" => Ok(Space::JZCZHZ),
_ => Err(()),
}
}
Expand Down Expand Up @@ -1365,6 +1368,13 @@ mod tests {
}
}

#[test]
fn space_strings() {
for space in Space::ALL {
assert_eq!(Ok(*space), Space::try_from(space.to_string().as_str()))
}
}

#[test]
fn str2col_base() {
assert_eq!(str2col("0.2, 0.5, 0.6"), Some((Space::SRGB, [0.2, 0.5, 0.6])))
Expand Down

0 comments on commit 2075933

Please sign in to comment.