MCPcopy Create free account
hub / github.com/codereader/DarkRadiant / parseBlock

Function parseBlock

test/DefBlockSyntaxParser.cpp:402–439  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

400}
401
402inline 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
441inline void parseBlock(const std::string& testString,
442 const std::string& expectedName, const std::string& needleToFindInBlockContents)

Callers 2

TEST_FFunction · 0.85
parseMethod · 0.85

Calls 10

splitFunction · 0.85
foreachBlockMethod · 0.80
getBlockContentsMethod · 0.80
parseMethod · 0.45
beginMethod · 0.45
findMethod · 0.45
getStringMethod · 0.45
getTypeMethod · 0.45
getNameMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected