mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-04 01:18:34 +00:00
to_str impls for two enums
This commit is contained in:
1 parent
cb6bc26a5d
commit
30cd8cd119
2 files changed
+64
No files matched your search
@@ -21,6 +21,19 @@ pub enum ArtcraftCreditsPackSlug {
|
||||
Artcraft50000,
|
||||
}
|
||||
|
||||
impl ArtcraftCreditsPackSlug {
|
||||
pub const fn to_str(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Artcraft1000 => "artcraft_1000",
|
||||
Self::Artcraft2500 => "artcraft_2500",
|
||||
Self::Artcraft5000 => "artcraft_5000",
|
||||
Self::Artcraft10000 => "artcraft_10000",
|
||||
Self::Artcraft25000 => "artcraft_25000",
|
||||
Self::Artcraft50000 => "artcraft_50000",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::ArtcraftCreditsPackSlug;
|
||||
@@ -56,6 +69,28 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
mod to_str_checks {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn to_str() {
|
||||
assert_eq!(ArtcraftCreditsPackSlug::Artcraft1000.to_str(), "artcraft_1000");
|
||||
assert_eq!(ArtcraftCreditsPackSlug::Artcraft2500.to_str(), "artcraft_2500");
|
||||
assert_eq!(ArtcraftCreditsPackSlug::Artcraft5000.to_str(), "artcraft_5000");
|
||||
assert_eq!(ArtcraftCreditsPackSlug::Artcraft10000.to_str(), "artcraft_10000");
|
||||
assert_eq!(ArtcraftCreditsPackSlug::Artcraft25000.to_str(), "artcraft_25000");
|
||||
assert_eq!(ArtcraftCreditsPackSlug::Artcraft50000.to_str(), "artcraft_50000");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn to_str_matches_serde() {
|
||||
for variant in ArtcraftCreditsPackSlug::iter() {
|
||||
let serde_str = serde_json::to_string(&variant).unwrap().replace('"', "");
|
||||
assert_eq!(variant.to_str(), serde_str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod mechanical_checks {
|
||||
use super::*;
|
||||
|
||||
|
||||
@@ -12,6 +12,16 @@ pub enum ArtcraftSubscriptionSlug {
|
||||
ArtcraftMax,
|
||||
}
|
||||
|
||||
impl ArtcraftSubscriptionSlug {
|
||||
pub const fn to_str(&self) -> &'static str {
|
||||
match self {
|
||||
Self::ArtcraftBasic => "artcraft_basic",
|
||||
Self::ArtcraftPro => "artcraft_pro",
|
||||
Self::ArtcraftMax => "artcraft_max",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::ArtcraftSubscriptionSlug;
|
||||
@@ -41,6 +51,25 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
mod to_str_checks {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn to_str() {
|
||||
assert_eq!(ArtcraftSubscriptionSlug::ArtcraftBasic.to_str(), "artcraft_basic");
|
||||
assert_eq!(ArtcraftSubscriptionSlug::ArtcraftPro.to_str(), "artcraft_pro");
|
||||
assert_eq!(ArtcraftSubscriptionSlug::ArtcraftMax.to_str(), "artcraft_max");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn to_str_matches_serde() {
|
||||
for variant in ArtcraftSubscriptionSlug::iter() {
|
||||
let serde_str = serde_json::to_string(&variant).unwrap().replace('"', "");
|
||||
assert_eq!(variant.to_str(), serde_str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod mechanical_checks {
|
||||
use super::*;
|
||||
|
||||
|
||||
Reference in new issue
Block a user