#[cfg(test)]
use strum::EnumIter;
use crate::boundary::Boundary;
use crate::pattern::Pattern;
#[cfg_attr(test, derive(EnumIter))]
#[derive(Eq, PartialEq, Hash, Clone, Copy, Debug)]
pub enum Case {
Upper,
Lower,
Title,
Sentence,
Toggle,
Camel,
Pascal,
UpperCamel,
Snake,
Constant,
UpperSnake,
Kebab,
Cobol,
UpperKebab,
Train,
Flat,
UpperFlat,
Alternating,
#[cfg(any(doc, feature = "random"))]
#[cfg(feature = "random")]
Random,
#[cfg(any(doc, feature = "random"))]
#[cfg(feature = "random")]
PseudoRandom,
}
impl Case {
pub const fn delim(&self) -> &'static str {
use Case::*;
match self {
Upper | Lower | Title | Sentence | Toggle | Alternating => " ",
Snake | Constant | UpperSnake => "_",
Kebab | Cobol | UpperKebab | Train => "-",
#[cfg(feature = "random")]
Random | PseudoRandom => " ",
UpperFlat | Flat | Camel | UpperCamel | Pascal => "",
}
}
pub const fn pattern(&self) -> Pattern {
use Case::*;
match self {
Upper | Constant | UpperSnake | UpperFlat | Cobol | UpperKebab => Pattern::Uppercase,
Lower | Snake | Kebab | Flat => Pattern::Lowercase,
Title | Pascal | UpperCamel | Train => Pattern::Capital,
Camel => Pattern::Camel,
Toggle => Pattern::Toggle,
Alternating => Pattern::Alternating,
Sentence => Pattern::Sentence,
#[cfg(feature = "random")]
Random => Pattern::Random,
#[cfg(feature = "random")]
PseudoRandom => Pattern::PseudoRandom,
}
}
pub fn boundaries(&self) -> Vec<Boundary> {
use Case::*;
match self {
Upper | Lower | Title | Sentence | Toggle | Alternating => vec![Boundary::SPACE],
Snake | Constant | UpperSnake => vec![Boundary::UNDERSCORE],
Kebab | Cobol | UpperKebab | Train => vec![Boundary::HYPHEN],
#[cfg(feature = "random")]
Random | PseudoRandom => vec![Boundary::SPACE],
UpperFlat | Flat => vec![],
Camel | UpperCamel | Pascal => vec![
Boundary::LOWER_UPPER,
Boundary::ACRONYM,
Boundary::LOWER_DIGIT,
Boundary::UPPER_DIGIT,
Boundary::DIGIT_LOWER,
Boundary::DIGIT_UPPER,
],
}
}
pub fn all_cases() -> Vec<Case> {
use Case::*;
vec![
Upper,
Lower,
Title,
Sentence,
Toggle,
Camel,
Pascal,
UpperCamel,
Snake,
Constant,
UpperSnake,
Kebab,
Cobol,
UpperKebab,
Train,
Flat,
UpperFlat,
Alternating,
#[cfg(feature = "random")]
Random,
#[cfg(feature = "random")]
PseudoRandom,
]
}
#[cfg(feature = "random")]
pub fn random_cases() -> Vec<Case> {
use Case::*;
vec![Random, PseudoRandom]
}
pub fn deterministic_cases() -> Vec<Case> {
use Case::*;
vec![
Upper,
Lower,
Title,
Sentence,
Toggle,
Camel,
Pascal,
UpperCamel,
Snake,
Constant,
UpperSnake,
Kebab,
Cobol,
UpperKebab,
Train,
Flat,
UpperFlat,
Alternating,
]
}
}
#[cfg(test)]
mod test {
use super::*;
use strum::IntoEnumIterator;
#[test]
fn all_cases_in_iter() {
let all = Case::all_cases();
for case in Case::iter() {
assert!(all.contains(&case));
}
}
}