diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-14 14:08:36 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-14 14:08:36 +0200 |
| commit | 1d3f2d1e4c59867024470d3444e12698b7ebb22e (patch) | |
| tree | 4fa14f455c72f9b206a680dcc1b0f4c1f3708158 /internal/config/dir_test.go | |
| parent | 07c24054cab965800983ef40f53a05c2db131ede (diff) | |
| download | krino-1d3f2d1e4c59867024470d3444e12698b7ebb22e.tar.gz krino-1d3f2d1e4c59867024470d3444e12698b7ebb22e.zip | |
0.0.4: max-size, exclude forms, --min-agev0.0.4
Diffstat (limited to 'internal/config/dir_test.go')
| -rw-r--r-- | internal/config/dir_test.go | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/internal/config/dir_test.go b/internal/config/dir_test.go index 7ddfa2a..080905c 100644 --- a/internal/config/dir_test.go +++ b/internal/config/dir_test.go @@ -4,6 +4,7 @@ package config import ( "reflect" + "strings" "testing" ) @@ -111,7 +112,7 @@ func TestParseDirErrors(t *testing.T) { {`(path "/a") (rule "x" (delete) (move "y"))`, `d.conf:1:32: rule "x": (move "y") after delete would never run`}, {`(path "/a") (rule "x" (stop now))`, `d.conf:1:23: rule "x": stop takes nothing: write (stop)`}, {`(path "/a") (rule "x" (fly "y"))`, `d.conf:1:23: rule "x": unknown form (fly ...); a rule has when, copy, move, rename, delete, stop, case, fold and on-conflict`}, - {`(path "/a") (sort "x")`, `d.conf:1:13: unknown form (sort ...); a directory file has path, ignore, rule and settings like (recursive yes)`}, + {`(path "/a") (sort "x")`, `d.conf:1:13: unknown form (sort ...); a directory file has path, ignore, exclude, rule and settings like (recursive yes)`}, } for _, tt := range tests { _, errs := ParseDir("d", "d.conf", []byte(tt.src)) @@ -120,3 +121,36 @@ func TestParseDirErrors(t *testing.T) { } } } + +// TestParseExclude: (exclude COND...) may repeat; each form keeps its +// conditions (all must hold, as in when) and its text as written, with the +// whitespace collapsed, for check and explain to show. +func TestParseExclude(t *testing.T) { + src := `(path "/tmp") +(exclude (type iso img)) +(exclude (name "^draft") + (content "poufne")) +` + dir, errs := ParseDir("dl", "dl.conf", []byte(src)) + if len(errs) != 0 { + t.Fatal(errs) + } + if len(dir.Excludes) != 2 || len(dir.Excludes[0].When) != 1 || len(dir.Excludes[1].When) != 2 { + t.Fatalf("Excludes = %+v", dir.Excludes) + } + if got, want := dir.Excludes[1].Text, `(exclude (name "^draft") (content "poufne"))`; got != want { + t.Errorf("Text = %q, want %q", got, want) + } + if dir.Excludes[1].Pos.Line != 3 { + t.Errorf("Pos = %+v, want line 3", dir.Excludes[1].Pos) + } + for _, tt := range []struct{ src, want string }{ + {"(path \"/tmp\")\n(exclude)\n", "(exclude) needs a condition"}, + {"(path \"/tmp\")\n(exclude iso)\n", "exclude: a condition is a form like (type pdf), not iso"}, + } { + _, errs := ParseDir("dl", "dl.conf", []byte(tt.src)) + if len(errs) != 1 || !strings.Contains(errs[0].Msg, tt.want) { + t.Errorf("%q: errs %v, want one containing %q", tt.src, errs, tt.want) + } + } +} |
