Software /
code /
prosody
Diff
spec/util_human_io_spec.lua @ 13054:f4d7fe919969
util.human.io: Add parse_duration() method to parse a duration string
Similar logic occurs throughout various modules in the codebase. We might even
want a module:get_option_duration()??
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 07 Apr 2023 14:14:53 +0100 |
parent | 11896:93e9f7ae2f9b |
child | 13196:eca44e058eed |
line wrap: on
line diff
--- a/spec/util_human_io_spec.lua Fri Apr 07 14:03:24 2023 +0200 +++ b/spec/util_human_io_spec.lua Fri Apr 07 14:14:53 2023 +0100 @@ -42,6 +42,24 @@ assert.equal("räksmörgås", human_io.ellipsis("räksmörgås", 10)); end); end); + + describe("parse_duration", function () + local function test(expected, duration) + assert.equal(expected, human_io.parse_duration(duration)); + end + it("works", function () + test(1, "1s"); + test(60, "1mi"); + test(60, "1min"); + test(60, "1 min"); + test(60, "1 minute"); + test(120, "2min"); + test(86400, "1d"); + test(2678400, "1m"); + test(2678400, "1month"); + test(2678400, "1 month"); + end); + end); end);