File: uuid.test.lua

package info (click to toggle)
tarantool 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 85,364 kB
  • sloc: ansic: 513,760; cpp: 69,489; sh: 25,650; python: 19,190; perl: 14,973; makefile: 4,173; yacc: 1,329; sql: 1,074; pascal: 620; ruby: 190; awk: 18; lisp: 7
file content (103 lines) | stat: -rw-r--r-- 1,741 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
-- box.uuid
uuid = require('uuid')

test_run = require('test_run').new()
test_run:cmd("push filter ".."'\\.lua.*:[0-9]+: ' to '.lua '")

--
-- RFC4122 compliance
--
uu = uuid.new()
-- new()always generates RFC4122 variant
bit.band(uu.clock_seq_hi_and_reserved, 0xc0) == 0x80
vsn = bit.rshift(uu.time_hi_and_version, 12)
-- new() generates time-based or random-based version
vsn == 1 or vsn == 4

--
-- to/from string
--
uu = uuid()
#uu:str()
string.match(uu:str(), '^[a-f0-9%-]+$') ~= nil
uu == uuid.fromstr(uu:str())
uu = uuid.fromstr('ba90d815-14e0-431d-80c0-ce587885bb78')
uu:str()
tostring(uu)
tostring(uu) == uu:str()
uu.time_low;
uu.time_mid;
uu.time_hi_and_version;
uu.clock_seq_hi_and_reserved;
uu.clock_seq_low;
uu.node[0]
uu.node[1]
uu.node[2]
uu.node[3]
uu.node[4]
uu.node[5]

-- aliases
#uuid.str()

-- invalid values
uuid.fromstr(nil)
uuid.fromstr('')
uuid.fromstr('blablabla')
uuid.fromstr(string.rep(' ', 36))
uuid.fromstr('ba90d81514e0431d80c0ce587885bb78')
uuid.fromstr('ba90d815-14e0-431d-80c0')
uuid.fromstr('ba90d815-14e0-431d-80c0-tt587885bb7')

--
-- to/from binary
--
uu = uuid()
#uu:bin()
#uu:bin('h')
#uu:bin('l')
#uu:bin('n')
#uu:bin('b')
uu:bin() == uu:bin('h')
uu:bin('n') ~= uu:bin('h')
uu:bin('b') ~= uu:bin('l')
uu == uuid.frombin(uu:bin())
uu == uuid.frombin(uu:bin('b'), 'b')
uu == uuid.frombin(uu:bin('l'), 'l')

uu = uuid.fromstr('adf9d02e-0756-11e4-b5cf-525400123456')
uu:bin('l')
uu:bin('b')

-- aliases
#uuid.bin()
#uuid.bin('l')

--
-- eq and nil
--

uu = uuid.new()
uuid.NULL
uuid.NULL:isnil()
uuid.NULL ~= uu
uu:isnil()
uu ==  uu
uu == uu
uu == nil
uu == 12345
uu == "blablabla"

--
-- invalid usage
--

uu = uuid.new()
uu.isnil()
uu.bin()
uu.str()

uu = nil
uuid = nil

test_run:cmd("clear filter")