跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

fuzz_test.go

38 行 · 1.2 KB历史下载
1package paths
2
3import (
4 "strings"
5 "testing"
6)
7
8// In and CutPrefix, case ignored or not: no panic, the rest is a suffix of
9// the path as spelled, and joined back it is the path again.
10func FuzzIn(f *testing.F) {
11 for _, s := range [][2]string{{"/a/b/c", "/a/b"}, {"/A/B", "/a/b"}, {"/a/bc", "/a/b"}, {"/İ/x", "/i̇"}, {"/ß/x", "/SS"}, {"/K/x", "/k"}, {"/", "/"}} {
12 f.Add(s[0], s[1], false)
13 f.Add(s[0], s[1], true)
14 }
15 f.Fuzz(func(t *testing.T, p, dir string, nocase bool) {
16 old := NoCase
17 NoCase = func() bool { return nocase }
18 defer func() { NoCase = old }()
19 if rest, ok := CutPrefix(p, dir); ok && !strings.HasSuffix(p, rest) {
20 t.Fatalf("CutPrefix(%q, %q) = %q, not the end of the path", p, dir, rest)
21 }
22 rel, ok := In(p, dir)
23 if !ok {
24 return
25 }
26 if rel == "." {
27 // dir itself, or dir/. as spelled.
28 p, dir := strings.TrimSuffix(p, "/"), strings.TrimSuffix(dir, "/")
29 if !Equal(p, dir) && !Equal(p, dir+"/.") {
30 t.Fatalf("In(%q, %q) = \".\"", p, dir)
31 }
32 return
33 }
34 if p := strings.TrimSuffix(p, "/"); !strings.HasSuffix(p, rel) || !Equal(p, strings.TrimSuffix(dir, "/")+"/"+rel) {
35 t.Fatalf("In(%q, %q) = %q", p, dir, rel)
36 }
37 })
38}