Skip to content
Open
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
15 changes: 15 additions & 0 deletions spec/System/TestItemMods_spec.lua.rej
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff a/spec/System/TestItemMods_spec.lua b/spec/System/TestItemMods_spec.lua (rejected hunks)
@@ -7,6 +7,13 @@ describe("TetsItemMods", function()
-- newBuild() takes care of resetting everything in setup()
end)

+ it("retains mod tags without generation weight multipliers", function()
+ local mod = data.itemMods.Item.IgniteChanceIncrease1
+
+ assert.same({ "no_cold_spell_mods", "no_lightning_spell_mods", "no_chaos_spell_mods" }, mod.tags)
+ assert.is_nil(mod.weightMultiplierKey)
+ end)
+
it("shows duplicate selected variants in item tooltips when enabled", function()
local item = new("Item", [[
Rarity: Unique
134 changes: 134 additions & 0 deletions spec/System/TestUtils_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
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 when allowed", function()
local out = serializeAndLoad("a\nb", true)
assert.equal("a\nb", out)
end)

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

it("escapes quotes and backslashes", function()
local input = 'a"b\\c'
local out = serializeAndLoad(input, true)
assert.equal(input, out)
end)

it("preserves carriage returns and long-string delimiters when allowed", function()
local input = "a\r\n]]b"
local out = serializeAndLoad(input, true)
assert.equal(input, out)
end)

it("normalizes all newline forms when newlines are disabled", function()
assert.equal('"a b c"', utils.stringify("a\r\nb\rc"))
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 escaped multiline string keys", function()
local input = { ['a"\\b\n]]c'] = true }
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)
64 changes: 64 additions & 0 deletions src/Classes/TradeQueryGenerator.lua.rej
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
diff a/src/Classes/TradeQueryGenerator.lua b/src/Classes/TradeQueryGenerator.lua (rejected hunks)
@@ -10,6 +10,7 @@ local m_max = math.max
local s_format = string.format
local t_insert = table.insert
local tradeHelpers = LoadModule("Classes/TradeHelpers")
+local utils = LoadModule("Modules/Utils")

-- string are an any type while tables require all fields to be matched with type and subType require both to be matched exactly. [1] type, [2] subType, subType is optional and must be nil if not present.
local tradeCategoryNames = {
@@ -395,11 +396,6 @@ function TradeQueryGeneratorClass:InitMods()
error("Error received from api/trade2/data/stats: "..body.error.message)
end

- local f = io.open("./Data/TradeSiteStats.lua", "w")
- if not f then
- error("Could not open file for writing trade stat data")
- end
-
for catIdx, _ in ipairs(body.result) do
table.sort(body.result[catIdx].entries, function(a, b)
if a.text == b.text then
@@ -409,14 +405,8 @@ function TradeQueryGeneratorClass:InitMods()
end)
end

- local template = [[-- This file is automatically downloaded, do not edit!
--- Trade site stat data (c) Grinding Gear Games
--- https://www.pathofexile.com/api/trade2/data/stats
--- spell-checker: disable
-return %s
--- spell-checker: enable]]
- f:write(s_format(template, stringify(body.result)))
- f:close()
+ local description = "This file contains the trade site data from https://www.pathofexile.com/api/trade2/data/stats"
+ utils.saveTableToFile("./Data/TradeSiteStats.lua", body.result, description)

self.modData = {
["Explicit"] = { },
@@ -636,19 +626,12 @@ return %s
end
end

- local queryModsFile = io.open(queryModFilePath, 'w')
- queryModsFile:write([[-- This file is automatically generated, do not edit!
--- Stat data (c) Grinding Gear Games
-
--- This file contains categories of stats, mapped from trade hash to details
--- relevant for generating search weights Note that the trade site requires a
--- prefix of e.g. explicit.stat_{hash}. See
--- https://www.pathofexile.com/api/trade2/data/stats for a list of all trade
--- site stats.
-
-]])
- queryModsFile:write("return " .. stringify(self.modData))
- queryModsFile:close()
+ local qmDescription = [[This file contains categories of stats, mapped from trade hash to details
+relevant for generating search weights Note that the trade site requires a
+prefix of e.g. explicit.stat_{hash}. See
+TradeSiteStats.lua for a list of all trade
+site stats.]]
+ utils.saveTableToFile(queryModFilePath, self.modData, qmDescription)
end

function TradeQueryGeneratorClass:GenerateModWeights(modsToTest)
3 changes: 2 additions & 1 deletion src/Classes/TradeQueryRequests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
--

local dkjson = require "dkjson"
local utils = LoadModule("Modules/Utils")

---@class TradeQueryRequests
local TradeQueryRequestsClass = newClass("TradeQueryRequests", function(self, rateLimiter)
Expand Down Expand Up @@ -210,7 +211,7 @@ function TradeQueryRequestsClass:PerformSearch(realm, league, query, callback)
if response.error then
if not (response.error.code and response.error.message) then
errMsg = "Encountered unknown error, check console for details."
ConPrintf("Unknown error: %s", stringify(response.error))
ConPrintf("Unknown error: %s", utils.stringify(response.error))
callback(response, errMsg)
end
if response.error.message:find("Logging in will increase this limit") then
Expand Down
Loading