Comparison

spec/util_format_spec.lua @ 12036:2ce06f788093

util.format: Fix some formats expecting positive numbers in Lua 5.2 Amazing how string.format behaves differently under each Lua version
author Kim Alvefur <zash@zash.se>
date Sat, 11 Dec 2021 20:54:37 +0100
parent 12034:ee94ac51b2dd
child 12039:e0a8c5b1ab4f
comparison
equal deleted inserted replaced
12035:dc7ab05005e8 12036:2ce06f788093
285 end); 285 end);
286 286
287 describe("to %o", function () 287 describe("to %o", function ()
288 it("works", function () 288 it("works", function ()
289 assert.equal("141", format("%o", 97)) 289 assert.equal("141", format("%o", 97))
290 assert.equal("1777777777777777747707", format("%o", -12345)) 290 assert.equal("[-12345]", format("%o", -12345))
291 assert.equal("[1.5]", format("%o", 1.5)) 291 assert.equal("[1.5]", format("%o", 1.5))
292 assert.equal("[7.3786976294838e+19]", format("%o", 73786976294838206464)) 292 assert.equal("[7.3786976294838e+19]", format("%o", 73786976294838206464))
293 assert.equal("[inf]", format("%o", math.huge)) 293 assert.equal("[inf]", format("%o", math.huge))
294 assert.equal("17777777777", format("%o", 2147483647)) 294 assert.equal("17777777777", format("%o", 2147483647))
295 end); 295 end);
296 end); 296 end);
297 297
298 describe("to %u", function () 298 describe("to %u", function ()
299 it("works", function () 299 it("works", function ()
300 assert.equal("97", format("%u", 97)) 300 assert.equal("97", format("%u", 97))
301 assert.equal("18446744073709539271", format("%u", -12345)) 301 assert.equal("[-12345]", format("%u", -12345))
302 assert.equal("[1.5]", format("%u", 1.5)) 302 assert.equal("[1.5]", format("%u", 1.5))
303 assert.equal("[7.3786976294838e+19]", format("%u", 73786976294838206464)) 303 assert.equal("[7.3786976294838e+19]", format("%u", 73786976294838206464))
304 assert.equal("[inf]", format("%u", math.huge)) 304 assert.equal("[inf]", format("%u", math.huge))
305 assert.equal("2147483647", format("%u", 2147483647)) 305 assert.equal("2147483647", format("%u", 2147483647))
306 end); 306 end);
307 end); 307 end);
308 308
309 describe("to %x", function () 309 describe("to %x", function ()
310 it("works", function () 310 it("works", function ()
311 assert.equal("61", format("%x", 97)) 311 assert.equal("61", format("%x", 97))
312 assert.equal("ffffffffffffcfc7", format("%x", -12345)) 312 assert.equal("[-12345]", format("%x", -12345))
313 assert.equal("[1.5]", format("%x", 1.5)) 313 assert.equal("[1.5]", format("%x", 1.5))
314 assert.equal("[7.3786976294838e+19]", format("%x", 73786976294838206464)) 314 assert.equal("[7.3786976294838e+19]", format("%x", 73786976294838206464))
315 assert.equal("[inf]", format("%x", math.huge)) 315 assert.equal("[inf]", format("%x", math.huge))
316 assert.equal("7fffffff", format("%x", 2147483647)) 316 assert.equal("7fffffff", format("%x", 2147483647))
317 end); 317 end);
318 end); 318 end);
319 319
320 describe("to %X", function () 320 describe("to %X", function ()
321 it("works", function () 321 it("works", function ()
322 assert.equal("61", format("%X", 97)) 322 assert.equal("61", format("%X", 97))
323 assert.equal("FFFFFFFFFFFFCFC7", format("%X", -12345)) 323 assert.equal("[-12345]", format("%X", -12345))
324 assert.equal("[1.5]", format("%X", 1.5)) 324 assert.equal("[1.5]", format("%X", 1.5))
325 assert.equal("[7.3786976294838e+19]", format("%X", 73786976294838206464)) 325 assert.equal("[7.3786976294838e+19]", format("%X", 73786976294838206464))
326 assert.equal("[inf]", format("%X", math.huge)) 326 assert.equal("[inf]", format("%X", math.huge))
327 assert.equal("7FFFFFFF", format("%X", 2147483647)) 327 assert.equal("7FFFFFFF", format("%X", 2147483647))
328 end); 328 end);