(t *testing.T)
| 1125 | } |
| 1126 | |
| 1127 | func TestStdlibCompat_UnicodePatterns(t *testing.T) { |
| 1128 | // Known differences: negated Unicode property classes may have different |
| 1129 | // boundary handling or empty match behavior |
| 1130 | unicodeKnownDiffs := map[string]string{ |
| 1131 | `\P{Han}+`: "negated Unicode property class boundary handling differs", |
| 1132 | } |
| 1133 | |
| 1134 | patterns := []struct { |
| 1135 | pattern string |
| 1136 | input string |
| 1137 | }{ |
| 1138 | {`[日本語]+`, "日本語test日本語"}, |
| 1139 | {`\p{Han}+`, "test中文test"}, |
| 1140 | {`\P{Han}+`, "abc中文def"}, |
| 1141 | {`[\x{4e00}-\x{9fff}]+`, "test中文test"}, |
| 1142 | } |
| 1143 | |
| 1144 | for _, tc := range patterns { |
| 1145 | t.Run(tc.pattern, func(t *testing.T) { |
| 1146 | if reason, ok := unicodeKnownDiffs[tc.pattern]; ok { |
| 1147 | t.Skipf("Known difference: %s", reason) |
| 1148 | } |
| 1149 | |
| 1150 | stdRe, stdErr := regexp.Compile(tc.pattern) |
| 1151 | cgRe, cgErr := Compile(tc.pattern) |
| 1152 | |
| 1153 | // Both should succeed or both should fail |
| 1154 | if (stdErr == nil) != (cgErr == nil) { |
| 1155 | t.Errorf("Compile error mismatch:\n stdlib: %v\n coregex: %v", stdErr, cgErr) |
| 1156 | return |
| 1157 | } |
| 1158 | |
| 1159 | if stdErr != nil { |
| 1160 | return // Both failed, that's consistent |
| 1161 | } |
| 1162 | |
| 1163 | stdResult := stdRe.FindString(tc.input) |
| 1164 | cgResult := cgRe.FindString(tc.input) |
| 1165 | |
| 1166 | if stdResult != cgResult { |
| 1167 | t.Errorf("FindString(%q, %q):\n stdlib: %q\n coregex: %q", |
| 1168 | tc.pattern, tc.input, stdResult, cgResult) |
| 1169 | } |
| 1170 | }) |
| 1171 | } |
| 1172 | } |
| 1173 | |
| 1174 | func TestStdlibCompat_LimitedFindAll(t *testing.T) { |
| 1175 | pattern := `\d+` |
nothing calls this directly
no test coverage detected