| 2488 | } |
| 2489 | |
| 2490 | func TestRegexp(t *testing.T) { |
| 2491 | t.Parallel() |
| 2492 | |
| 2493 | mockT := new(testing.T) |
| 2494 | |
| 2495 | cases := []struct { |
| 2496 | rx, str string |
| 2497 | }{ |
| 2498 | {"^start", "start of the line"}, |
| 2499 | {"end$", "in the end"}, |
| 2500 | {"end$", "in the end"}, |
| 2501 | {"[0-9]{3}[.-]?[0-9]{2}[.-]?[0-9]{2}", "My phone number is 650.12.34"}, |
| 2502 | } |
| 2503 | |
| 2504 | for _, tc := range cases { |
| 2505 | True(t, Regexp(mockT, tc.rx, tc.str)) |
| 2506 | True(t, Regexp(mockT, regexp.MustCompile(tc.rx), tc.str)) |
| 2507 | True(t, Regexp(mockT, regexp.MustCompile(tc.rx), []byte(tc.str))) |
| 2508 | False(t, NotRegexp(mockT, tc.rx, tc.str)) |
| 2509 | False(t, NotRegexp(mockT, tc.rx, []byte(tc.str))) |
| 2510 | False(t, NotRegexp(mockT, regexp.MustCompile(tc.rx), tc.str)) |
| 2511 | } |
| 2512 | |
| 2513 | cases = []struct { |
| 2514 | rx, str string |
| 2515 | }{ |
| 2516 | {"^asdfastart", "Not the start of the line"}, |
| 2517 | {"end$", "in the end."}, |
| 2518 | {"[0-9]{3}[.-]?[0-9]{2}[.-]?[0-9]{2}", "My phone number is 650.12a.34"}, |
| 2519 | } |
| 2520 | |
| 2521 | for _, tc := range cases { |
| 2522 | False(t, Regexp(mockT, tc.rx, tc.str), "Expected %q to not match %q", tc.rx, tc.str) |
| 2523 | False(t, Regexp(mockT, regexp.MustCompile(tc.rx), tc.str)) |
| 2524 | False(t, Regexp(mockT, regexp.MustCompile(tc.rx), []byte(tc.str))) |
| 2525 | True(t, NotRegexp(mockT, tc.rx, tc.str)) |
| 2526 | True(t, NotRegexp(mockT, tc.rx, []byte(tc.str))) |
| 2527 | True(t, NotRegexp(mockT, regexp.MustCompile(tc.rx), tc.str)) |
| 2528 | } |
| 2529 | } |
| 2530 | |
| 2531 | func testAutogeneratedFunction() { |
| 2532 | defer func() { |