util.format: Fix some formats expecting positive numbers in Lua 5.2

Amazing how string.format behaves differently under each Lua version
This commit is contained in:
Kim Alvefur 2021-12-11 20:54:37 +01:00
parent db41cd8e4d
commit d482ece962
2 changed files with 9 additions and 4 deletions

View file

@ -287,7 +287,7 @@ describe("util.format", function()
describe("to %o", function ()
it("works", function ()
assert.equal("141", format("%o", 97))
assert.equal("1777777777777777747707", format("%o", -12345))
assert.equal("[-12345]", format("%o", -12345))
assert.equal("[1.5]", format("%o", 1.5))
assert.equal("[7.3786976294838e+19]", format("%o", 73786976294838206464))
assert.equal("[inf]", format("%o", math.huge))
@ -298,7 +298,7 @@ describe("util.format", function()
describe("to %u", function ()
it("works", function ()
assert.equal("97", format("%u", 97))
assert.equal("18446744073709539271", format("%u", -12345))
assert.equal("[-12345]", format("%u", -12345))
assert.equal("[1.5]", format("%u", 1.5))
assert.equal("[7.3786976294838e+19]", format("%u", 73786976294838206464))
assert.equal("[inf]", format("%u", math.huge))
@ -309,7 +309,7 @@ describe("util.format", function()
describe("to %x", function ()
it("works", function ()
assert.equal("61", format("%x", 97))
assert.equal("ffffffffffffcfc7", format("%x", -12345))
assert.equal("[-12345]", format("%x", -12345))
assert.equal("[1.5]", format("%x", 1.5))
assert.equal("[7.3786976294838e+19]", format("%x", 73786976294838206464))
assert.equal("[inf]", format("%x", math.huge))
@ -320,7 +320,7 @@ describe("util.format", function()
describe("to %X", function ()
it("works", function ()
assert.equal("61", format("%X", 97))
assert.equal("FFFFFFFFFFFFCFC7", format("%X", -12345))
assert.equal("[-12345]", format("%X", -12345))
assert.equal("[1.5]", format("%X", 1.5))
assert.equal("[7.3786976294838e+19]", format("%X", 73786976294838206464))
assert.equal("[inf]", format("%X", math.huge))