Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tarantool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
core
tarantool
Commits
7db0dfe0
Commit
7db0dfe0
authored
10 years ago
by
Roman Tsisyk
Browse files
Options
Downloads
Patches
Plain Diff
Fix #506: Additional parameters to tuple:unpack()
parent
b4963295
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/box/lua/tuple.lua
+23
-8
23 additions, 8 deletions
src/box/lua/tuple.lua
test/box/tuple.result
+75
-7
75 additions, 7 deletions
test/box/tuple.result
test/box/tuple.test.lua
+19
-5
19 additions, 5 deletions
test/box/tuple.test.lua
with
117 additions
and
20 deletions
src/box/lua/tuple.lua
+
23
−
8
View file @
7db0dfe0
...
...
@@ -114,23 +114,38 @@ local tuple_totable_mt = {
__serialize
=
'seq'
;
-- enables flow mode for yaml
}
local
function
tuple_totable
(
tuple
)
local
function
tuple_totable
(
tuple
,
i
,
j
)
-- use a precreated iterator for tuple_next
builtin
.
tuple_rewind
(
next_it
,
tuple
)
local
ret
=
{}
while
true
do
local
field
=
builtin
.
tuple_next
(
next_it
)
if
field
==
nil
then
break
local
field
if
i
~=
nil
then
if
i
<
1
then
error
(
'tuple.totable: invalid second argument'
)
end
field
=
builtin
.
tuple_seek
(
next_it
,
i
-
1
)
else
i
=
1
field
=
builtin
.
tuple_next
(
next_it
)
end
if
j
~=
nil
then
if
j
<=
0
then
error
(
'tuple.totable: invalid third argument'
)
end
else
j
=
4294967295
end
local
ret
=
{}
while
field
~=
nil
and
i
<=
j
do
local
val
=
msgpackffi
.
decode_unchecked
(
field
)
table.insert
(
ret
,
val
)
i
=
i
+
1
field
=
builtin
.
tuple_next
(
next_it
)
end
return
setmetatable
(
ret
,
tuple_totable_mt
)
end
local
function
tuple_unpack
(
tuple
)
return
unpack
(
tuple_totable
(
tuple
))
local
function
tuple_unpack
(
tuple
,
i
,
j
)
return
unpack
(
tuple_totable
(
tuple
,
i
,
j
))
end
local
function
tuple_find
(
tuple
,
offset
,
val
)
...
...
This diff is collapsed.
Click to expand it.
test/box/tuple.result
+
75
−
7
View file @
7db0dfe0
...
...
@@ -227,24 +227,92 @@ box.tuple.new{'x', 'y', 'z', {1, 2}, {c = 3, d = 4}, {e = 5, f = 6}}
---
- ['x', 'y', 'z', [1, 2], {'c': 3, 'd': 4}, {'e': 5, 'f': 6}]
...
--
-- A test case for #107 "box.tuple.unpack asserts on extra arguments"
--
t=box.tuple.new{'a','b','c'}
---
...
t:unpack(5)
t:totable()
---
- ['a', 'b', 'c']
...
t:unpack()
---
- a
- b
- c
...
t:unpack(1, 2, 3, 4, 5)
t:totable(1)
---
- ['a', 'b', 'c']
...
t:unpack(1)
---
- a
- b
- c
...
t:totable(2)
---
- ['b', 'c']
...
t:unpack(2)
---
- b
- c
...
t:totable(1, 3)
---
- ['a', 'b', 'c']
...
t:unpack(1, 3)
---
- a
- b
- c
...
t:totable(2, 3)
---
- ['b', 'c']
...
t:unpack(2, 3)
---
- b
- c
...
t:totable(2, 4)
---
- ['b', 'c']
...
t:unpack(2, 4)
---
- b
- c
...
t:totable(nil, 2)
---
- ['a', 'b']
...
t:unpack(nil, 2)
---
- a
- b
...
t:totable(2, 1)
---
- []
...
t:unpack(2, 1)
---
...
t:totable(0)
---
- error: '[string "-- tuple.lua (internal file)..."]:123: tuple.totable: invalid second
argument'
...
t:totable(1, 0)
---
- error: '[string "-- tuple.lua (internal file)..."]:132: tuple.totable: invalid third
argument'
...
--
-- Check that tuple:totable correctly sets serializer hints
--
...
...
@@ -735,12 +803,12 @@ t = box.tuple.new({'a', 'b', 'c', 'd', 'e'})
...
t:update()
---
- error: '[string "-- tuple.lua (internal file)..."]:1
5
7: Usage: tuple:update({ {
- error: '[string "-- tuple.lua (internal file)..."]:17
2
: Usage: tuple:update({ {
op, field, arg}+ })'
...
t:update(10)
---
- error: '[string "-- tuple.lua (internal file)..."]:1
5
7: Usage: tuple:update({ {
- error: '[string "-- tuple.lua (internal file)..."]:17
2
: Usage: tuple:update({ {
op, field, arg}+ })'
...
t:update({})
...
...
This diff is collapsed.
Click to expand it.
test/box/tuple.test.lua
+
19
−
5
View file @
7db0dfe0
...
...
@@ -66,12 +66,26 @@ box.tuple.new{{1, 2}, 'x', 'y', 'z', {c = 3, d = 4}, {e = 5, f = 6}}
box
.
tuple
.
new
(
'x'
,
'y'
,
'z'
,
{
1
,
2
},
{
c
=
3
,
d
=
4
},
{
e
=
5
,
f
=
6
})
box
.
tuple
.
new
{
'x'
,
'y'
,
'z'
,
{
1
,
2
},
{
c
=
3
,
d
=
4
},
{
e
=
5
,
f
=
6
}}
--
-- A test case for #107 "box.tuple.unpack asserts on extra arguments"
--
t
=
box
.
tuple
.
new
{
'a'
,
'b'
,
'c'
}
t
:
unpack
(
5
)
t
:
unpack
(
1
,
2
,
3
,
4
,
5
)
t
:
totable
()
t
:
unpack
()
t
:
totable
(
1
)
t
:
unpack
(
1
)
t
:
totable
(
2
)
t
:
unpack
(
2
)
t
:
totable
(
1
,
3
)
t
:
unpack
(
1
,
3
)
t
:
totable
(
2
,
3
)
t
:
unpack
(
2
,
3
)
t
:
totable
(
2
,
4
)
t
:
unpack
(
2
,
4
)
t
:
totable
(
nil
,
2
)
t
:
unpack
(
nil
,
2
)
t
:
totable
(
2
,
1
)
t
:
unpack
(
2
,
1
)
t
:
totable
(
0
)
t
:
totable
(
1
,
0
)
--
-- Check that tuple:totable correctly sets serializer hints
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment