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

Function expectDeclIsPresentInFile

test/DeclManager.cpp:1284–1322  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1282}
1283
1284inline void expectDeclIsPresentInFile(const ITestDeclaration::Ptr& decl, const std::string& path, bool expectPresent)
1285{
1286 auto contents = algorithm::loadTextFromVfsFile(path);
1287
1288 parser::DefBlockSyntaxParser<const std::string> parser(contents);
1289 auto syntaxTree = parser.parse();
1290
1291 std::vector<parser::DefBlockSyntax::Ptr> foundBlocks;
1292 auto declName = string::to_lower_copy(decl->getDeclName());
1293
1294 // Run a check against our custom decl
1295 auto hasAllKeyValuePairs = true;
1296
1297 syntaxTree->foreachBlock([&] (const parser::DefBlockSyntax::Ptr& block)
1298 {
1299 auto blockContents = block->getBlockContents();
1300
1301 if (block->getName() && string::to_lower_copy(block->getName()->getString()) == declName)
1302 {
1303 foundBlocks.push_back(block);
1304
1305 // Every key and every value must be present in the file
1306 decl->foreachKeyValue([&](std::pair<std::string, std::string> pair)
1307 {
1308 hasAllKeyValuePairs &= blockContents.find("\"" + pair.first + "\"") != std::string::npos;
1309 hasAllKeyValuePairs &= blockContents.find("\"" + pair.second + "\"") != std::string::npos;
1310 });
1311 }
1312 });
1313
1314 if (expectPresent)
1315 {
1316 EXPECT_EQ(foundBlocks.size() && hasAllKeyValuePairs, 1) << "Expected exactly one decl " << declName << " in the contents in the file";
1317 }
1318 else
1319 {
1320 EXPECT_TRUE(foundBlocks.empty() || !hasAllKeyValuePairs) << "Expected no decl " << declName << " in the contents in the file";
1321 }
1322}
1323
1324// Save a new declaration to a file on disk
1325TEST_F(DeclManagerTest, SaveNewDeclToNewFile)

Callers 1

TEST_FFunction · 0.85

Calls 13

loadTextFromVfsFileFunction · 0.85
to_lower_copyFunction · 0.85
getDeclNameMethod · 0.80
foreachBlockMethod · 0.80
getBlockContentsMethod · 0.80
foreachKeyValueMethod · 0.80
parseMethod · 0.45
getNameMethod · 0.45
getStringMethod · 0.45
push_backMethod · 0.45
findMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected