| 400 | } |
| 401 | |
| 402 | inline void parseBlock(const std::string& testString, |
| 403 | const std::vector<std::pair<std::string, std::string>>& expectedBlocks) |
| 404 | { |
| 405 | // Use the stream parser variant (even though we could parse right from the string) |
| 406 | std::istringstream stream{ testString }; |
| 407 | parser::DefBlockSyntaxParser<std::istream> parser(stream); |
| 408 | auto syntaxTree = parser.parse(); |
| 409 | |
| 410 | // Check that the expected blocks appear in the syntax tree, in the correct order |
| 411 | auto expectedBlock = expectedBlocks.begin(); |
| 412 | |
| 413 | syntaxTree->foreachBlock([&](const parser::DefBlockSyntax::Ptr& block) |
| 414 | { |
| 415 | if (expectedBlock->first.find(' ') != std::string::npos) |
| 416 | { |
| 417 | // Check name and type |
| 418 | std::vector<std::string> parts; |
| 419 | string::split(parts, expectedBlock->first, " \t"); |
| 420 | EXPECT_EQ(block->getType()->getString(), parts[0]); |
| 421 | EXPECT_EQ(block->getName()->getString(), parts[1]); |
| 422 | } |
| 423 | else |
| 424 | { |
| 425 | if (expectedBlock->first.empty()) |
| 426 | { |
| 427 | EXPECT_TRUE(!block->getName() || block->getName()->getString().empty()); |
| 428 | } |
| 429 | else |
| 430 | { |
| 431 | EXPECT_EQ(block->getName()->getString(), expectedBlock->first); |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | EXPECT_NE(block->getBlockContents().find(expectedBlock->second), std::string::npos); |
| 436 | |
| 437 | ++expectedBlock; |
| 438 | }); |
| 439 | } |
| 440 | |
| 441 | inline void parseBlock(const std::string& testString, |
| 442 | const std::string& expectedName, const std::string& needleToFindInBlockContents) |