#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
use fren_date::SlugOpts;
use slug_preserve::CaseMode;
fn rust_default_opts() -> SlugOpts {
SlugOpts::default()
}
fn slug(input: &str) -> String {
fren_date::slugify_camel_iso_with_year(input, &rust_default_opts(), 2024)
}
#[test]
fn whats_app_stays_glued() {
assert_eq!(slug("WhatsApp"), "WhatsApp");
}
#[test]
fn json_file_stays_glued() {
assert_eq!(slug("JSONFile"), "JSONFile");
}
#[test]
fn camel_case_token_stays_glued() {
assert_eq!(slug("CamelCase"), "CamelCase");
}
#[test]
fn pascal_case_token_stays_glued() {
assert_eq!(slug("PascalCase"), "PascalCase");
}
#[test]
fn lower_camel_token_stays_glued() {
assert_eq!(slug("myVariable"), "myVariable");
}
#[test]
fn camel_in_phrase_keeps_tokens_intact() {
assert_eq!(
slug("CamelCase pascalCase WhatsApp"),
"CamelCase-pascalCase-WhatsApp"
);
}
#[test]
fn whatsapp_at_pattern_still_detected_without_split() {
assert_eq!(
slug("WhatsApp Image 2024-01-15 at 12.30.45"),
"WhatsApp-Image-2024-01-15T12-30-45"
);
}
#[test]
fn date_detected_alongside_camel_token() {
assert_eq!(
slug("WhatsApp Photo 2024-01-15"),
"WhatsApp-Photo-2024-01-15"
);
}
#[test]
fn explicit_split_camel_works() {
let opts = SlugOpts {
separator: '-',
case: CaseMode::Preserve,
split_camel: true,
};
let out = fren_date::slugify_camel_iso_with_year("WhatsApp Image", &opts, 2024);
assert_eq!(out, "Whats-App-Image");
}
#[test]
fn explicit_split_camel_with_underscore_separator() {
let opts = SlugOpts {
separator: '_',
case: CaseMode::Preserve,
split_camel: true,
};
let out = fren_date::slugify_camel_iso_with_year("PascalCase", &opts, 2024);
assert_eq!(out, "Pascal_Case");
}