Skip to content

Commit

Permalink
#5977: Add unit test checking the precedence of parsed decls with the…
Browse files Browse the repository at this point in the history
… same name (test is failing right now)
  • Loading branch information
codereader committed Jun 26, 2022
1 parent 3a58c3c commit 9cd5976
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/DeclManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,4 +515,16 @@ TEST_F(DeclManagerTest, ReloadDeclarationsIncreasesParseStamp)
EXPECT_NE(decl->getParseStamp(), firstParseStamp) << "Parse stamp should have changed on reload";
}

TEST_F(DeclManagerTest, DeclarationPrecedence)
{
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
GlobalDeclarationManager().registerDeclFolder(decl::Type::Material, "testdecls", ".decl");

expectMaterialIsPresent(decl::Type::Material, "decl/precedence_test/1");

// The first decl in the file precedence_test1.decl takes precedence over any decls
// declared in the same file or other files sorted after precedence_test1.decl
expectMaterialContains(decl::Type::Material, "decl/precedence_test/1", "diffusemap textures/numbers/1");
}

}
14 changes: 14 additions & 0 deletions test/resources/tdm/testdecls/precedence_test1.decl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Test declarations used for precedence tests

// This first decl makes the cut
// all following decls with the same type and name are ignored and warned about
decl/precedence_test/1
{
diffusemap textures/numbers/1
}

decl/precedence_test/1
{
diffusemap textures/numbers/2
}

8 changes: 8 additions & 0 deletions test/resources/tdm/testdecls/precedence_test2.decl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Test declarations used for precedence tests

// This one is ignored since a decl in the precedence_test1.decl has already been declared with this name
// The file precedence_test1.decl is sorted before precedence_test2.decl, so it takes precedence
decl/precedence_test/1
{
diffusemap textures/numbers/3
}

0 comments on commit 9cd5976

Please sign in to comment.