diff options
Diffstat (limited to 'cmd/krino/sort_test.go')
| -rw-r--r-- | cmd/krino/sort_test.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/cmd/krino/sort_test.go b/cmd/krino/sort_test.go new file mode 100644 index 0000000..a646503 --- /dev/null +++ b/cmd/krino/sort_test.go @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package main + +import "testing" + +// TestRelWidthAndPadCellCountRunes: C4. relWidth and padCell must measure +// column width in runes, not bytes, or a name carrying diacritics +// misaligns its column - "próba.txt" is 9 runes but 10 bytes (ó is a +// two-byte UTF-8 sequence), one column narrower than its byte length +// would suggest. +func TestRelWidthAndPadCellCountRunes(t *testing.T) { + rels := []string{"a.txt", "próba.txt"} + if w := relWidth(rels); w != 9 { + t.Fatalf("relWidth(%q) = %d, want 9 (rune count of próba.txt, not its %d bytes)", rels, w, len("próba.txt")) + } + if got, want := padCell("a.txt", 9), "a.txt "; got != want { + t.Fatalf("padCell(%q, 9) = %q, want %q", "a.txt", got, want) + } + if got, want := padCell("próba.txt", 9), "próba.txt"; got != want { + t.Fatalf("padCell(%q, 9) = %q, want %q (already at width: no padding)", "próba.txt", got, want) + } +} |
