aboutsummaryrefslogtreecommitdiffstats
path: root/spec/util_datetime_spec.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2022-10-08 23:55:22 +0100
committerMatthew Wild <mwild1@gmail.com>2022-10-08 23:55:22 +0100
commitf8f90ea923315383477b936e1ec109ec30eb2dd3 (patch)
tree21f4182bd16033df0dd0696e97d319e94a63bb81 /spec/util_datetime_spec.lua
parentc6c5fec97e139ba432252d1b9370b75ad8e34c49 (diff)
downloadprosody-f8f90ea923315383477b936e1ec109ec30eb2dd3.tar.gz
prosody-f8f90ea923315383477b936e1ec109ec30eb2dd3.zip
util.datetime: Add some missing test cases
You guessed it, mutation testing.
Diffstat (limited to 'spec/util_datetime_spec.lua')
-rw-r--r--spec/util_datetime_spec.lua15
1 files changed, 15 insertions, 0 deletions
diff --git a/spec/util_datetime_spec.lua b/spec/util_datetime_spec.lua
index a35a1037..960e8aef 100644
--- a/spec/util_datetime_spec.lua
+++ b/spec/util_datetime_spec.lua
@@ -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);