| 228 | } |
| 229 | |
| 230 | void TestParse(const Test* tests, int ntests, Regexp::ParseFlags flags, |
| 231 | const std::string& title) { |
| 232 | Regexp** re = new Regexp*[ntests]; |
| 233 | for (int i = 0; i < ntests; i++) { |
| 234 | RegexpStatus status; |
| 235 | Regexp::ParseFlags f = flags; |
| 236 | if (tests[i].flags != 0) { |
| 237 | f = tests[i].flags & ~TestZeroFlags; |
| 238 | } |
| 239 | re[i] = Regexp::Parse(tests[i].regexp, f, &status); |
| 240 | ASSERT_TRUE(re[i] != NULL) |
| 241 | << " " << tests[i].regexp << " " << status.Text(); |
| 242 | std::string s = re[i]->Dump(); |
| 243 | EXPECT_EQ(std::string(tests[i].parse), s) |
| 244 | << "Regexp: " << tests[i].regexp |
| 245 | << "\nparse: " << std::string(tests[i].parse) |
| 246 | << " s: " << s << " flag=" << f; |
| 247 | } |
| 248 | |
| 249 | for (int i = 0; i < ntests; i++) { |
| 250 | for (int j = 0; j < ntests; j++) { |
| 251 | EXPECT_EQ(std::string(tests[i].parse) == std::string(tests[j].parse), |
| 252 | RegexpEqualTestingOnly(re[i], re[j])) |
| 253 | << "Regexp: " << tests[i].regexp << " " << tests[j].regexp; |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | for (int i = 0; i < ntests; i++) |
| 258 | re[i]->Decref(); |
| 259 | delete[] re; |
| 260 | } |
| 261 | |
| 262 | // Test that regexps parse to expected structures. |
| 263 | TEST(TestParse, SimpleRegexps) { |