aboutsummaryrefslogtreecommitdiff
path: root/internal/config/enum_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/config/enum_test.go')
-rw-r--r--internal/config/enum_test.go52
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)
+ }
+ }
+ }
+}