| 1282 | } |
| 1283 | |
| 1284 | inline 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 |
| 1325 | TEST_F(DeclManagerTest, SaveNewDeclToNewFile) |
no test coverage detected