| 236 | } |
| 237 | |
| 238 | func TestParseMainParams(t *testing.T) { |
| 239 | tests := []struct { |
| 240 | name string |
| 241 | give []string |
| 242 | want mainParams |
| 243 | wantErr []string // non-empty if we expect an error |
| 244 | }{ |
| 245 | { |
| 246 | name: "stdin", |
| 247 | want: mainParams{ |
| 248 | Patterns: []string{"-"}, |
| 249 | ImplicitStdin: true, |
| 250 | }, |
| 251 | }, |
| 252 | } |
| 253 | |
| 254 | for _, tt := range tests { |
| 255 | t.Run(tt.name, func(t *testing.T) { |
| 256 | var got mainParams |
| 257 | err := got.Parse(testWriter{t}, tt.give) |
| 258 | |
| 259 | if len(tt.wantErr) > 0 { |
| 260 | if err == nil { |
| 261 | t.Fatalf("expected error, got nil") |
| 262 | } |
| 263 | |
| 264 | for _, want := range tt.wantErr { |
| 265 | if got := err.Error(); !strings.Contains(got, want) { |
| 266 | t.Errorf("error %q does not contain %q", got, want) |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | return |
| 271 | } |
| 272 | |
| 273 | if want, got := tt.want, got; !reflect.DeepEqual(want, got) { |
| 274 | t.Errorf("got %v, want %v", got, want) |
| 275 | } |
| 276 | }) |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | func TestParseFormatFlag(t *testing.T) { |
| 281 | tests := []struct { |