refactor: 删除更多未使用的死代码

- parse.go: 删除 RemoveDuplicate 函数及其测试
- parsers.go: 删除 excludeHosts, removeDuplicates 别名函数
- 更新测试使用真正的函数名
This commit is contained in:
ZacharyZcR
2026-01-21 23:43:07 +08:00
parent f18b51ca92
commit be76e272a5
4 changed files with 9 additions and 415 deletions
+9 -9
View File
@@ -790,46 +790,46 @@ func TestExcludeHosts(t *testing.T) {
hosts := []string{"host1", "host2", "host3", "host4"}
exclude := []string{"host2", "host4"}
result := excludeHosts(hosts, exclude)
result := excludeFromList(hosts, exclude)
expected := []string{"host1", "host3"}
if !reflect.DeepEqual(result, expected) {
t.Errorf("excludeHosts = %v, want %v", result, expected)
t.Errorf("excludeFromList = %v, want %v", result, expected)
}
t.Logf("✓ excludeHosts: %d → %d", len(hosts), len(result))
t.Logf("✓ excludeFromList: %d → %d", len(hosts), len(result))
}
// TestExcludeHosts_EmptyExclude 测试空排除列表
func TestExcludeHosts_EmptyExclude(t *testing.T) {
hosts := []string{"host1", "host2"}
result := excludeHosts(hosts, []string{})
result := excludeFromList(hosts, []string{})
if !reflect.DeepEqual(result, hosts) {
t.Errorf("excludeHosts(空排除列表) 应该返回原列表")
t.Errorf("excludeFromList(空排除列表) 应该返回原列表")
}
}
// TestRemoveDuplicates 测试去重
func TestRemoveDuplicates(t *testing.T) {
input := []string{"a", "b", "a", "c", "b", "d"}
result := removeDuplicates(input)
result := removeDuplicateStrings(input)
// 验证无重复
seen := make(map[string]bool)
for _, item := range result {
if seen[item] {
t.Errorf("removeDuplicates 结果包含重复项: %s", item)
t.Errorf("removeDuplicateStrings 结果包含重复项: %s", item)
}
seen[item] = true
}
// 验证长度
if len(result) != 4 {
t.Errorf("removeDuplicates 返回%d项,期望4项", len(result))
t.Errorf("removeDuplicateStrings 返回%d项,期望4项", len(result))
}
t.Logf("✓ removeDuplicates: %d → %d", len(input), len(result))
t.Logf("✓ removeDuplicateStrings: %d → %d", len(input), len(result))
}
// TestRemoveDuplicatePorts 测试端口去重
-12
View File
@@ -487,15 +487,3 @@ func removeDuplicatePorts(slice []int) []int {
}
// =============================================================================
// 导出别名(供测试使用)
// =============================================================================
// excludeHosts 是 excludeFromList 的别名(供测试兼容)
func excludeHosts(hosts, excludeList []string) []string {
return excludeFromList(hosts, excludeList)
}
// removeDuplicates 是 removeDuplicateStrings 的别名(供测试兼容)
func removeDuplicates(slice []string) []string {
return removeDuplicateStrings(slice)
}