Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions spec/System/TestStatDescriber_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
describe("StatDescriber getScope scenarios", function()
before_each(function()
newBuild()
end)

teardown(function()
-- newBuild() resets environment in setup()
end)

local cases = {
{ name = "should_load_lowercase_prefixed_herald_scope", scope = "specific_skill_stat_descriptions/herald_of_thunder_statset_1", stats = {}, shouldSucceed = true, expectedOutputLines = 0 },
{ name = "should_load_herald_scope_without_prefix", scope = "herald_of_thunder_statset_1", stats = {}, shouldSucceed = true, expectedOutputLines = 0 },
{ name = "should_load_alchemist_boon_scope", scope = "alchemist_boon", stats = {}, shouldSucceed = true, expectedOutputLines = 0 },
{ name = "should_load_skill_stat_descriptions", scope = "skill_stat_descriptions", stats = {}, shouldSucceed = true, expectedOutputLines = 0 },
{ name = "should_generate_output_for_life_stat", scope = "stat_descriptions", stats = { base_maximum_life = 50 }, shouldSucceed = true, expectedOutputLines = 1 },
{ name = "should_generate_output_for_alchemist_boon_flask_recovery", scope = "alchemist_boon", stats = { ["recovery_from_flasks_applies_to_allies_in_presence_%"] = 30 }, shouldSucceed = true, expectedOutputLines = 1 },
{ name = "should_generate_output_for_fireball_area_radius", scope = "fireball", stats = { active_skill_base_area_of_effect_radius = 15 }, shouldSucceed = true, expectedOutputLines = 1 },
{ name = "should_fail_for_nonexistent_scope", scope = "definitely_nonexistent_scope_12345", stats = {}, shouldSucceed = false },
{ name = "should_fail_for_nonexistent_prefixed_scope", scope = "specific_skill_stat_descriptions/definitely_nonexistent_scope_12345", stats = {}, shouldSucceed = false },
}

for _, case in ipairs(cases) do
it(case.name, function()
ConPrintf("[StatDescriber getScope] %s", case.name)
local describe = require("Modules/StatDescriber")

if case.shouldSucceed then
local out, lineMap = describe(case.stats, case.scope)
assert.are.equal("table", type(out))
assert.are.equal("table", type(lineMap))
if case.expectedOutputLines then
assert.are.equal(case.expectedOutputLines, #out)
end
else
local ok, err = pcall(function()
describe(case.stats, case.scope)
end)
assert.False(ok)
assert.is_string(err)
end
end)
end
end)
11 changes: 7 additions & 4 deletions src/Modules/StatDescriber.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ local scopes = { }
local function getScope(scopeName)
if not scopes[scopeName] then
local scope = nil
local file = io.open("Data/StatDescriptions/specific_skill_stat_descriptions/"..scopeName..".lua", 'rb')
-- Allow lowercase "specific_skill_stat_descriptions/<name>" by stripping the prefix (Linux is case-sensitive).
local normalizedScopeName = scopeName:gsub("^specific_skill_stat_descriptions/", "")

local file = io.open("Data/StatDescriptions/Specific_Skill_Stat_Descriptions/"..normalizedScopeName..".lua", 'rb')
if file then
file.close()
scope = LoadModule("Data/StatDescriptions/Specific_Skill_Stat_Descriptions/"..scopeName)
file:close()
scope = LoadModule("Data/StatDescriptions/Specific_Skill_Stat_Descriptions/"..normalizedScopeName)
else
scope = LoadModule("Data/StatDescriptions/"..scopeName)
scope = LoadModule("Data/StatDescriptions/"..normalizedScopeName)
end
scope.name = scopeName
if scope.parent then
Expand Down