aboutsummaryrefslogtreecommitdiff
path: root/gui/internal/model/mainconf_test.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-09-17 14:14:26 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-09-17 14:14:26 +0200
commit6d28cf285f9944eb26c7ed0efcce558521b51cb9 (patch)
tree6fac77b186ab34300528bba80350ca48a655b12e /gui/internal/model/mainconf_test.go
parented86f44a926fd1f0d438cbe5e2e10ad5b063db55 (diff)
downloadkrino-6d28cf285f9944eb26c7ed0efcce558521b51cb9.tar.gz
krino-6d28cf285f9944eb26c7ed0efcce558521b51cb9.zip
editing one form no longer takes its neighbour with it
A form's span was whole lines, which is wrong the moment two forms share one. Delete: "(exclude A) (exclude B)" on one line, delete the first, both went. The dialog named one. The file still parsed, the live check said no errors and Save lit, so an exclusion could disappear silently and the next run would sort the files it had been protecting. Clear a setting: the same shape, and the Settings window walked into it itself - it writes "(defaults\n (case ignore))", so the closing paren of defaults sits on the setting's line, and putting that setting back to "default" deleted the line and broke the file it had just written. Every later change then silently reverted until Settings was reopened. A hand-written "(defaults (case ignore) (fold yes))" lost fold the same way, and that one still loaded, so it was saveable. Both now take the whole line only when the line holds nothing else, and otherwise take the form and the spaces after it. One helper, used by the main file and by a directory's settings alike.
Diffstat (limited to 'gui/internal/model/mainconf_test.go')
-rw-r--r--gui/internal/model/mainconf_test.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/gui/internal/model/mainconf_test.go b/gui/internal/model/mainconf_test.go
index c77591c..bd7720e 100644
--- a/gui/internal/model/mainconf_test.go
+++ b/gui/internal/model/mainconf_test.go
@@ -167,3 +167,34 @@ func TestMainSettingRefusesAnUnknownHead(t *testing.T) {
t.Error("an unknown setting was read")
}
}
+
+// TestClearingASettingKeepsTheRestOfItsLine: clearing removed whole lines,
+// so a setting sharing a line with anything else took it too. The Settings
+// window writes "(defaults\n (case ignore))" itself - the closing paren of
+// defaults sits on the setting's line - so setting a value and putting it
+// back to "default" broke the file it had just written, and every later
+// change silently reverted.
+func TestClearingASettingKeepsTheRestOfItsLine(t *testing.T) {
+ m, _, _ := mainConf(t, "(include \"dl\")\n")
+ if err := m.SetSetting("case", "ignore"); err != nil {
+ t.Fatal(err)
+ }
+ if err := m.SetSetting("case", ""); err != nil {
+ t.Fatal(err)
+ }
+ if diags := m.Check(); len(diags) > 0 {
+ t.Errorf("the text no longer loads after set-then-clear: %v\n%s", diags[0], m.Text)
+ }
+
+ // The other half: a hand-written one-line (defaults ...).
+ m2, _, _ := mainConf(t, "(include \"dl\")\n(defaults (case ignore) (fold yes))\n")
+ if err := m2.SetSetting("case", ""); err != nil {
+ t.Fatal(err)
+ }
+ if !strings.Contains(m2.Text, "(fold yes)") {
+ t.Errorf("clearing (case ...) took (fold yes) from the same line:\n%s", m2.Text)
+ }
+ if diags := m2.Check(); len(diags) > 0 {
+ t.Errorf("the text no longer loads: %v\n%s", diags[0], m2.Text)
+ }
+}