aboutsummaryrefslogtreecommitdiff
path: root/internal/tui/tui_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/tui/tui_test.go')
-rw-r--r--internal/tui/tui_test.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/internal/tui/tui_test.go b/internal/tui/tui_test.go
index a3640ac..614f239 100644
--- a/internal/tui/tui_test.go
+++ b/internal/tui/tui_test.go
@@ -51,6 +51,28 @@ func TestHeight(t *testing.T) {
}
}
+// TestWidth: the terminal's column count, and 0 wherever there is no
+// terminal to wrap to, so a caller treats 0 as "never wrap".
+func TestWidth(t *testing.T) {
+ var buf bytes.Buffer
+ if w := Width(&buf); w != 0 {
+ t.Errorf("Width on a non-terminal writer = %d, want 0", w)
+ }
+
+ oldT, oldS := isTerminal, termSize
+ t.Cleanup(func() { isTerminal, termSize = oldT, oldS })
+ isTerminal = func(fd int) bool { return true }
+ termSize = func(fd int) (int, int, error) { return 132, 24, nil }
+ if w := Width(os.Stdout); w != 132 {
+ t.Errorf("Width = %d, want 132", w)
+ }
+
+ termSize = func(fd int) (int, int, error) { return 0, 0, os.ErrInvalid }
+ if w := Width(os.Stdout); w != 0 {
+ t.Errorf("Width when the size cannot be read = %d, want 0", w)
+ }
+}
+
func TestPageUsesPagerOnlyWhenTaller(t *testing.T) {
dir := t.TempDir()
marker := filepath.Join(dir, "paged")