Software /
code /
prosody
Comparison
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 |
comparison
equal
deleted
inserted
replaced
13053:8128c4f1b08b | 13054:f4d7fe919969 |
---|---|
40 assert.equal("räksmör…", human_io.ellipsis("räksmörgås", 8)); | 40 assert.equal("räksmör…", human_io.ellipsis("räksmörgås", 8)); |
41 assert.equal("räksmörg…", human_io.ellipsis("räksmörgås", 9)); | 41 assert.equal("räksmörg…", human_io.ellipsis("räksmörgås", 9)); |
42 assert.equal("räksmörgås", human_io.ellipsis("räksmörgås", 10)); | 42 assert.equal("räksmörgås", human_io.ellipsis("räksmörgås", 10)); |
43 end); | 43 end); |
44 end); | 44 end); |
45 | |
46 describe("parse_duration", function () | |
47 local function test(expected, duration) | |
48 assert.equal(expected, human_io.parse_duration(duration)); | |
49 end | |
50 it("works", function () | |
51 test(1, "1s"); | |
52 test(60, "1mi"); | |
53 test(60, "1min"); | |
54 test(60, "1 min"); | |
55 test(60, "1 minute"); | |
56 test(120, "2min"); | |
57 test(86400, "1d"); | |
58 test(2678400, "1m"); | |
59 test(2678400, "1month"); | |
60 test(2678400, "1 month"); | |
61 end); | |
62 end); | |
45 end); | 63 end); |
46 | 64 |
47 | 65 |
48 | 66 |