* [Tarantool-patches] [PATCH] lua: introduce function to check that passed value is uuid
@ 2020-07-16 18:20 olegrok
2020-07-27 20:19 ` Vladislav Shpilevoy
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: olegrok @ 2020-07-16 18:20 UTC (permalink / raw)
To: lvasiliev, v.shpilevoy; +Cc: tarantool-patches
From: Oleg Babin <babinoleg@mail.ru>
We've already have is_decimal function that checks allowed value
is decimal. After tarantool started to support UUID type it will
be quite often case to check that some value has UUID type as
well. This patch introduces "is_uuid" function for this purpose.
Closes #5171
@TarantoolBot document
Title: uuid.is_uuid
is_uuid function returns "true" if specified value has uuid type
and "false" otherwise.
---
Issue: https://github.com/tarantool/tarantool/issues/5171
Branch: https://github.com/tarantool/tarantool/tree/olegrok/5171-is_uuid
@Changelog:
* Introduce function to check that specified value has UUID
type (gh-5171).
src/lua/uuid.lua | 15 ++++++++++-----
test/app/uuid.result | 19 +++++++++++++++++++
test/app/uuid.test.lua | 10 ++++++++++
3 files changed, 39 insertions(+), 5 deletions(-)
diff --git a/src/lua/uuid.lua b/src/lua/uuid.lua
index 5d19a4408..42016601d 100644
--- a/src/lua/uuid.lua
+++ b/src/lua/uuid.lua
@@ -26,8 +26,12 @@ local uuid_t = ffi.typeof('struct tt_uuid')
local UUID_STR_LEN = 36
local UUID_LEN = ffi.sizeof(uuid_t)
+local is_uuid = function(value)
+ return ffi.istype(uuid_t, value)
+end
+
local uuid_tostring = function(uu)
- if not ffi.istype(uuid_t, uu) then
+ if not is_uuid(uu) then
return error('Usage: uuid:str()')
end
return ffi.string(builtin.tt_uuid_str(uu), UUID_STR_LEN)
@@ -56,7 +60,7 @@ local need_bswap = function(order)
end
local uuid_tobin = function(uu, byteorder)
- if not ffi.istype(uuid_t, uu) then
+ if not is_uuid(uu) then
return error('Usage: uuid:bin([byteorder])')
end
if need_bswap(byteorder) then
@@ -81,17 +85,17 @@ local uuid_frombin = function(bin, byteorder)
end
local uuid_isnil = function(uu)
- if not ffi.istype(uuid_t, uu) then
+ if not is_uuid(uu) then
return error('Usage: uuid:isnil()')
end
return builtin.tt_uuid_is_nil(uu)
end
local uuid_eq = function(lhs, rhs)
- if not ffi.istype(uuid_t, rhs) then
+ if not is_uuid(rhs) then
return false
end
- if not ffi.istype(uuid_t, lhs) then
+ if not is_uuid(lhs) then
return error('Usage: uuid == var')
end
return builtin.tt_uuid_is_equal(lhs, rhs)
@@ -133,6 +137,7 @@ return setmetatable({
frombin = uuid_frombin;
bin = uuid_new_bin; -- optimized shortcut for new():bin()
str = uuid_new_str; -- optimized shortcut for new():str()
+ is_uuid = is_uuid;
}, {
__call = uuid_new; -- shortcut for new()
})
diff --git a/test/app/uuid.result b/test/app/uuid.result
index 751865e5f..9fe0e7fb4 100644
--- a/test/app/uuid.result
+++ b/test/app/uuid.result
@@ -272,6 +272,25 @@ uu.str()
uu = nil
---
...
+--
+-- gh-5171: is_uuid function
+--
+uuid.is_uuid(uuid.new())
+---
+- true
+...
+uuid.is_uuid(uuid.new():str())
+---
+- false
+...
+uuid.is_uuid(1)
+---
+- false
+...
+uuid.is_uuid(require('decimal').new('123'))
+---
+- false
+...
uuid = nil
---
...
diff --git a/test/app/uuid.test.lua b/test/app/uuid.test.lua
index ac125cddc..47a96f3c6 100644
--- a/test/app/uuid.test.lua
+++ b/test/app/uuid.test.lua
@@ -98,6 +98,16 @@ uu.bin()
uu.str()
uu = nil
+
+--
+-- gh-5171: is_uuid function
+--
+
+uuid.is_uuid(uuid.new())
+uuid.is_uuid(uuid.new():str())
+uuid.is_uuid(1)
+uuid.is_uuid(require('decimal').new('123'))
+
uuid = nil
test_run:cmd("clear filter")
--
2.23.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Tarantool-patches] [PATCH] lua: introduce function to check that passed value is uuid
2020-07-16 18:20 [Tarantool-patches] [PATCH] lua: introduce function to check that passed value is uuid olegrok
@ 2020-07-27 20:19 ` Vladislav Shpilevoy
2020-07-28 8:23 ` Leonid Vasiliev
2020-07-28 14:59 ` Kirill Yukhin
2 siblings, 0 replies; 5+ messages in thread
From: Vladislav Shpilevoy @ 2020-07-27 20:19 UTC (permalink / raw)
To: olegrok, lvasiliev; +Cc: tarantool-patches
Hi! Thanks for the patch!
LGTM.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Tarantool-patches] [PATCH] lua: introduce function to check that passed value is uuid
2020-07-16 18:20 [Tarantool-patches] [PATCH] lua: introduce function to check that passed value is uuid olegrok
2020-07-27 20:19 ` Vladislav Shpilevoy
@ 2020-07-28 8:23 ` Leonid Vasiliev
2020-07-28 8:34 ` Oleg Babin
2020-07-28 14:59 ` Kirill Yukhin
2 siblings, 1 reply; 5+ messages in thread
From: Leonid Vasiliev @ 2020-07-28 8:23 UTC (permalink / raw)
To: olegrok, v.shpilevoy; +Cc: tarantool-patches
Hi! Thank you for the patch.
LGTM.
Up to you:
> We've already have is_decimal function that checks allowed value
If I'm not mistaken: "We already have".
I think the first sentence is unnecessary.
> is decimal. After tarantool started to support UUID type it will
> be quite often case to check that some value has UUID type as
> well. This patch introduces "is_uuid" function for this purpose.
>
> Closes #5171
>
> @TarantoolBot document
> Title: uuid.is_uuid
>
> is_uuid function returns "true" if specified value has uuid type
> and "false" otherwise.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Tarantool-patches] [PATCH] lua: introduce function to check that passed value is uuid
2020-07-28 8:23 ` Leonid Vasiliev
@ 2020-07-28 8:34 ` Oleg Babin
0 siblings, 0 replies; 5+ messages in thread
From: Oleg Babin @ 2020-07-28 8:34 UTC (permalink / raw)
To: Leonid Vasiliev, v.shpilevoy; +Cc: tarantool-patches
Hi! Thanks for review.
On 28/07/2020 11:23, Leonid Vasiliev wrote:
> Hi! Thank you for the patch.
> LGTM.
>
> Up to you:
>
>> We've already have is_decimal function that checks allowed value
>
> If I'm not mistaken: "We already have".
Yes, thanks. Fixed and force-pushed.
And seems patch has two LGTMs and could be merged.
CCed Kirill.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Tarantool-patches] [PATCH] lua: introduce function to check that passed value is uuid
2020-07-16 18:20 [Tarantool-patches] [PATCH] lua: introduce function to check that passed value is uuid olegrok
2020-07-27 20:19 ` Vladislav Shpilevoy
2020-07-28 8:23 ` Leonid Vasiliev
@ 2020-07-28 14:59 ` Kirill Yukhin
2 siblings, 0 replies; 5+ messages in thread
From: Kirill Yukhin @ 2020-07-28 14:59 UTC (permalink / raw)
To: olegrok; +Cc: tarantool-patches, v.shpilevoy
Hello,
On 16 июл 21:20, olegrok@tarantool.org wrote:
> From: Oleg Babin <babinoleg@mail.ru>
>
> We've already have is_decimal function that checks allowed value
> is decimal. After tarantool started to support UUID type it will
> be quite often case to check that some value has UUID type as
> well. This patch introduces "is_uuid" function for this purpose.
>
> Closes #5171
I've checked your patch into master.
--
Regards, Kirill Yukhin
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-07-28 14:59 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-16 18:20 [Tarantool-patches] [PATCH] lua: introduce function to check that passed value is uuid olegrok
2020-07-27 20:19 ` Vladislav Shpilevoy
2020-07-28 8:23 ` Leonid Vasiliev
2020-07-28 8:34 ` Oleg Babin
2020-07-28 14:59 ` Kirill Yukhin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox