TestErrorMessageFormat verifies that error messages match stdlib format. stdlib returns *syntax.Error directly with format: "error parsing regexp: ..."
(t *testing.T)
| 11 | // TestErrorMessageFormat verifies that error messages match stdlib format. |
| 12 | // stdlib returns *syntax.Error directly with format: "error parsing regexp: ..." |
| 13 | func TestErrorMessageFormat(t *testing.T) { |
| 14 | patterns := []string{ |
| 15 | "[invalid", |
| 16 | `\`, |
| 17 | "(abc", |
| 18 | "*abc", |
| 19 | `\8`, |
| 20 | } |
| 21 | |
| 22 | for _, pattern := range patterns { |
| 23 | t.Run(pattern, func(t *testing.T) { |
| 24 | _, stdlibErr := regexp.Compile(pattern) |
| 25 | _, ourErr := Compile(pattern) |
| 26 | |
| 27 | if stdlibErr == nil { |
| 28 | t.Skip("stdlib accepts this pattern") |
| 29 | } |
| 30 | |
| 31 | if ourErr == nil { |
| 32 | t.Fatalf("Compile(%q) expected error, got nil", pattern) |
| 33 | } |
| 34 | |
| 35 | // Error messages should match exactly |
| 36 | if ourErr.Error() != stdlibErr.Error() { |
| 37 | t.Errorf("error message mismatch:\n got: %q\n want: %q", |
| 38 | ourErr.Error(), stdlibErr.Error()) |
| 39 | } |
| 40 | }) |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | // TestMustCompilePanicFormat verifies MustCompile panic message matches stdlib format. |
| 45 | func TestMustCompilePanicFormat(t *testing.T) { |