diff options
Diffstat (limited to 'cmd/krino/review_test.go')
| -rw-r--r-- | cmd/krino/review_test.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/cmd/krino/review_test.go b/cmd/krino/review_test.go index b138451..fc175cb 100644 --- a/cmd/krino/review_test.go +++ b/cmd/krino/review_test.go @@ -11,6 +11,7 @@ import ( "testing" "unicode/utf8" + "krino/internal/engine" "krino/internal/plan" "krino/internal/scan" ) @@ -326,3 +327,41 @@ func TestStopAfterApply(t *testing.T) { } } } + +// TestReviewHeadingsCannotFakeAStepLine: a long name in the per-file +// heading of review and of undo wraps with its continuation past the column +// step labels use, so the name cannot pass for a step (plan 11 review L4). +func TestReviewHeadingsCannotFakeAStepLine(t *testing.T) { + old := widthPolicy + t.Cleanup(func() { widthPolicy = old }) + widthPolicy = func(io.Writer) int { return 60 } + name := strings.Repeat("x", 50) + " DELETE permanently" + + out := new(strings.Builder) + cs := []plan.Chain{{File: scan.File{Rel: name}, Steps: []plan.Step{{Kind: plan.Move, Rule: "r", Dst: "/w/Out/a.pdf"}}}} + if _, _, _, err := reviewChains(strings.NewReader("cy"), out, cs, "/w", palette{}); err != nil { + t.Fatal(err) + } + for _, l := range strings.Split(out.String(), "\n") { + if strings.HasPrefix(strings.TrimLeft(l, " "), "DELETE") { + t.Errorf("review: a line reads as a step: %q\n%s", l, out) + } + if n := cols(l); n > 60 { + t.Errorf("review: a line of %d columns, over 60, which the terminal wraps: %q", n, l) + } + } + + out.Reset() + files := []engine.UndoFile{{Dir: "dl", File: name, Steps: []engine.UndoStep{{Action: "undo-move", Src: "/t/a", Dst: "/s/a"}}}} + if _, _, err := reviewUndoFiles(strings.NewReader("cy"), out, files, palette{}); err != nil { + t.Fatal(err) + } + for _, l := range strings.Split(out.String(), "\n") { + if strings.HasPrefix(strings.TrimLeft(l, " "), "DELETE") { + t.Errorf("undo: a line reads as a step: %q\n%s", l, out) + } + if n := cols(l); n > 60 { + t.Errorf("undo: a line of %d columns, over 60, which the terminal wraps: %q", n, l) + } + } +} |
