mirror of
https://github.com/bjc/prosody.git
synced 2025-04-01 20:27:39 +03:00
util.datetime: Add some missing test cases
You guessed it, mutation testing.
This commit is contained in:
parent
c6c5fec97e
commit
f8f90ea923
1 changed files with 15 additions and 0 deletions
|
@ -38,7 +38,10 @@ describe("util.datetime", function ()
|
|||
assert.equals("22:04:05", time(1136239445));
|
||||
end);
|
||||
it("should handle precision", function ()
|
||||
assert.equal("14:46:31.158200", time(1660488391.1582))
|
||||
assert.equal("14:46:32.158200", time(1660488392.1582))
|
||||
assert.equal("14:46:33.158200", time(1660488393.1582))
|
||||
assert.equal("14:46:33.999900", time(1660488393.9999))
|
||||
end)
|
||||
end);
|
||||
describe("#datetime", function ()
|
||||
|
@ -57,7 +60,10 @@ describe("util.datetime", function ()
|
|||
assert.equals("2006-01-02T22:04:05Z", datetime(1136239445));
|
||||
end);
|
||||
it("should handle precision", function ()
|
||||
assert.equal("2022-08-14T14:46:31.158200Z", datetime(1660488391.1582))
|
||||
assert.equal("2022-08-14T14:46:32.158200Z", datetime(1660488392.1582))
|
||||
assert.equal("2022-08-14T14:46:33.158200Z", datetime(1660488393.1582))
|
||||
assert.equal("2022-08-14T14:46:33.999900Z", datetime(1660488393.9999))
|
||||
end)
|
||||
end);
|
||||
describe("#legacy", function ()
|
||||
|
@ -65,6 +71,9 @@ describe("util.datetime", function ()
|
|||
it("should exist", function ()
|
||||
assert.is_function(legacy);
|
||||
end);
|
||||
it("should not add precision", function ()
|
||||
assert.equal("20220814T14:46:31", legacy(1660488391.1582));
|
||||
end);
|
||||
end);
|
||||
describe("#parse", function ()
|
||||
local parse = util_datetime.parse;
|
||||
|
@ -76,6 +85,7 @@ describe("util.datetime", function ()
|
|||
assert.equals(1511114293, parse("2017-11-19T17:58:13Z"));
|
||||
assert.equals(1511114330, parse("2017-11-19T18:58:50+0100"));
|
||||
assert.equals(1136239445, parse("2006-01-02T15:04:05-0700"));
|
||||
assert.equals(1136239445, parse("2006-01-02T15:04:05-07"));
|
||||
end);
|
||||
it("should handle timezones", function ()
|
||||
-- https://xmpp.org/extensions/xep-0082.html#example-2 and 3
|
||||
|
@ -85,5 +95,10 @@ describe("util.datetime", function ()
|
|||
-- floating point comparison is not an exact science
|
||||
assert.truthy(math.abs(1660488392.1582 - parse("2022-08-14T14:46:32.158200Z")) < 0.001)
|
||||
end)
|
||||
it("should return nil when given invalid inputs", function ()
|
||||
assert.is_nil(parse(nil));
|
||||
assert.is_nil(parse("hello world"));
|
||||
assert.is_nil(parse("2017-11-19T18:58:50$0100"));
|
||||
end);
|
||||
end);
|
||||
end);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue