(t *testing.T)
| 123 | } |
| 124 | |
| 125 | func TestProgramNonTTYDimensions(t *testing.T) { |
| 126 | t.Run("non-tty output does not receive fallback dimensions", func(t *testing.T) { |
| 127 | t.Setenv("COLUMNS", "110") |
| 128 | t.Setenv("LINES", "35") |
| 129 | |
| 130 | var buf bytes.Buffer |
| 131 | var in bytes.Buffer |
| 132 | m := &windowSizeModel{} |
| 133 | |
| 134 | p := NewProgram(m, |
| 135 | WithInput(&in), |
| 136 | WithOutput(&buf), |
| 137 | ) |
| 138 | |
| 139 | if _, err := p.Run(); err != nil { |
| 140 | t.Fatalf("unexpected error: %v", err) |
| 141 | } |
| 142 | |
| 143 | if m.windowSize.Width != 0 || m.windowSize.Height != 0 { |
| 144 | t.Errorf("expected WindowSizeMsg 0x0 for non-TTY output, got %dx%d", |
| 145 | m.windowSize.Width, m.windowSize.Height) |
| 146 | } |
| 147 | }) |
| 148 | |
| 149 | t.Run("non-tty output with program environment does not receive fallback dimensions", func(t *testing.T) { |
| 150 | var buf bytes.Buffer |
| 151 | var in bytes.Buffer |
| 152 | m := &windowSizeModel{} |
| 153 | |
| 154 | p := NewProgram(m, |
| 155 | WithInput(&in), |
| 156 | WithOutput(&buf), |
| 157 | WithEnvironment([]string{"COLUMNS=150", "LINES=60"}), |
| 158 | ) |
| 159 | |
| 160 | if _, err := p.Run(); err != nil { |
| 161 | t.Fatalf("unexpected error: %v", err) |
| 162 | } |
| 163 | |
| 164 | if m.windowSize.Width != 0 || m.windowSize.Height != 0 { |
| 165 | t.Errorf("expected WindowSizeMsg 0x0 for non-TTY output, got %dx%d", |
| 166 | m.windowSize.Width, m.windowSize.Height) |
| 167 | } |
| 168 | }) |
| 169 | |
| 170 | t.Run("non-tty output preserves WithWindowSize when specified", func(t *testing.T) { |
| 171 | var buf bytes.Buffer |
| 172 | var in bytes.Buffer |
| 173 | m := &windowSizeModel{} |
| 174 | |
| 175 | p := NewProgram(m, |
| 176 | WithInput(&in), |
| 177 | WithOutput(&buf), |
| 178 | WithWindowSize(120, 50), |
| 179 | ) |
| 180 | |
| 181 | if _, err := p.Run(); err != nil { |
| 182 | t.Fatalf("unexpected error: %v", err) |
nothing calls this directly
no test coverage detected