| 183 | } |
| 184 | |
| 185 | func TestRpad(t *testing.T) { |
| 186 | tests := []struct { |
| 187 | name string |
| 188 | inputString string |
| 189 | padding int |
| 190 | expected string |
| 191 | }{ |
| 192 | { |
| 193 | name: "Padding required", |
| 194 | inputString: "Hello", |
| 195 | padding: 10, |
| 196 | expected: "Hello ", |
| 197 | }, |
| 198 | { |
| 199 | name: "No padding required", |
| 200 | inputString: "World", |
| 201 | padding: 5, |
| 202 | expected: "World", |
| 203 | }, |
| 204 | { |
| 205 | name: "Empty string", |
| 206 | inputString: "", |
| 207 | padding: 8, |
| 208 | expected: " ", |
| 209 | }, |
| 210 | { |
| 211 | name: "Zero padding", |
| 212 | inputString: "cobra", |
| 213 | padding: 0, |
| 214 | expected: "cobra", |
| 215 | }, |
| 216 | } |
| 217 | |
| 218 | for _, tt := range tests { |
| 219 | t.Run(tt.name, func(t *testing.T) { |
| 220 | // Act |
| 221 | got := rpad(tt.inputString, tt.padding) |
| 222 | |
| 223 | // Assert |
| 224 | if got != tt.expected { |
| 225 | t.Errorf("Expected rpad: %v\nGot: %v", tt.expected, got) |
| 226 | } |
| 227 | }) |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | // TestDeadcodeElimination checks that a simple program using cobra in its |
| 232 | // default configuration is linked taking full advantage of the linker's |