| 998 |
998 |
|
mod tests {
|
| 999 |
999 |
|
use super::*;
|
| 1000 |
1000 |
|
|
| 1001 |
|
- |
// --- TagConfig & validate_with ---
|
| 1002 |
|
- |
|
| 1003 |
1001 |
|
const STRICT: TagConfig = TagConfig {
|
| 1004 |
1002 |
|
max_depth: 3,
|
| 1005 |
1003 |
|
max_length: 30,
|
| 1077 |
1075 |
|
assert!(validate_with("a", &cfg).is_err());
|
| 1078 |
1076 |
|
}
|
| 1079 |
1077 |
|
|
| 1080 |
|
- |
// --- Default validate (backwards compat) ---
|
| 1081 |
|
- |
|
| 1082 |
1078 |
|
#[test]
|
| 1083 |
1079 |
|
fn valid_tags() {
|
| 1084 |
1080 |
|
assert!(validate("genre").is_ok());
|
| 1144 |
1140 |
|
assert!(validate(&ok).is_ok());
|
| 1145 |
1141 |
|
}
|
| 1146 |
1142 |
|
|
| 1147 |
|
- |
// --- segment ---
|
| 1148 |
|
- |
|
| 1149 |
1143 |
|
#[test]
|
| 1150 |
1144 |
|
fn segment_indices() {
|
| 1151 |
1145 |
|
assert_eq!(segment("genre.electronic.house", 0), Some("genre"));
|
| 1160 |
1154 |
|
assert_eq!(segment("genre", 1), None);
|
| 1161 |
1155 |
|
}
|
| 1162 |
1156 |
|
|
| 1163 |
|
- |
// --- prefix_at_depth ---
|
| 1164 |
|
- |
|
| 1165 |
1157 |
|
#[test]
|
| 1166 |
1158 |
|
fn prefix_at_depth_values() {
|
| 1167 |
1159 |
|
assert_eq!(prefix_at_depth("a.b.c.d", 0), None);
|
| 1178 |
1170 |
|
assert_eq!(prefix_at_depth("genre", 2), None);
|
| 1179 |
1171 |
|
}
|
| 1180 |
1172 |
|
|
| 1181 |
|
- |
// --- semantic_prefix / free_suffix ---
|
| 1182 |
|
- |
|
| 1183 |
1173 |
|
#[test]
|
| 1184 |
1174 |
|
fn semantic_prefix_depth_1() {
|
| 1185 |
1175 |
|
assert_eq!(semantic_prefix("genre.electronic.house", 1), Some("genre"));
|
| 1213 |
1203 |
|
assert_eq!(free_suffix("", 0), None);
|
| 1214 |
1204 |
|
}
|
| 1215 |
1205 |
|
|
| 1216 |
|
- |
// --- Parent ---
|
| 1217 |
|
- |
|
| 1218 |
1206 |
|
#[test]
|
| 1219 |
1207 |
|
fn parent_of_nested() {
|
| 1220 |
1208 |
|
assert_eq!(parent("a.b.c"), Some("a.b"));
|
| 1226 |
1214 |
|
assert_eq!(parent("a"), None);
|
| 1227 |
1215 |
|
}
|
| 1228 |
1216 |
|
|
| 1229 |
|
- |
// --- Leaf ---
|
| 1230 |
|
- |
|
| 1231 |
1217 |
|
#[test]
|
| 1232 |
1218 |
|
fn leaf_of_nested() {
|
| 1233 |
1219 |
|
assert_eq!(leaf("a.b.c"), "c");
|
| 1239 |
1225 |
|
assert_eq!(leaf("genre"), "genre");
|
| 1240 |
1226 |
|
}
|
| 1241 |
1227 |
|
|
| 1242 |
|
- |
// --- Depth ---
|
| 1243 |
|
- |
|
| 1244 |
1228 |
|
#[test]
|
| 1245 |
1229 |
|
fn depth_levels() {
|
| 1246 |
1230 |
|
assert_eq!(depth(""), 0);
|
| 1250 |
1234 |
|
assert_eq!(depth("a.b.c.d.e"), 5);
|
| 1251 |
1235 |
|
}
|
| 1252 |
1236 |
|
|
| 1253 |
|
- |
// --- Ancestors ---
|
| 1254 |
|
- |
|
| 1255 |
1237 |
|
#[test]
|
| 1256 |
1238 |
|
fn ancestors_chain() {
|
| 1257 |
1239 |
|
assert_eq!(
|
| 1271 |
1253 |
|
assert_eq!(ancestors("genre.rock"), vec!["genre"]);
|
| 1272 |
1254 |
|
}
|
| 1273 |
1255 |
|
|
| 1274 |
|
- |
// --- is_ancestor_of ---
|
| 1275 |
|
- |
|
| 1276 |
1256 |
|
#[test]
|
| 1277 |
1257 |
|
fn ancestor_relationship() {
|
| 1278 |
1258 |
|
assert!(is_ancestor_of("genre", "genre.electronic"));
|
| 1301 |
1281 |
|
assert!(!is_ancestor_of("genre", "mood.dark"));
|
| 1302 |
1282 |
|
}
|
| 1303 |
1283 |
|
|
| 1304 |
|
- |
// --- common_ancestor ---
|
| 1305 |
|
- |
|
| 1306 |
1284 |
|
#[test]
|
| 1307 |
1285 |
|
fn common_ancestor_siblings() {
|
| 1308 |
1286 |
|
assert_eq!(
|
| 1340 |
1318 |
|
assert_eq!(common_ancestor("genre.rock", "genetic.code"), None);
|
| 1341 |
1319 |
|
}
|
| 1342 |
1320 |
|
|
| 1343 |
|
- |
// --- children_at_prefix ---
|
| 1344 |
|
- |
|
| 1345 |
1321 |
|
#[test]
|
| 1346 |
1322 |
|
fn children_at_root() {
|
| 1347 |
1323 |
|
let tags = [
|
| 1446 |
1422 |
|
);
|
| 1447 |
1423 |
|
}
|
| 1448 |
1424 |
|
|
| 1449 |
|
- |
// --- subtree ---
|
| 1450 |
|
- |
|
| 1451 |
1425 |
|
#[test]
|
| 1452 |
1426 |
|
fn subtree_includes_self_and_descendants() {
|
| 1453 |
1427 |
|
let tags = [
|
| 1480 |
1454 |
|
assert!(result.is_empty());
|
| 1481 |
1455 |
|
}
|
| 1482 |
1456 |
|
|
| 1483 |
|
- |
// --- escape_like ---
|
| 1484 |
|
- |
|
| 1485 |
1457 |
|
#[test]
|
| 1486 |
1458 |
|
fn escape_like_special_chars() {
|
| 1487 |
1459 |
|
assert_eq!(escape_like("100%"), r"100\%");
|
| 1490 |
1462 |
|
assert_eq!(escape_like("normal"), "normal");
|
| 1491 |
1463 |
|
}
|
| 1492 |
1464 |
|
|
| 1493 |
|
- |
// --- like_descendant_pattern ---
|
| 1494 |
|
- |
|
| 1495 |
1465 |
|
#[test]
|
| 1496 |
1466 |
|
fn like_descendant_pattern_simple() {
|
| 1497 |
1467 |
|
assert_eq!(like_descendant_pattern("genre"), "genre.%");
|
| 1506 |
1476 |
|
assert_eq!(like_descendant_pattern("a%b"), r"a\%b.%");
|
| 1507 |
1477 |
|
}
|
| 1508 |
1478 |
|
|
| 1509 |
|
- |
// --- rename_prefix ---
|
| 1510 |
|
- |
|
| 1511 |
1479 |
|
#[test]
|
| 1512 |
1480 |
|
fn rename_descendant() {
|
| 1513 |
1481 |
|
assert_eq!(
|
| 1545 |
1513 |
|
);
|
| 1546 |
1514 |
|
}
|
| 1547 |
1515 |
|
|
| 1548 |
|
- |
// --- TagIndex ---
|
| 1549 |
|
- |
|
| 1550 |
1516 |
|
fn test_index() -> TagIndex {
|
| 1551 |
1517 |
|
TagIndex::new(vec![
|
| 1552 |
1518 |
|
"genre.electronic.house".into(),
|
| 1610 |
1576 |
|
assert_eq!(idx.iter().collect::<Vec<_>>(), vec!["a", "b"]);
|
| 1611 |
1577 |
|
}
|
| 1612 |
1578 |
|
|
| 1613 |
|
- |
// --- suggest: tier 1 (path prefix) ---
|
| 1614 |
|
- |
|
| 1615 |
1579 |
|
#[test]
|
| 1616 |
1580 |
|
fn suggest_full_path_prefix() {
|
| 1617 |
1581 |
|
let idx = test_index();
|
| 1682 |
1646 |
|
);
|
| 1683 |
1647 |
|
}
|
| 1684 |
1648 |
|
|
| 1685 |
|
- |
// --- suggest: tier 2 (segment prefix) ---
|
| 1686 |
|
- |
|
| 1687 |
1649 |
|
#[test]
|
| 1688 |
1650 |
|
fn suggest_segment_prefix_mid_tag() {
|
| 1689 |
1651 |
|
let idx = test_index();
|
| 1755 |
1717 |
|
assert!(idx.suggest("ock", 10).is_empty());
|
| 1756 |
1718 |
|
}
|
| 1757 |
1719 |
|
|
| 1758 |
|
- |
// --- suggest_with_status ---
|
| 1759 |
|
- |
|
| 1760 |
1720 |
|
#[test]
|
| 1761 |
1721 |
|
fn suggest_with_status_exact_exists() {
|
| 1762 |
1722 |
|
let idx = test_index();
|
| 1780 |
1740 |
|
assert!(!exact);
|
| 1781 |
1741 |
|
}
|
| 1782 |
1742 |
|
|
| 1783 |
|
- |
// --- edit_distance ---
|
| 1784 |
|
- |
|
| 1785 |
1743 |
|
#[test]
|
| 1786 |
1744 |
|
fn edit_distance_identical() {
|
| 1787 |
1745 |
|
assert_eq!(edit_distance("genre", "genre", 2), Some(0));
|
| 1826 |
1784 |
|
assert_eq!(edit_distance("", "abc", 2), None);
|
| 1827 |
1785 |
|
}
|
| 1828 |
1786 |
|
|
| 1829 |
|
- |
// --- suggest_fuzzy ---
|
| 1830 |
|
- |
|
| 1831 |
1787 |
|
#[test]
|
| 1832 |
1788 |
|
fn suggest_fuzzy_typo_in_root_segment() {
|
| 1833 |
1789 |
|
let idx = test_index();
|
| 1899 |
1855 |
|
assert_eq!(results[1], "mood.dork");
|
| 1900 |
1856 |
|
}
|
| 1901 |
1857 |
|
|
| 1902 |
|
- |
// --- rename_prefix_bulk ---
|
| 1903 |
|
- |
|
| 1904 |
1858 |
|
#[test]
|
| 1905 |
1859 |
|
fn rename_prefix_bulk_renames_matching() {
|
| 1906 |
1860 |
|
let mut idx = TagIndex::new(vec![
|
| 1925 |
1879 |
|
assert!(idx.contains("genre.rock"));
|
| 1926 |
1880 |
|
}
|
| 1927 |
1881 |
|
|
| 1928 |
|
- |
// --- remove_subtree ---
|
| 1929 |
|
- |
|
| 1930 |
1882 |
|
#[test]
|
| 1931 |
1883 |
|
fn remove_subtree_removes_prefix_and_descendants() {
|
| 1932 |
1884 |
|
let mut idx = TagIndex::new(vec![
|
| 1947 |
1899 |
|
assert_eq!(idx.len(), 1);
|
| 1948 |
1900 |
|
}
|
| 1949 |
1901 |
|
|
| 1950 |
|
- |
// --- merge_tags ---
|
| 1951 |
|
- |
|
| 1952 |
1902 |
|
#[test]
|
| 1953 |
1903 |
|
fn merge_tags_replaces_source() {
|
| 1954 |
1904 |
|
let mut idx = TagIndex::new(vec!["genre.electronic".into(), "genre.rock".into()]);
|
| 2011 |
1961 |
|
assert!(idx.contains("genre.dance.house"));
|
| 2012 |
1962 |
|
}
|
| 2013 |
1963 |
|
|
| 2014 |
|
- |
// --- batch_rename ---
|
| 2015 |
|
- |
|
| 2016 |
1964 |
|
#[test]
|
| 2017 |
1965 |
|
fn batch_rename_multiple_ops() {
|
| 2018 |
1966 |
|
let mut idx = TagIndex::new(vec!["genre.electronic.house".into(), "mood.dark".into()]);
|
| 2032 |
1980 |
|
|
| 2033 |
1981 |
|
// Mutation-coverage tests, added to close gaps surfaced by cargo-mutants.
|
| 2034 |
1982 |
|
// Each test pins down a specific decision boundary that prior tests did
|
| 2035 |
|
- |
// not constrain. See `_private/docs/meta/archive/remediation_todo.md` ยง C1 for context.
|
|
1983 |
+ |
// not constrain.
|
| 2036 |
1984 |
|
|
| 2037 |
1985 |
|
#[test]
|
| 2038 |
1986 |
|
fn tag_error_display_includes_message() {
|