diff --git a/test/DeclManager.cpp b/test/DeclManager.cpp index faef11be2a..d07ec05528 100644 --- a/test/DeclManager.cpp +++ b/test/DeclManager.cpp @@ -903,6 +903,36 @@ TEST_F(DeclManagerTest, RemoveDeclarationRemovesLeadingMultilineComment) EXPECT_TRUE(algorithm::fileContainsText(fullPath, "// Some comments after decl/removal/2")); } +// There's an evil misleading commented out declaration decl/removal/9 in the file +// right before the actual, uncommented one +TEST_F(DeclManagerTest, RemoveDeclarationIgnoresCommentedContent) +{ + GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared()); + GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, ".decl"); + + // Create a backup copy of the decl file we're going to manipulate + auto fullPath = _context.getTestProjectPath() + "testdecls/removal_tests.decl"; + BackupCopy backup(fullPath); + + // decl/removal/9 has a commented declaration above the actual one + EXPECT_TRUE(algorithm::fileContainsText(fullPath, R"(/* +testdecl decl/removal/9 +{ + diffusemap textures/old/5 +} +*/)")); + expectDeclIsPresent(decl::Type::TestDecl, "decl/removal/9"); + + GlobalDeclarationManager().removeDeclaration(decl::Type::TestDecl, "decl/removal/9"); + + EXPECT_TRUE(algorithm::fileContainsText(fullPath, R"(/* +testdecl decl/removal/9 +{ + diffusemap textures/old/5 +} +*/)")) << "The decl manager removed the wrong declaration"; +} + TEST_F(DeclManagerTest, RemoveUnsavedDeclaration) { GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared()); diff --git a/test/resources/tdm/testdecls/removal_tests.decl b/test/resources/tdm/testdecls/removal_tests.decl index 9717fcef2a..b6eda196e2 100644 --- a/test/resources/tdm/testdecls/removal_tests.decl +++ b/test/resources/tdm/testdecls/removal_tests.decl @@ -40,3 +40,17 @@ testdecl decl/removal/6 { diffusemap textures/removal/6 } testdecl decl/removal/7 { diffusemap textures/removal/7 } testdecl decl/removal/8 { diffusemap textures/removal/8 } + +// An old, commented out version of a decl that should not be touched +// This is trying to mislead the splice helper cutting out the decl +/* +testdecl decl/removal/9 +{ + diffusemap textures/old/5 +} +*/ + +testdecl decl/removal/9 +{ + diffusemap textures/removal/5 +}