Skip to content

Commit

Permalink
Add test-pretty tests for number formatting
Browse files Browse the repository at this point in the history
Also remove pretty.number tests from there,
a copy exists in test-pretty-number already.
  • Loading branch information
mpeterv committed Jul 22, 2016
1 parent 9e609a9 commit 25314ba
Showing 1 changed file with 6 additions and 30 deletions.
36 changes: 6 additions & 30 deletions tests/test-pretty.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,35 +84,11 @@ t2 = {}
t1[1],t1[2] = t2,t2
asserteq( pretty.write(t1,""), [[{{},{}}]] )

function testm(x,s)
asserteq(pretty.number(x,'M'),s)
end

testm(123,'123B')
testm(1234,'1.2KiB')
testm(10*1024,'10.0KiB')
testm(1024*1024,'1.0MiB')

function testn(x,s)
asserteq(pretty.number(x,'N',2),s)
end
-- Check number formatting
asserteq(pretty.write({1/0, -1/0, 0/0, 1, 1/2}, ""), "{Inf,-Inf,NaN,1,0.5}")

testn(123,'123')
testn(1234,'1.23K')
testn(10*1024,'10.24K')
testn(1024*1024,'1.05M')
testn(1024*1024*1024,'1.07B')

function testc(x,s)
asserteq(pretty.number(x,'T'),s)
if _VERSION == "Lua 5.3" then
asserteq(pretty.write({1.0}, ""), "{1.0}")
else
asserteq(pretty.write({1.0}, ""), "{1}")
end

testc(123,'123')
testc(1234,'1,234')
testc(12345,'12,345')
testc(123456,'123,456')
testc(1234567,'1,234,567')
testc(12345678,'12,345,678')

asserteq(pretty.number(1e12,'N'),'1000.0B')

0 comments on commit 25314ba

Please sign in to comment.