Files
Shuery 0df07ad0ae refactor: 迁移至 bashly CLI 与功能域模块结构
- CLI 定义迁移至 src/bashly.yml(bashly 1.4 生成参数解析),入口收敛为 src/root_command.sh
- 源码按功能域重组:config/storage/integrate/media/pipeline,消除扁平散落
- 新增零依赖测试框架 tests/(123 用例)与 CI 流水线(lint + test + build + 产物一致性)
- build.sh 支持版本单一来源注入与 --check 产物校验;新增 lint.sh(bash -n + shellcheck 零容忍)
- 删除旧单文件 media_organizer.sh 与旧扁平模块
2026-08-14 22:41:28 +08:00

62 lines
2.2 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ============================================================================
# 特典类别判定表外置测试(src/lib/config/maps.sh + ai_resolve.sh)
# ============================================================================
setup() {
TEST_DIR="$(mktemp -d)"
AUTOMATED=true
load_special_categories "$TEST_DIR/categories.json"
}
teardown() {
rm -rf "$TEST_DIR"
}
# load_special_categories:数组加载(顺序 = 优先级)
test_load_special_categories_basic() {
cat >"$TEST_DIR/categories.json" <<'EOF'
[
{"match": "wow", "tag": "新类别"},
{"match": "menu", "tag": "自定义Menu"}
]
EOF
load_special_categories "$TEST_DIR/categories.json"
assert_eq "2" "${#SPECIAL_CATEGORIES[@]}"
# 用户表优先于内置默认表
assert_eq "自定义Menu" "$(special_category_tag "Menu01")"
assert_eq "新类别" "$(special_category_tag "wow01")"
}
# special_category_tag:用户表未命中 → 回退内置默认表
test_special_category_tag_fallback_builtin() {
assert_eq "NCED" "$(special_category_tag "NCED02")"
assert_eq "CM" "$(special_category_tag "TVSP")"
assert_eq "Special" "$(special_category_tag "完全未知词")"
}
# special_category_tag:空表(文件缺失/自动化)→ 内置默认表全量工作
test_special_category_tag_empty_table() {
assert_eq "Menu" "$(special_category_tag "Menu01")"
assert_eq "PV" "$(special_category_tag "Announcement")"
assert_eq "ED" "$(special_category_tag "Lyric")"
assert_eq "Music Video" "$(special_category_tag "MV")"
assert_eq "Picture Drama" "$(special_category_tag "Drama")"
assert_eq "IV" "$(special_category_tag "IV01")"
}
# load_special_categories:非法格式 → 空表不阻断
test_load_special_categories_invalid() {
echo '{"a": 1}' >"$TEST_DIR/categories.json"
load_special_categories "$TEST_DIR/categories.json"
assert_eq "0" "${#SPECIAL_CATEGORIES[@]}"
}
# init_special_categories:自动化 + 文件缺失 → 不创建、空表(内置兜底可用)
test_init_special_categories_automated_missing() {
MATCH_FILE="$TEST_DIR/missing/special_categories.json"
init_special_categories "$MATCH_FILE"
assert_file_absent "$MATCH_FILE"
assert_eq "0" "${#SPECIAL_CATEGORIES[@]}"
assert_eq "Special" "$(special_category_tag "未知")"
}