From 7fdadb741155dc84f2a7d11c9ad9fd3b99da9319 Mon Sep 17 00:00:00 2001 From: Georgy Moiseev Date: Wed, 11 Jan 2023 16:05:05 +0300 Subject: [PATCH] feature: support datetime type Support datetime type checks [1] (added in Tarantool 2.10.0). 1. https://github.com/tarantool/tarantool/issues/5941 Part of tarantool/tarantool#7726 --- CHANGELOG.md | 1 + checks.lua | 5 ++++ test.lua | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c572ac..b623030 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - "error" type supported. +- "datetime" type supported. ### Fixed diff --git a/checks.lua b/checks.lua index ee00f7c..9c45b86 100644 --- a/checks.lua +++ b/checks.lua @@ -344,4 +344,9 @@ end add_ffi_type_checker('error', 'struct error') +local has_datetime, datetime = pcall(require, 'datetime') +if has_datetime then + checkers.datetime = datetime.is_datetime +end + return checks diff --git a/test.lua b/test.lua index fc873c7..b045f91 100755 --- a/test.lua +++ b/test.lua @@ -624,6 +624,15 @@ end local has_error = (box.error ~= nil) and (box.error.new ~= nil) +function testdata.fn_datetime(arg) -- luacheck: no unused args + checks('datetime') +end + +local has_datetime, datetime = pcall(require, 'datetime') +if has_datetime then + testdata.datetime = datetime +end + local ret_cases = { -- fn_int64 { @@ -970,6 +979,64 @@ local ret_cases = { code = 'fn_error(1)', ok = false, }, + + -- fn_datetime + { + skip = not has_datetime, + code = 'fn_datetime(datetime.new())', + ok = true, + additional_data = {'datetime'}, + }, + { + skip = not has_datetime, + code = 'fn_datetime(datetime.new{year=2023, month=1,day=11})', + ok = true, + additional_data = {'datetime'}, + }, + { + skip = not has_datetime, + code = 'fn_datetime(datetime.new{nsec=1001001})', + ok = true, + additional_data = {'datetime'}, + }, + { + skip = not has_datetime, + code = 'fn_datetime(datetime.new{timestamp=1673439642})', + ok = true, + additional_data = {'datetime'}, + }, + { + skip = not has_datetime, + code = 'fn_datetime(datetime.new{tzoffset=180})', + ok = true, + additional_data = {'datetime'}, + }, + { + skip = not has_datetime, + code = 'fn_datetime(datetime.new{tz="Europe/Moscow"})', + ok = true, + additional_data = {'datetime'}, + }, + { + skip = not has_datetime, + code = 'fn_datetime()', + ok = false, + }, + { + skip = not has_datetime, + code = 'fn_datetime("1.11.2023")', + ok = false, + }, + { + skip = not has_datetime, + code = 'fn_datetime(1673439642)', + ok = false, + }, + { + skip = not has_datetime, + code = 'fn_datetime({year=2023, month=1,day=11})', + ok = false, + }, } for _, case in pairs(ret_cases) do