aboutsummaryrefslogtreecommitdiff
path: root/cmd/krino/render_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/krino/render_test.go')
-rw-r--r--cmd/krino/render_test.go55
1 files changed, 53 insertions, 2 deletions
diff --git a/cmd/krino/render_test.go b/cmd/krino/render_test.go
index 9df75f4..a964b43 100644
--- a/cmd/krino/render_test.go
+++ b/cmd/krino/render_test.go
@@ -182,8 +182,10 @@ func TestPrintPlanWrapsToWidth(t *testing.T) {
}
gotName := strings.TrimPrefix(lines[start], " 1 ")
i := start + 1
- for ; i < len(lines) && strings.HasPrefix(lines[i], " ") && !strings.HasPrefix(lines[i], " move"); i++ {
- gotName += strings.TrimPrefix(lines[i], " ")
+ // Continuation lines start at the value column (13), never at the
+ // label column (5), so a name cannot pass for a step line.
+ for ; i < len(lines) && strings.HasPrefix(lines[i], " ") && !strings.HasPrefix(lines[i], " move"); i++ {
+ gotName += strings.TrimPrefix(lines[i], " ")
}
if gotName != name {
t.Errorf("wrapped name reads %q, want %q\n%s", gotName, name, out)
@@ -375,3 +377,52 @@ func TestSkipSummaryLineAccountsForEveryFile(t *testing.T) {
acting, excluded, allSkipped, len(r.Unmatched), len(r.Skipped), scanned)
}
}
+
+// TestWrappedNameCannotFakeAStepLine: a long name's continuation lines start
+// at the value column, not at the column step labels use, so a name holding
+// "rename → x" cannot pass for a step of its own block (triage 28l).
+func TestWrappedNameCannotFakeAStepLine(t *testing.T) {
+ home(t)
+ name := strings.Repeat("a", 30) + " rename → evil.pdf"
+ dp := &engine.DirPlan{
+ Dir: &engine.Dir{Name: "dl", Root: "/r"},
+ Chains: []plan.Chain{{File: scan.File{Rel: name}, Steps: []plan.Step{{Kind: plan.Move, Rule: "r", Src: "/r/" + name, Dst: "/r/Out/" + name}}}},
+ Result: &engine.Result{Matched: []engine.FileMatch{{File: scan.File{Rel: name}}}},
+ }
+ var buf bytes.Buffer
+ printPlan(&buf, dp, false, palette{}, 40)
+ for _, l := range strings.Split(buf.String(), "\n") {
+ if strings.HasPrefix(l, " ") && len(l) > 5 && l[5] != ' ' && !strings.HasPrefix(l, " move") && !strings.HasPrefix(l, " rule") {
+ t.Errorf("a line at the label column that is not a step: %q\n%s", l, buf.String())
+ }
+ }
+}
+
+// TestColumnsCountWideAndCombiningCharacters: widths and wrapping count
+// terminal columns - two for a CJK character, none for a combining mark -
+// so a name in a wide script neither overruns the terminal nor misaligns
+// its column (triage 28j).
+func TestColumnsCountWideAndCombiningCharacters(t *testing.T) {
+ if n := cols("漢字"); n != 4 {
+ t.Errorf("cols(漢字) = %d, want 4", n)
+ }
+ if n := cols("éx"); n != 2 {
+ t.Errorf("cols(e + combining acute + x) = %d, want 2", n)
+ }
+ if got := padCell("漢字", 6); got != "漢字 " {
+ t.Errorf("padCell(漢字, 6) = %q, want two spaces of padding", got)
+ }
+ if w := relWidth([]string{"a.txt", "漢字.txt"}); w != 8 {
+ t.Errorf("relWidth = %d, want 8", w)
+ }
+ s := strings.Repeat("漢字", 5)
+ pieces := wrapText(s, 5)
+ if strings.Join(pieces, "") != s {
+ t.Fatalf("wrapText lost text: %q", pieces)
+ }
+ for _, p := range pieces {
+ if cols(p) > 5 {
+ t.Errorf("piece %q is %d columns, over 5", p, cols(p))
+ }
+ }
+}