package app import ( "path/filepath" "testing" ) func TestRemapPath(t *testing.T) { old := filepath.Join("C:", "work", "a.go") target := filepath.Join("C:", "work", "b.go") cases := []struct { in string want string ok bool }{ {old, target, true}, {old + ".bak", old + ".bak", false}, // 同名前缀的邻居不能动 {filepath.Join("C:", "work", "other.go"), filepath.Join("C:", "work", "other.go"), false}, } for _, c := range cases { got, ok := remapPath(c.in, old, target) if got != c.want || ok != c.ok { t.Fatalf("remapPath(%q)=(%q,%v),期望 (%q,%v)", c.in, got, ok, c.want, c.ok) } } } func TestRemapPathDir(t *testing.T) { old := filepath.Join("C:", "work", "pkg") target := filepath.Join("C:", "work", "lib") inside := filepath.Join(old, "sub", "x.go") got, ok := remapPath(inside, old, target) if !ok || got != filepath.Join(target, "sub", "x.go") { t.Fatalf("目录内文件应跟着搬: (%q,%v)", got, ok) } sibling := filepath.Join("C:", "work", "pkg2", "y.go") got, ok = remapPath(sibling, old, target) if ok || got != sibling { t.Fatalf("同前缀的兄弟目录不能动: (%q,%v)", got, ok) } }