Skip to content

Commit

Permalink
#6189: Add first unit test checking the root cause
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Dec 30, 2022
1 parent ca2c5e1 commit b6411c2
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/DeclManager.cpp
Expand Up @@ -1724,4 +1724,30 @@ decl/temporaryGame/1
fs::remove_all(temporaryFmPath);
}

// #6189: Assigning a new syntax block on a previously missing declaration didn't clear
// the internal _syntaxBlockInvalidated flag of EditableDeclarations, which caused
// the new syntax block contents to be immediately overwritten by generateSyntax()
TEST_F(DeclManagerTest, AssigningSyntaxBlockOverridesModification)
{
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, ".decl");

// Find an existing decl
auto decl = std::static_pointer_cast<TestDeclaration>(
GlobalDeclarationManager().findDeclaration(decl::Type::TestDecl, "decl/numbers/3"));

decl->setKeyValue("description", "This decl is missing and has been modified");
decl->setFileInfo(vfs::FileInfo(TEST_DECL_FOLDER, "_autogenerated.decl", vfs::Visibility::NORMAL));

auto newSyntax = decl->getBlockSyntax();
newSyntax.contents = R"(
"description" "assigned"
)";

// Assigning a new syntax block after parsing should work even if the decl has been modified
decl->setBlockSyntax(newSyntax);

EXPECT_EQ(decl->getKeyValue("description"), "assigned") << "Assigned syntax block didn't take effect";
}

}

0 comments on commit b6411c2

Please sign in to comment.