use crate::codegen::cfg::cfg_default_and_forwarding_lines;
use std::collections::{BTreeSet, HashSet};
fn set(names: &[&str]) -> BTreeSet<String> {
names.iter().map(|n| (*n).to_string()).collect()
}
#[test]
fn builds_default_line_then_one_forwarding_row_per_feature() {
let features = set(&["chunking-tokenizers", "ner"]);
let excluded = HashSet::new();
let lines = cfg_default_and_forwarding_lines(&features, "core-lib", &excluded);
assert_eq!(
lines,
vec![
r#"default = ["chunking-tokenizers", "ner"]"#.to_string(),
r#"chunking-tokenizers = ["core-lib/chunking-tokenizers"]"#.to_string(),
r#"ner = ["core-lib/ner"]"#.to_string(),
],
"got: {lines:?}"
);
}
#[test]
fn excluded_default_feature_is_forwarded_but_not_defaulted() {
let features = set(&["chunking-tokenizers", "heic"]);
let excluded: HashSet<&str> = ["heic"].into_iter().collect();
let lines = cfg_default_and_forwarding_lines(&features, "core-lib", &excluded);
assert_eq!(
lines[0], r#"default = ["chunking-tokenizers"]"#,
"excluded name must not appear in default: {lines:?}"
);
assert!(
lines.contains(&r#"heic = ["core-lib/heic"]"#.to_string()),
"excluded name must still get a forwarding row: {lines:?}"
);
}
#[test]
fn empty_feature_set_still_emits_a_default_line_with_no_forwarding_rows() {
let features = BTreeSet::new();
let excluded = HashSet::new();
let lines = cfg_default_and_forwarding_lines(&features, "core-lib", &excluded);
assert_eq!(lines, vec!["default = []".to_string()], "got: {lines:?}");
}