Skip to content

Commit

Permalink
#6031: Add a misleading commented out declaration on top of the real …
Browse files Browse the repository at this point in the history
…one, this is throwing the splice helper off its rails
  • Loading branch information
codereader committed Aug 7, 2022
1 parent 6288cb6 commit bea4004
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/DeclManager.cpp
Expand Up @@ -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<TestDeclarationCreator>());
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<TestDeclarationCreator>());
Expand Down
14 changes: 14 additions & 0 deletions test/resources/tdm/testdecls/removal_tests.decl
Expand Up @@ -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
}

0 comments on commit bea4004

Please sign in to comment.