Skip to content
Draft
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
2 changes: 1 addition & 1 deletion spec/System/TestStatDescriber_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe("StatDescriber getScope scenarios", function()
for _, case in ipairs(cases) do
it(case.name, function()
ConPrintf("[StatDescriber getScope] %s", case.name)
local describe = require("Modules/StatDescriber")
local describe = require("Modules/StatDescriber").describeStats

if case.shouldSucceed then
local out, lineMap = describe(case.stats, case.scope)
Expand Down
9 changes: 0 additions & 9 deletions spec/System/TestTradeQueryGenerator_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@ describe("TradeQueryGenerator", function()
local mock_queryGen = new("TradeQueryGenerator", { itemsTab = {} })

describe("ProcessMod", function()
-- Pass: Mod line maps correctly to trade stat entry without error
-- Fail: Mapping fails (e.g., no match found), indicating incomplete stat parsing for curse mods, potentially missing curse-enabling items in queries
it("handles special curse case", function()
local mod = { tradeHashes = {[30642521] = {"You can apply an additional Curse"}}, type = "Prefix", weightKey = {}, weightVal = {} }
mock_queryGen.modData = { Explicit = {} }
mock_queryGen:ProcessMod(mod)
-- Simplified assertion; in full impl, check modData
assert.is_true(true)
end)
end)

describe("WeightedRatioOutputs", function()
Expand Down
111 changes: 111 additions & 0 deletions spec/System/TestUtils_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
describe("Utils.stringify", function()
local utils = require("Modules/Utils")

-- Parses stringify output back into a Lua value
local function serializeAndLoad(value, allowNewlines)
local str = utils.stringify(value, allowNewlines)
local chunk, err = loadstring("return "..str)
assert.is_truthy(chunk)
return chunk(), str
end

describe("scalars", function()
it("stringifies strings with quotes", function()
assert.equal('"hello"', utils.stringify("hello"))
end)

it("strips newlines from strings by default", function()
assert.equal('"a b"', utils.stringify("a\nb"))
end)

it("preserves newlines as long strings when allowed", function()
assert.equal("[[a\nb]]", utils.stringify("a\nb", true))
end)

it("does not use long string form for newline-free strings", function()
assert.equal('"ab"', utils.stringify("ab", true))
end)

it("stringifies numbers", function()
assert.equal("42", utils.stringify(42))
assert.equal("-3.5", utils.stringify(-3.5))
end)

it("stringifies booleans", function()
assert.equal("true", utils.stringify(true))
assert.equal("false", utils.stringify(false))
end)

it("stringifies nil", function()
assert.equal("nil", utils.stringify(nil))
end)

-- supposedly these are valid table keys, but like come on
it("errors on disallowed types", function()
assert.has_error(function() utils.stringify(function() end) end)
assert.has_error(function() utils.stringify({[ function() end ] = "hello"}) end)
end)
end)

describe("tables", function()
it("serializes and loads an empty table", function()
local out = serializeAndLoad({})
assert.same({}, out)
end)

it("serializes and loads an array using array syntax", function()
local input = { 1, 2, 3 }
local out, str = serializeAndLoad(input)
assert.same(input, out)
-- array entries should not include explicit keys
assert.is_nil(str:find("%[1%]"))
end)

it("serializes and loads a string-keyed map", function()
local input = { foo = "bar", baz = 1 }
local out = serializeAndLoad(input)
assert.same(input, out)
end)

it("serializes and loads nested tables (no mixed array/map levels)", function()
local input = { a = { b = { c = { deep = true, value = 3 } } }, list = { "x", "y" } }
local out = serializeAndLoad(input)
assert.same(input, out)
end)

it("sorts map keys deterministically", function()
local str = utils.stringify({ c = 1, a = 1, b = 1 })
local posA = str:find('%["a"%]')
local posB = str:find('%["b"%]')
local posC = str:find('%["c"%]')
assert.is_truthy(posA < posB and posB < posC)
end)

it("serializes and loads numeric (non-sequential) keys", function()
local input = { [5] = "five", [10] = "ten" }
local out = serializeAndLoad(input)
assert.same(input, out)
end)

it("serializes and loads multiline string values when allowed", function()
local input = { text = "line1\nline2" }
local out = serializeAndLoad(input, true)
assert.same(input, out)
end)

it("serializes and loads mixed tables", function()
local input = {"one", "two", six = 7, 3, 4, five = "six"}
local str = utils.stringify(input, false, 1)
assert.equal([[{
"one",
"two",
3,
4,
["five"] = "six",
["six"] = 7,
}]], str)
local out = serializeAndLoad(input)
assert.same(input, out)
end)
end)
end)
Loading
Loading