diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-17 14:14:26 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-17 14:14:26 +0200 |
| commit | 6d28cf285f9944eb26c7ed0efcce558521b51cb9 (patch) | |
| tree | 6fac77b186ab34300528bba80350ca48a655b12e /gui/internal/model/forms_test.go | |
| parent | ed86f44a926fd1f0d438cbe5e2e10ad5b063db55 (diff) | |
| download | krino-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/forms_test.go')
| -rw-r--r-- | gui/internal/model/forms_test.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/gui/internal/model/forms_test.go b/gui/internal/model/forms_test.go index efbd662..46b5820 100644 --- a/gui/internal/model/forms_test.go +++ b/gui/internal/model/forms_test.go @@ -238,3 +238,56 @@ func labels(forms []Form) []string { } return out } + +// TestDeleteFormLeavesItsNeighbourAlone: a form's block is whole lines, so +// deleting one of two forms written on the same line took both. The dialog +// names one; the other vanished, the file still parsed, the check said "no +// errors" and Save lit - so an (exclude ...) could disappear silently and +// the next run would sort the files it had been protecting. +func TestDeleteFormLeavesItsNeighbourAlone(t *testing.T) { + r := openForms(t, "(path \"~/dl\")\n\n"+ + "(exclude (name \"^keep-\")) (exclude (name \"^hold-\"))\n\n"+ + "(rule \"rest\" (move \"Other\"))\n") + before, err := r.Forms() + if err != nil { + t.Fatal(err) + } + if len(before) != 3 { + t.Fatalf("fixture has %d forms, want 3 (two excludes and one rule)", len(before)) + } + if err := r.DeleteForm(0); err != nil { // the first exclude + t.Fatal(err) + } + if strings.Contains(r.Text, "^keep-") { + t.Error("the exclude that was asked for is still there") + } + if !strings.Contains(r.Text, "^hold-") { + t.Errorf("deleting the first exclude took the second with it:\n%s", r.Text) + } + if !strings.Contains(r.Text, `(rule "rest"`) { + t.Errorf("the rule is gone too:\n%s", r.Text) + } + after, err := r.Forms() + if err != nil { + t.Fatalf("the text no longer parses: %v\n%s", err, r.Text) + } + if len(after) != 2 { + t.Errorf("%d forms left, want 2:\n%s", len(after), r.Text) + } +} + +// TestDeleteFormTakesTheWholeLineWhenItIsAlone: the ordinary case is +// unchanged - a form on its own lines goes with its line, leaving no blank +// where it was. +func TestDeleteFormTakesTheWholeLineWhenItIsAlone(t *testing.T) { + r := openForms(t, "(path \"~/dl\")\n\n(exclude (name \"^keep-\"))\n\n(rule \"rest\" (move \"Other\"))\n") + if err := r.DeleteForm(0); err != nil { + t.Fatal(err) + } + if strings.Contains(r.Text, "^keep-") { + t.Error("the exclude is still there") + } + if strings.Contains(r.Text, "\n\n\n") { + t.Errorf("a blank line was left where the form was:\n%q", r.Text) + } +} |
