(t *testing.T)
| 299 | } |
| 300 | |
| 301 | func TestParseCommaSeparatedInt(t *testing.T) { |
| 302 | t.Parallel() |
| 303 | tt := []struct { |
| 304 | stringCodes string |
| 305 | expectedCodes []int |
| 306 | expectedError string |
| 307 | }{ |
| 308 | {"200,100,202", []int{200, 100, 202}, ""}, |
| 309 | {"200, 100 , 202", []int{200, 100, 202}, ""}, |
| 310 | {"200, 100, 202, 100", []int{200, 100, 202}, ""}, |
| 311 | {"200,AAA", []int{}, "invalid string given: AAA"}, |
| 312 | {"2000000000000000000000000000000", []int{}, "invalid string given: 2000000000000000000000000000000"}, |
| 313 | {"", []int{}, "invalid string provided"}, |
| 314 | {"200-205", []int{200, 201, 202, 203, 204, 205}, ""}, |
| 315 | {"200-202,203-205", []int{200, 201, 202, 203, 204, 205}, ""}, |
| 316 | {"200-202,204-205", []int{200, 201, 202, 204, 205}, ""}, |
| 317 | {"200-202,205", []int{200, 201, 202, 205}, ""}, |
| 318 | {"205,200,100-101,103-105", []int{100, 101, 103, 104, 105, 200, 205}, ""}, |
| 319 | {"200-200", []int{200}, ""}, |
| 320 | {"200 - 202", []int{200, 201, 202}, ""}, |
| 321 | {"200 -202", []int{200, 201, 202}, ""}, |
| 322 | {"200- 202", []int{200, 201, 202}, ""}, |
| 323 | {"200 - 202", []int{200, 201, 202}, ""}, |
| 324 | {"230-200", []int{}, "invalid range given: 230-200"}, |
| 325 | {"A-200", []int{}, "invalid range given: A-200"}, |
| 326 | {"230-A", []int{}, "invalid range given: 230-A"}, |
| 327 | {"200,202-205,A,206-210", []int{}, "invalid string given: A"}, |
| 328 | {"200,202-205,A-1,206-210", []int{}, "invalid range given: A-1"}, |
| 329 | {"200,202-205,1-A,206-210", []int{}, "invalid range given: 1-A"}, |
| 330 | } |
| 331 | |
| 332 | for _, x := range tt { |
| 333 | t.Run(x.stringCodes, func(t *testing.T) { |
| 334 | t.Parallel() |
| 335 | want := NewSet[int]() |
| 336 | want.AddRange(x.expectedCodes) |
| 337 | ret, err := ParseCommaSeparatedInt(x.stringCodes) |
| 338 | if x.expectedError != "" { |
| 339 | if err != nil && err.Error() != x.expectedError { |
| 340 | t.Fatalf("Expected error %q but got %q", x.expectedError, err.Error()) |
| 341 | } |
| 342 | } else if !reflect.DeepEqual(want, ret) { |
| 343 | t.Fatalf("Expected %v but got %v", want, ret) |
| 344 | } |
| 345 | }) |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | func BenchmarkParseExtensions(b *testing.B) { |
| 350 | tt := []struct { |
nothing calls this directly
no test coverage detected