| 27 | } |
| 28 | |
| 29 | TEST(LuaConfigurationTest, ValidOMWScripts) |
| 30 | { |
| 31 | ESM::LuaScriptsCfg cfg; |
| 32 | LuaUtil::parseOMWScripts(cfg, R"X( |
| 33 | # Lines starting with '#' are comments |
| 34 | GLOBAL: my_mod/#some_global_script.lua |
| 35 | |
| 36 | # Script that will be automatically attached to the player |
| 37 | PLAYER :my_mod/player.lua |
| 38 | CUSTOM : my_mod/some_other_script.lua |
| 39 | NPC , CREATURE PLAYER : my_mod/some_other_script.lua)X"); |
| 40 | LuaUtil::parseOMWScripts(cfg, ":my_mod/player.LUA \r\nCREATURE,CUSTOM: my_mod/creature.lua\r\n"); |
| 41 | |
| 42 | ASSERT_EQ(cfg.mScripts.size(), 6); |
| 43 | EXPECT_EQ(LuaUtil::scriptCfgToString(cfg.mScripts[0]), "GLOBAL : my_mod/#some_global_script.lua"); |
| 44 | EXPECT_EQ(LuaUtil::scriptCfgToString(cfg.mScripts[1]), "PLAYER : my_mod/player.lua"); |
| 45 | EXPECT_EQ(LuaUtil::scriptCfgToString(cfg.mScripts[2]), "CUSTOM : my_mod/some_other_script.lua"); |
| 46 | EXPECT_EQ(LuaUtil::scriptCfgToString(cfg.mScripts[3]), "PLAYER NPC CREATURE : my_mod/some_other_script.lua"); |
| 47 | EXPECT_EQ(LuaUtil::scriptCfgToString(cfg.mScripts[4]), ": my_mod/player.lua"); |
| 48 | EXPECT_EQ(LuaUtil::scriptCfgToString(cfg.mScripts[5]), "CUSTOM CREATURE : my_mod/creature.lua"); |
| 49 | |
| 50 | LuaUtil::ScriptsConfiguration conf; |
| 51 | conf.init(std::move(cfg), false); |
| 52 | ASSERT_EQ(conf.size(), 4); |
| 53 | EXPECT_EQ(LuaUtil::scriptCfgToString(conf[0]), "GLOBAL : my_mod/#some_global_script.lua"); |
| 54 | // cfg.mScripts[1] is overridden by cfg.mScripts[4] |
| 55 | // cfg.mScripts[2] is overridden by cfg.mScripts[3] |
| 56 | EXPECT_EQ(LuaUtil::scriptCfgToString(conf[1]), "PLAYER NPC CREATURE : my_mod/some_other_script.lua"); |
| 57 | EXPECT_EQ(LuaUtil::scriptCfgToString(conf[2]), ": my_mod/player.lua"); |
| 58 | EXPECT_EQ(LuaUtil::scriptCfgToString(conf[3]), "CUSTOM CREATURE : my_mod/creature.lua"); |
| 59 | |
| 60 | EXPECT_THAT(asVector(conf.getGlobalConf()), ElementsAre(Pair(0, ""))); |
| 61 | EXPECT_THAT(asVector(conf.getPlayerConf()), ElementsAre(Pair(1, ""))); |
| 62 | const ESM::RefId something = ESM::RefId::stringRefId("something"); |
| 63 | |
| 64 | EXPECT_THAT(asVector(conf.getLocalConf(ESM::REC_CONT, something, ESM::RefNum())), ElementsAre()); |
| 65 | EXPECT_THAT(asVector(conf.getLocalConf(ESM::REC_NPC_, something, ESM::RefNum())), ElementsAre(Pair(1, ""))); |
| 66 | EXPECT_THAT(asVector(conf.getLocalConf(ESM::REC_CREA, something, ESM::RefNum())), |
| 67 | ElementsAre(Pair(1, ""), Pair(3, ""))); |
| 68 | |
| 69 | // Check that initialization cleans old data |
| 70 | cfg = ESM::LuaScriptsCfg(); |
| 71 | conf.init(std::move(cfg), false); |
| 72 | EXPECT_EQ(conf.size(), 0); |
| 73 | } |
| 74 | |
| 75 | TEST(LuaConfigurationTest, InvalidOMWScripts) |
| 76 | { |
nothing calls this directly
no test coverage detected