diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-16 01:34:45 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-16 01:34:45 +0200 |
| commit | ecfaeabf2a92e26c6a521d5fac404a0fff6263b6 (patch) | |
| tree | 4147dd6809a45fe5b773447352354dbee2295900 /internal/config/enum_test.go | |
| parent | be4b1275c76b9cad984dfafaa8023db94eb3eecf (diff) | |
| download | krino-ecfaeabf2a92e26c6a521d5fac404a0fff6263b6.tar.gz krino-ecfaeabf2a92e26c6a521d5fac404a0fff6263b6.zip | |
milestone 1 review: claims span the run, explain's chain is opt-in and its own, overrides keyed by clean path, splice and enum guards
Diffstat (limited to 'internal/config/enum_test.go')
| -rw-r--r-- | internal/config/enum_test.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/internal/config/enum_test.go b/internal/config/enum_test.go new file mode 100644 index 0000000..2e5b718 --- /dev/null +++ b/internal/config/enum_test.go @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package config + +import ( + "strings" + "testing" + + "krino/internal/enumtest" +) + +// TestEverySettingValuePrintsAsItselfInAConfig: PrintRule writes settings +// with their String(), so every Conflict and CaseMode value must print as +// the word a configuration uses, and parse back as that same value. A value +// added later without its branch would otherwise print as "Conflict(3)", +// which krino check refuses (plan 13 review F5). +func TestEverySettingValuePrintsAsItselfInAConfig(t *testing.T) { + for _, c := range []struct { + typ, form string + printed func(int) string + parsed func(*Rule) string + }{ + {"Conflict", "on-conflict", func(i int) string { return Conflict(i).String() }, + func(r *Rule) string { return r.Settings.OnConflict.String() }}, + {"CaseMode", "case", func(i int) string { return CaseMode(i).String() }, + func(r *Rule) string { return r.Settings.Case.String() }}, + } { + names, err := enumtest.Names("settings.go", c.typ) + if err != nil { + t.Fatal(err) + } + if len(names) == 0 { + t.Fatalf("no %s values found", c.typ) + } + for i, name := range names { + word := c.printed(i) + if strings.ContainsAny(word, "()0123456789") { + t.Errorf("%s.String() = %q; give it a word a configuration uses", name, word) + continue + } + src := "(path \"/tmp\")\n(rule \"r\" (" + c.form + " " + word + ") (move \"Out\"))\n" + dir, errs := ParseDir("dl", "dl.conf", []byte(src)) + if len(errs) > 0 { + t.Errorf("%s prints as %q, which krino check refuses: %v", name, word, errs) + continue + } + if got := c.parsed(dir.Rules[0]); got != word { + t.Errorf("%s prints as %q but parses back as %q", name, word, got) + } + } + } +} |
