From: Timur Safin via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Subject: [Tarantool-patches] [RFC PATCH 03/13] test: datetime test Date: Thu, 15 Jul 2021 11:18:09 +0300 [thread overview] Message-ID: <5eab17762162a6ea36205586dc55a89702091e6c.1626335241.git.tsafin@tarantool.org> (raw) In-Reply-To: <cover.1626335241.git.tsafin@tarantool.org> * created app-tap test fro newly created builtin module - `datetime.lua` --- test/app-tap/datetime.test.lua | 89 ++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 test/app-tap/datetime.test.lua diff --git a/test/app-tap/datetime.test.lua b/test/app-tap/datetime.test.lua new file mode 100755 index 000000000..bc66b3296 --- /dev/null +++ b/test/app-tap/datetime.test.lua @@ -0,0 +1,89 @@ +#!/usr/bin/env tarantool + +local tap = require('tap') +local test = tap.test("errno") +local date = require('datetime') + +test:plan(2) + +test:test("Simple tests for parser", function(test) + test:plan(2) + test:ok(date("1970-01-01T01:00:00Z") == + date {year=1970, month=1, day=1, hour=1, minute=0, second=0}) + test:ok(date("1970-01-01T02:00:00+02:00") == + date {year=1970, month=1, day=1, hour=2, minute=0, second=0, tz=120}) +end) + +test:test("Multiple tests for parser (with nanoseconds)", function(test) + test:plan(165) + -- borrowed from p5-time-moments/t/180_from_string.t + local tests = + { + { '1970-01-01T00:00:00Z', 0, 0, 0 }, + { '1970-01-01T02:00:00+02:00', 0, 0, 120 }, + { '1970-01-01T01:30:00+01:30', 0, 0, 90 }, + { '1970-01-01T01:00:00+01:00', 0, 0, 60 }, + { '1970-01-01T00:01:00+00:01', 0, 0, 1 }, + { '1970-01-01T00:00:00+00:00', 0, 0, 0 }, + { '1969-12-31T23:59:00-00:01', 0, 0, -1 }, + { '1969-12-31T23:00:00-01:00', 0, 0, -60 }, + { '1969-12-31T22:30:00-01:30', 0, 0, -90 }, + { '1969-12-31T22:00:00-02:00', 0, 0, -120 }, + { '1970-01-01T00:00:00.123456789Z', 0, 123456789, 0 }, + { '1970-01-01T00:00:00.12345678Z', 0, 123456780, 0 }, + { '1970-01-01T00:00:00.1234567Z', 0, 123456700, 0 }, + { '1970-01-01T00:00:00.123456Z', 0, 123456000, 0 }, + { '1970-01-01T00:00:00.12345Z', 0, 123450000, 0 }, + { '1970-01-01T00:00:00.1234Z', 0, 123400000, 0 }, + { '1970-01-01T00:00:00.123Z', 0, 123000000, 0 }, + { '1970-01-01T00:00:00.12Z', 0, 120000000, 0 }, + { '1970-01-01T00:00:00.1Z', 0, 100000000, 0 }, + { '1970-01-01T00:00:00.01Z', 0, 10000000, 0 }, + { '1970-01-01T00:00:00.001Z', 0, 1000000, 0 }, + { '1970-01-01T00:00:00.0001Z', 0, 100000, 0 }, + { '1970-01-01T00:00:00.00001Z', 0, 10000, 0 }, + { '1970-01-01T00:00:00.000001Z', 0, 1000, 0 }, + { '1970-01-01T00:00:00.0000001Z', 0, 100, 0 }, + { '1970-01-01T00:00:00.00000001Z', 0, 10, 0 }, + { '1970-01-01T00:00:00.000000001Z', 0, 1, 0 }, + { '1970-01-01T00:00:00.000000009Z', 0, 9, 0 }, + { '1970-01-01T00:00:00.00000009Z', 0, 90, 0 }, + { '1970-01-01T00:00:00.0000009Z', 0, 900, 0 }, + { '1970-01-01T00:00:00.000009Z', 0, 9000, 0 }, + { '1970-01-01T00:00:00.00009Z', 0, 90000, 0 }, + { '1970-01-01T00:00:00.0009Z', 0, 900000, 0 }, + { '1970-01-01T00:00:00.009Z', 0, 9000000, 0 }, + { '1970-01-01T00:00:00.09Z', 0, 90000000, 0 }, + { '1970-01-01T00:00:00.9Z', 0, 900000000, 0 }, + { '1970-01-01T00:00:00.99Z', 0, 990000000, 0 }, + { '1970-01-01T00:00:00.999Z', 0, 999000000, 0 }, + { '1970-01-01T00:00:00.9999Z', 0, 999900000, 0 }, + { '1970-01-01T00:00:00.99999Z', 0, 999990000, 0 }, + { '1970-01-01T00:00:00.999999Z', 0, 999999000, 0 }, + { '1970-01-01T00:00:00.9999999Z', 0, 999999900, 0 }, + { '1970-01-01T00:00:00.99999999Z', 0, 999999990, 0 }, + { '1970-01-01T00:00:00.999999999Z', 0, 999999999, 0 }, + { '1970-01-01T00:00:00.0Z', 0, 0, 0 }, + { '1970-01-01T00:00:00.00Z', 0, 0, 0 }, + { '1970-01-01T00:00:00.000Z', 0, 0, 0 }, + { '1970-01-01T00:00:00.0000Z', 0, 0, 0 }, + { '1970-01-01T00:00:00.00000Z', 0, 0, 0 }, + { '1970-01-01T00:00:00.000000Z', 0, 0, 0 }, + { '1970-01-01T00:00:00.0000000Z', 0, 0, 0 }, + { '1970-01-01T00:00:00.00000000Z', 0, 0, 0 }, + { '1970-01-01T00:00:00.000000000Z', 0, 0, 0 }, + { '1973-11-29T21:33:09Z', 123456789, 0, 0 }, + { '2013-10-28T17:51:56Z', 1382982716, 0, 0 }, + -- { '9999-12-31T23:59:59Z', 253402300799, 0, 0 }, + } + for _, value in ipairs(tests) do + local str, epoch, nsec, offset + str, epoch, nsec, offset = unpack(value) + local dt = date(str) + test:ok(dt.secs == epoch, ('%s: dt.secs == %d'):format(str, epoch)) + test:ok(dt.nsec == nsec, ('%s: dt.nsec == %d'):format(str, nsec)) + test:ok(dt.offset == offset, ('%s: dt.offset == %d'):format(str, offset)) + end +end) + +os.exit(test:check() and 0 or 1) -- 2.29.2
next prev parent reply other threads:[~2021-07-15 8:20 UTC|newest] Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-07-15 8:18 [Tarantool-patches] [RFC PATCH 00/13] Initial datetime support Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 01/13] build: add Christian Hansen c-dt to the build Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 02/13] lua: built-in module datetime Timur Safin via Tarantool-patches 2021-07-15 8:18 ` Timur Safin via Tarantool-patches [this message] 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 04/13] test: datetime string formatting Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 05/13] box: add messagepack support for datetime Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 06/13] lua: positive/negative cases in datetime test Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 07/13] lua: asctime and strfime fixed Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 08/13] box, lua: renamed t_datetime_tz structure to datetime_t Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 09/13] lua: calculated attributes for date Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 10/13] lua: tostring formatization in datetime.lua Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 11/13] test: allow relaxed date format without tz Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 12/13] lua: initial time duration support Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 13/13] lua: complete " Timur Safin via Tarantool-patches 2021-07-15 16:56 ` [Tarantool-patches] [RFC PATCH 00/13] Initial datetime support Oleg Babin via Tarantool-patches 2021-07-15 23:03 ` Timur Safin via Tarantool-patches 2021-07-16 6:58 ` Oleg Babin via Tarantool-patches 2021-07-22 10:01 ` Igor Munkin via Tarantool-patches 2021-07-22 12:54 ` Timur Safin via Tarantool-patches
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=5eab17762162a6ea36205586dc55a89702091e6c.1626335241.git.tsafin@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=tsafin@tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [RFC PATCH 03/13] test: datetime test' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox