(out string, height int, width int, border bool)
| 126 | } |
| 127 | |
| 128 | func validateRender(out string, height int, width int, border bool) error { |
| 129 | strippedOut := ansi.Strip(out) |
| 130 | |
| 131 | // Empty content is not handled correctly |
| 132 | // strings.Split("", "\n") will return [""], not []. |
| 133 | // Hence we need this separate handling |
| 134 | if height == 0 { |
| 135 | // zero lines |
| 136 | if strippedOut != "" { |
| 137 | return fmt.Errorf("render height mismatch: expected empty string for 0 height, got '%v'", strippedOut) |
| 138 | } |
| 139 | return nil |
| 140 | } |
| 141 | |
| 142 | lines := strings.Split(strippedOut, "\n") |
| 143 | |
| 144 | if len(lines) != height { |
| 145 | return fmt.Errorf("render height mismatch: expected %v lines, got %v", height, len(lines)) |
| 146 | } |
| 147 | |
| 148 | for i, line := range lines { |
| 149 | lineWidth := ansi.StringWidth(line) |
| 150 | if lineWidth != width { |
| 151 | return fmt.Errorf( |
| 152 | "render line %v, expected %v width, got %v(line - '%v')", |
| 153 | i, |
| 154 | width, |
| 155 | lineWidth, |
| 156 | lines[i], |
| 157 | ) |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | if !border { |
| 162 | return nil |
| 163 | } |
| 164 | |
| 165 | return validateRenderBorderValidations(lines) |
| 166 | } |
| 167 | |
| 168 | func validateRenderBorderValidations(lines []string) error { |
| 169 | if len(lines) < minLinesForBorder { |
no test coverage detected