use finetype_cli::enum_emission::{collect_unique_values_if_categorical, label_is_enum_eligible};
const PVC_DEFAULT_ENUM_THRESHOLD: usize = 32;
#[test]
fn pvc_enum_omitted_for_non_categorical_label() {
let values: Vec<String> = [
"Australia/Sydney",
"Europe/London",
"America/New_York",
"America/Los_Angeles",
"Asia/Tokyo",
"Asia/Shanghai",
"Africa/Lagos",
"Africa/Cairo",
"America/Chicago",
"Europe/Paris",
"Europe/Berlin",
"America/Sao_Paulo",
]
.iter()
.map(|s| (*s).to_string())
.collect();
assert!(!label_is_enum_eligible("datetime.offset.iana"));
let result = collect_unique_values_if_categorical(
"datetime.offset.iana",
&values,
PVC_DEFAULT_ENUM_THRESHOLD,
);
assert!(
result.is_none(),
"expected None for non-enum-eligible label, got {:?}",
result
);
}
#[test]
fn pvc_enum_kept_for_boolean_terms_label() {
let values: Vec<String> = [
"yes", "no", "y", "n", "true", "false", "yes", "yes", "no", "no",
]
.iter()
.map(|s| (*s).to_string())
.collect();
assert!(label_is_enum_eligible("representation.boolean.terms"));
let result = collect_unique_values_if_categorical(
"representation.boolean.terms",
&values,
PVC_DEFAULT_ENUM_THRESHOLD,
);
let enum_values = result.expect("expected Some(enum) for boolean.terms under threshold");
assert_eq!(
enum_values,
vec!["false", "n", "no", "true", "y", "yes"],
"enum values should be sorted unique"
);
}
#[test]
fn pvc_enum_omitted_when_cardinality_exceeds_default() {
let values: Vec<String> = (0..40).map(|i| format!("category_{i:02}")).collect();
assert!(label_is_enum_eligible(
"representation.discrete.categorical"
));
let result = collect_unique_values_if_categorical(
"representation.discrete.categorical",
&values,
PVC_DEFAULT_ENUM_THRESHOLD,
);
assert!(
result.is_none(),
"expected None when cardinality (40) > threshold (32), got {:?}",
result.as_ref().map(|v| v.len())
);
let v32: Vec<String> = (0..32).map(|i| format!("c_{i:02}")).collect();
let v33: Vec<String> = (0..33).map(|i| format!("c_{i:02}")).collect();
assert!(collect_unique_values_if_categorical(
"representation.discrete.categorical",
&v32,
PVC_DEFAULT_ENUM_THRESHOLD
)
.is_some());
assert!(collect_unique_values_if_categorical(
"representation.discrete.categorical",
&v33,
PVC_DEFAULT_ENUM_THRESHOLD
)
.is_none());
}