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