diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-14 21:24:22 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-14 21:24:22 +0200 |
| commit | 8c6afca96a9f0af41c5a9d05beb7f1dedb994740 (patch) | |
| tree | 8ad65b02ced85ac1cecf6fdaf53269a602cb1666 /internal/plan/fuzz_test.go | |
| parent | a92ce86c0dff7ce8f1de4113f20edd76c249371e (diff) | |
| download | krino-8c6afca96a9f0af41c5a9d05beb7f1dedb994740.tar.gz krino-8c6afca96a9f0af41c5a9d05beb7f1dedb994740.zip | |
plan 9: placeholders stay inside the directory the rule names
Diffstat (limited to 'internal/plan/fuzz_test.go')
| -rw-r--r-- | internal/plan/fuzz_test.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/internal/plan/fuzz_test.go b/internal/plan/fuzz_test.go index fb68f94..6deb225 100644 --- a/internal/plan/fuzz_test.go +++ b/internal/plan/fuzz_test.go @@ -3,13 +3,21 @@ package plan import ( + "path/filepath" + "strings" "testing" "time" + + "krino/internal/config" + "krino/internal/scan" ) // FuzzExpand: expanding any template against any file name never panics, // gives the same answer twice, and never succeeds with a {N} beyond the // capture groups there are - MaxIndex and Expand read placeholders alike. +// Used as a destination - relative, in the home directory, or bare - a +// template never plans a move outside the directory its text names before +// the first placeholder (review M1). func FuzzExpand(f *testing.F) { for _, s := range []string{"{name}", "{stem}{ext}", "{mtime:%Y/%m}", "{1}_{2}", "{{literal}}", "{", "}", "{now:%", "{0}", "{9}", "{99999999999999999999}"} { f.Add(s, "a.b.pdf") @@ -29,5 +37,15 @@ func FuzzExpand(f *testing.F) { if n, err := MaxIndex(tmpl); err == nil && n > 2 && errA == nil { t.Fatalf("Expand(%q) = %q, though it uses {%d} and only 2 groups exist", tmpl, a, n) } + for _, dest := range []string{tmpl, "Out/" + tmpl, "~/docs/" + tmpl} { + in := []Input{{ + File: scan.File{Path: "/r/x.pdf", Rel: "x.pdf", Name: "x.pdf", ModTime: facts.ModTime}, + Rules: []RuleMatch{{Name: "a", Captures: facts.Captures, Actions: []config.Action{{Kind: config.Move, Arg: dest}}}}, + }} + s := Build("/r", in, facts.Now, NoDisk{}, NewClaims())[0].Steps[0] + if strings.ContainsRune(dest, '{') && s.Skip == "" && !within(filepath.Dir(s.Dst), staticDir(dest, "/r")) { + t.Fatalf("destination %q planned %q, outside %q", dest, s.Dst, staticDir(dest, "/r")) + } + } }) } |
