From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 886A26EC55; Fri, 30 Jul 2021 23:45:15 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 886A26EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1627677915; bh=fK2KrCd26uk4cSE2umQLo610NgzMhy0KSqz9kONtftA=; h=To:Cc:References:In-Reply-To:Date:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=pZqMeM7Te7qVJRK29Zt2FKfUkKeuEvvvicsghOopeNNP9V2ush8PF7b3tXPfpz3YZ 0bsQODfEWeeai+4z2PIpQb0iRJTiXLs00TrHhBzZSaeMTjxEwbK5a92E+GH20SSxRj xnYFmjK66LFHBZbbGbLV1ycfNc1oBHYot8hxPY1I= Received: from smtp49.i.mail.ru (smtp49.i.mail.ru [94.100.177.109]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id A97456EC55 for ; Fri, 30 Jul 2021 23:45:14 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A97456EC55 Received: by smtp49.i.mail.ru with esmtpa (envelope-from ) id 1m9ZNZ-0004qA-FL; Fri, 30 Jul 2021 23:45:14 +0300 To: "'Oleg Babin'" , Cc: References: <76ae95a7c49c1c981a726b59f24a2f524b256880.1627468002.git.tsafin@tarantool.org> <89450197-1b62-9bd6-0b61-8ae99b3538ff@tarantool.org> In-Reply-To: <89450197-1b62-9bd6-0b61-8ae99b3538ff@tarantool.org> Date: Fri, 30 Jul 2021 23:45:13 +0300 Message-ID: <043501d78583$cbc22fb0$63468f10$@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQNJI0ot4YBfKbZyj2tYNprdOv6c+gHitw9ZAjf9ubuoVwUWYA== Content-Language: ru X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD941C43E597735A9C3104FC76DFAAAAF7DA068FE323FAC4379182A05F538085040C797DE41802C309DB6CF6553071B1E6CE903E217701FE9F25F5296347D33363F X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE754E958D11587BC68EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637A6A20D80F0832BC78638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8F2C8611E4035BB34DC26F1355B9B210B117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BAA867293B0326636D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE91ADC097FE2C3A08B78CF848AE20165DD8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE37527C25B2C93CE762D242C3BD2E3F4C6C4224003CC836476EA7A3FFF5B025636E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F7900637B8F435DEDE9E76EBEFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458F0AFF96BAACF4158235E5A14AD4A4A4625E192CAD1D9E79DB53CE8437368708918740B73A442B77C X-C1DE0DAB: 0D63561A33F958A57ED67C5BFF63EA69872FD46A112DC614AF7C5C791EE64C90D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA751B940EDA0DFB0535410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D342B1F2AD168155B06E768A9053597F8EB8160D25CAF0BF5867304CBF00414DB1B8682FB375316339F1D7E09C32AA3244C36C3F00655D73A42AB7E671D171EE77324AF4FAF06DA24FDFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojWBddABnKmoJqeT69V1yTvQ== X-Mailru-Sender: B5B6A6EBBD94DAD8DF9DB9650A8885C818494578DD5ACEE327101DD6FFA1A8FFA197D3E7E84645491EC9E4A2C82A33BC8C24925A86E657CE0C70AEE3C9A96FBAB3D7EE8ED63280BE112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH resend v2 03/11] lua, datetime: datetime tests X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Timur Safin via Tarantool-patches Reply-To: Timur Safin Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hello Oleg, : From: Oleg Babin : Subject: Re: [Tarantool-patches] [PATCH resend v2 03/11] lua, = datetime: : datetime tests :=20 : Thanks for your patch. To be honest I don't understand the structure = of : this changes. :=20 : I expect that "datetime tests" will contain only tests. All unrelated = to : tests changes :=20 : should be squashed to the previous patch. Yup, sudden artefact of late minute squashes. Will copy to prior commit. :=20 :=20 : I put several comments below. :=20 :=20 : On 28.07.2021 13:34, Timur Safin via Tarantool-patches wrote: : > * created app-tap test for new builtin module `datetime.lua` : > * added case to check datetime string formatting using: : > - asctime (gmt time); : > - ctime (local TZ time); : > - strftime (using given format). : > : > * added positive/negative checks to datetime test : > - extended api of datetime.parse_date, .parse_time, = .parse_time_zone : > with a length of parsed (sub)string; : > - this allows us to check partially valid strings like "20121224 = Foo : bar". : > : > Part of #5941 : > --- : > src/lua/datetime.lua | 14 ++- : > test/app-tap/datetime.test.lua | 191 = +++++++++++++++++++++++++++++++++ : > 2 files changed, 197 insertions(+), 8 deletions(-) : > create mode 100755 test/app-tap/datetime.test.lua : > : > diff --git a/src/lua/datetime.lua b/src/lua/datetime.lua : > index 0996ca5a2..f4d2d7737 100644 : > --- a/src/lua/datetime.lua : > +++ b/src/lua/datetime.lua : > @@ -318,7 +318,7 @@ local function datetime_new(o) : > end, : > : > month =3D function(v) : > - assert(v > 0 and v < 12 ) : > + assert(v > 0 and v < 13 ) : > M =3D v : > ymd =3D true : > end, : > @@ -393,9 +393,8 @@ end : > : > local function parse_date(str) : > local dt =3D ffi.new('dt_t[1]') : > - local rc =3D cdt.dt_parse_iso_date(str, #str, dt) : > - assert(rc > 0) : > - return mk_timestamp(dt[0]) : > + local len =3D cdt.dt_parse_iso_date(str, #str, dt) : > + return len > 0 and mk_timestamp(dt[0]) or nil, tonumber(len) : > end : > : > --[[ : > @@ -411,9 +410,8 @@ end : > local function parse_time(str) : > local sp =3D ffi.new('int[1]') : > local fp =3D ffi.new('int[1]') : > - local rc =3D cdt.dt_parse_iso_time(str, #str, sp, fp) : > - assert(rc > 0) : > - return mk_timestamp(nil, sp[0], fp[0]) : > + local len =3D cdt.dt_parse_iso_time(str, #str, sp, fp) : > + return len > 0 and mk_timestamp(nil, sp[0], fp[0]) or nil, : tonumber(len) : > end : > : > --[[ : > @@ -448,7 +446,7 @@ local function parse_str(str) : > str =3D str:sub(tonumber(n) + 1) : > : > local ch =3D str:sub(1,1) : > - if ch ~=3D 't' and ch ~=3D 'T' and ch ~=3D ' ' then : > + if ch:match('[Tt ]') =3D=3D nil then : > return mk_timestamp(dt_) : > end : > : > diff --git a/test/app-tap/datetime.test.lua b/test/app- : tap/datetime.test.lua : > new file mode 100755 : > index 000000000..09c968858 : > --- /dev/null : > +++ b/test/app-tap/datetime.test.lua : > @@ -0,0 +1,191 @@ : > +#!/usr/bin/env tarantool : > + : > +local tap =3D require('tap') : > +local test =3D tap.test("errno") : > +local date =3D require('datetime') : > + : > +test:plan(5) : > + : > +test:test("Simple tests for parser", function(test) : > + test:plan(2) : > + test:ok(date("1970-01-01T01:00:00Z") =3D=3D : > + date {year=3D1970, month=3D1, day=3D1, hour=3D1, = minute=3D0, second=3D0}) : > + test:ok(date("1970-01-01T02:00:00+02:00") =3D=3D : > + date {year=3D1970, month=3D1, day=3D1, hour=3D2, = minute=3D0, second=3D0, : tz=3D120}) : > +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 =3D : > + { : > + { '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 }, :=20 : Why is it commented? It used to be failing to pass range checks, but now there is no reason = (IIRC) need to restore this case. Thanks! :=20 : > + } : > + for _, value in ipairs(tests) do : > + local str, epoch, nsec, offset : > + str, epoch, nsec, offset =3D unpack(value) : > + local dt =3D date(str) : > + test:ok(dt.secs =3D=3D epoch, ('%s: dt.secs =3D=3D = %d'):format(str, : epoch)) : > + test:ok(dt.nsec =3D=3D nsec, ('%s: dt.nsec =3D=3D = %d'):format(str, nsec)) : > + test:ok(dt.offset =3D=3D offset, ('%s: dt.offset =3D=3D = %d'):format(str, : offset)) : > + end : > +end) : > + : > +local ffi =3D require('ffi') : > + : > +ffi.cdef [[ : > + void tzset(void); : > +]] : > + :=20 :=20 : It's probably better to require all modules at the top of the file. Will do :=20 : > +test:test("Datetime string formatting", function(test) : > + test:plan(7) : > + local str =3D "1970-01-01" : > + local t =3D date(str) : > + test:ok(t.secs =3D=3D 0, ('%s: t.secs =3D=3D %d'):format(str, : tonumber(t.secs))) : > + test:ok(t.nsec =3D=3D 0, ('%s: t.nsec =3D=3D %d'):format(str, = t.nsec)) : > + test:ok(t.offset =3D=3D 0, ('%s: t.offset =3D=3D = %d'):format(str, t.offset)) : > + test:ok(date.asctime(t) =3D=3D 'Thu Jan 1 00:00:00 1970\n', = ('%s: : asctime'):format(str)) : > + -- ctime() is local timezone dependent. To make sure that : > + -- test is deterministic we enforce timezone via TZ environment : > + -- manipulations and calling tzset() : > + : > + -- redefine timezone to be always GMT-2 : > + os.setenv('TZ', 'GMT-2') : > + ffi.C.tzset() : > + test:ok(date.ctime(t) =3D=3D 'Thu Jan 1 02:00:00 1970\n', = ('%s: ctime : with timezone'):format(str)) : > + test:ok(date.strftime('%d/%m/%Y', t) =3D=3D '01/01/1970', ('%s: = strftime : #1'):format(str)) : > + test:ok(date.strftime('%A %d. %B %Y', t) =3D=3D 'Thursday 01. = January : 1970', ('%s: strftime #2'):format(str)) : > +end) : > + : > +test:test("Parse iso date - valid strings", function(test) : > + test:plan(32) : > + local good =3D { : > + {2012, 12, 24, "20121224", 8 }, : > + {2012, 12, 24, "20121224 Foo bar", 8 }, : > + {2012, 12, 24, "2012-12-24", 10 }, : > + {2012, 12, 24, "2012-12-24 23:59:59", 10 }, : > + {2012, 12, 24, "2012-12-24T00:00:00+00:00", 10 }, : > + {2012, 12, 24, "2012359", 7 }, : > + {2012, 12, 24, "2012359T235959+0130", 7 }, : > + {2012, 12, 24, "2012-359", 8 }, : > + {2012, 12, 24, "2012W521", 8 }, : > + {2012, 12, 24, "2012-W52-1", 10 }, : > + {2012, 12, 24, "2012Q485", 8 }, : > + {2012, 12, 24, "2012-Q4-85", 10 }, : > + { 1, 1, 1, "0001-Q1-01", 10 }, : > + { 1, 1, 1, "0001-W01-1", 10 }, : > + { 1, 1, 1, "0001-01-01", 10 }, : > + { 1, 1, 1, "0001-001", 8 }, : > + } : > + : > + for _, value in ipairs(good) do : > + local year, month, day, str, date_part_len; :=20 : I didn't see before that somebody uses semicolon after variables = definition. Centures of programming in C/C++ give to know :) :=20 : It's about code-style. It is clear that this is syntactically correct. :=20 : > + year, month, day, str, date_part_len =3D unpack(value) : > + local expected_date =3D date{year =3D year, month =3D = month, day =3D day} : > + local date_part, len : > + date_part, len =3D date.parse_date(str) : > + test:ok(len =3D=3D date_part_len, ('%s: length check = %d'):format(str, : len)) : > + test:ok(expected_date =3D=3D date_part, ('%s: expected : date'):format(str)) : > + end : > +end) : > + : > +test:test("Parse iso date - invalid strings", function(test) : > + test:plan(62) : > + local bad =3D { : > + "20121232" , -- Invalid day of month : > + "2012-12-310", -- Invalid day of month : > + "2012-13-24" , -- Invalid month : > + "2012367" , -- Invalid day of year : > + "2012-000" , -- Invalid day of year : > + "2012W533" , -- Invalid week of year : > + "2012-W52-8" , -- Invalid day of week : > + "2012Q495" , -- Invalid day of quarter : > + "2012-Q5-85" , -- Invalid quarter : > + "20123670" , -- Trailing digit : > + "201212320" , -- Trailing digit : > + "2012-12" , -- Reduced accuracy : > + "2012-Q4" , -- Reduced accuracy : > + "2012-Q42" , -- Invalid : > + "2012-Q1-1" , -- Invalid day of quarter : > + "2012Q--420" , -- Invalid : > + "2012-Q-420" , -- Invalid : > + "2012Q11" , -- Incomplete : > + "2012Q1234" , -- Trailing digit : > + "2012W12" , -- Incomplete : > + "2012W1234" , -- Trailing digit : > + "2012W-123" , -- Invalid : > + "2012-W12" , -- Incomplete : > + "2012-W12-12", -- Trailing digit : > + "2012U1234" , -- Invalid : > + "2012-1234" , -- Invalid : > + "2012-X1234" , -- Invalid : > + "0000-Q1-01" , -- Year less than 0001 : > + "0000-W01-1" , -- Year less than 0001 : > + "0000-01-01" , -- Year less than 0001 : > + "0000-001" , -- Year less than 0001 : > + } : > + : > + for _, str in ipairs(bad) do : > + local date_part, len : > + date_part, len =3D date.parse_date(str) : > + test:ok(len =3D=3D 0, ('%s: length check %d'):format(str, = len)) : > + test:ok(date_part =3D=3D nil, ('%s: empty date check = %s'):format(str, : date_part)) : > + end : > +end) : > + : > +os.exit(test:check() and 0 or 1) Thanks, Timur