summaryrefslogtreecommitdiff
path: root/Data/Libraries/Penlight/spec/pretty_spec.lua
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-10-30 11:32:16 +0800
committerchai <chaifix@163.com>2021-10-30 11:32:16 +0800
commit42ec7286b2d36a9ba22925f816a17cb1cc2aa5ce (patch)
tree24bc7009457a8d7500f264e89946dc20d069294f /Data/Libraries/Penlight/spec/pretty_spec.lua
parent164885fd98d48703bd771f802d79557b7db97431 (diff)
+ Penlight
Diffstat (limited to 'Data/Libraries/Penlight/spec/pretty_spec.lua')
-rw-r--r--Data/Libraries/Penlight/spec/pretty_spec.lua40
1 files changed, 40 insertions, 0 deletions
diff --git a/Data/Libraries/Penlight/spec/pretty_spec.lua b/Data/Libraries/Penlight/spec/pretty_spec.lua
new file mode 100644
index 0000000..85e3770
--- /dev/null
+++ b/Data/Libraries/Penlight/spec/pretty_spec.lua
@@ -0,0 +1,40 @@
+local pretty = require("pl.pretty")
+
+describe("pl.pretty.number", function ()
+
+ it("should format memory", function ()
+ local function assert_memory (expected, input)
+ assert.is.equal(expected, pretty.number(input, "M"))
+ end
+ assert_memory("123B", 123)
+ assert_memory("1.2KiB", 1234)
+ assert_memory("10.0KiB", 10*1024)
+ assert_memory("1.0MiB", 1024*1024)
+ assert_memory("1.0GiB", 1024*1024*1024)
+ end)
+
+ it("should format postfixes", function ()
+ local function assert_postfix(expected, input)
+ assert.is.equal(expected, pretty.number(input, "N", 2))
+ end
+ assert_postfix("123", 123)
+ assert_postfix("1.23K", 1234)
+ assert_postfix("10.24K", 10*1024)
+ assert_postfix("1.05M", 1024*1024)
+ assert_postfix("1.07B", 1024*1024*1024)
+ end)
+
+ it("should format postfixes", function ()
+ local function assert_separator(expected, input)
+ assert.is.equal(expected, pretty.number(input, "T"))
+ end
+ assert_separator('123', 123)
+ assert_separator('1,234', 1234)
+ assert_separator('12,345', 12345)
+ assert_separator('123,456', 123456)
+ assert_separator('1,234,567', 1234567)
+ assert_separator('12,345,678', 12345678)
+ end)
+
+
+end)