TestPackageLevelMatchString tests the package-level MatchString function.
(t *testing.T)
| 40 | |
| 41 | // TestPackageLevelMatchString tests the package-level MatchString function. |
| 42 | func TestPackageLevelMatchString(t *testing.T) { |
| 43 | tests := []struct { |
| 44 | pattern string |
| 45 | input string |
| 46 | want bool |
| 47 | }{ |
| 48 | {`\d+`, "hello 123", true}, |
| 49 | {`\d+`, "hello", false}, |
| 50 | {`^hello`, "hello world", true}, |
| 51 | {`^hello`, "say hello", false}, |
| 52 | } |
| 53 | |
| 54 | for _, tt := range tests { |
| 55 | got, err := MatchString(tt.pattern, tt.input) |
| 56 | if err != nil { |
| 57 | t.Errorf("MatchString(%q, %q) error: %v", tt.pattern, tt.input, err) |
| 58 | continue |
| 59 | } |
| 60 | if got != tt.want { |
| 61 | t.Errorf("MatchString(%q, %q) = %v, want %v", tt.pattern, tt.input, got, tt.want) |
| 62 | } |
| 63 | |
| 64 | // Compare with stdlib |
| 65 | stdGot, _ := regexp.MatchString(tt.pattern, tt.input) |
| 66 | if got != stdGot { |
| 67 | t.Errorf("MatchString(%q, %q) = %v, stdlib = %v", tt.pattern, tt.input, got, stdGot) |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // TestCompilePOSIX tests POSIX compilation with leftmost-longest semantics. |
| 73 | func TestCompilePOSIX(t *testing.T) { |
nothing calls this directly
no test coverage detected