diff options
author | Caleb Maclennan <caleb@alerque.com> | 2020-10-02 00:36:29 +0300 |
---|---|---|
committer | Thijs Schreijer <thijs@thijsschreijer.nl> | 2020-10-09 13:51:40 +0300 |
commit | 9ef4b2f3f1e562051736f6758107a1fe31d67a4e (patch) | |
tree | 7460bc39727166e448ceb712c1f4cff0ecd916e5 /spec | |
parent | 943a7009244729626df7b2642fcb3c3a9444856e (diff) |
test: Port Date format tests to Busted
Diffstat (limited to 'spec')
-rw-r--r-- | spec/date_spec.lua | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/spec/date_spec.lua b/spec/date_spec.lua index 0a02744..1032de2 100644 --- a/spec/date_spec.lua +++ b/spec/date_spec.lua @@ -1,11 +1,48 @@ local Date = require("pl.Date") -describe("pl.Date:__tostring()", function () +describe("pl.Date", function () + + describe("function", function () + + describe("Format()", function () + + it("should output parsable inputs", function () + local function assert_date_format(expected, format) + local df = Date.Format(format) + local d = df:parse(expected) + assert.is.equal(expected, df:tostring(d)) + end + assert_date_format('02/04/10', 'dd/mm/yy') + assert_date_format('04/02/2010', 'mm/dd/yyyy') + assert_date_format('2011-02-20', 'yyyy-mm-dd') + assert_date_format('20070320', 'yyyymmdd') + assert_date_format('23:10', 'HH:MM') + end) + + it("should parse 'slack' fields", function () + local df = Date.Format("m/d/yy") + -- TODO: Re-enable when issue #359 fixed + -- assert.is.equal('01/05/99', df:tostring(df:parse('1/5/99'))) + assert.is.equal('01/05/01', df:tostring(df:parse('1/5/01'))) + assert.is.equal('01/05/32', df:tostring(df:parse('1/5/32'))) + end) + + end) + + end) + + describe("meta method", function () + + describe("__tostring()", function () + + it("should be suitable for serialization", function () + local df = Date.Format() + local du = df:parse("2008-07-05") + assert.is.equal(du, du:toUTC()) + end) + + end) - it("should be suitable for serialization", function () - local df = Date.Format() - local du = df:parse("2008-07-05") - assert.is.equal(du, du:toUTC()) end) end) |