forked from tarantool/tarantool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
box: support brackets in name resolution for Lua calls
Fefactor lua name resolution, simplify and comment. Add an ability to specify path with brackets, for example in 'box.space[512]:get' or 'box.space["test"]:get'. Only literals (strings and numbers) are supported. Closes tarantool#8604 @TarantoolBot document Title: square brackets in procedure resolution for Lua calls Square brackets are now supported in Lua call procedure resolution. This is applicable to `net.box` connection objects `call` method as well as `box.schema.func.call`. Examples of function calls with square brackets can be found in the test to this patch.
- Loading branch information
Showing
3 changed files
with
182 additions
and
55 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
...leased/gh-8604-support-square-brackets-in-procedure-resolution-for-lua-calls.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
## feature/box | ||
|
||
* Added support for square brackets in procedure resolution for Lua calls | ||
(gh-8604). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
...ox-luatest/gh_8604_support_square_brackets_in_procedure_resolution_for_lua_calls_test.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
local server = require('luatest.server') | ||
local t = require('luatest') | ||
|
||
local g = t.group() | ||
g.before_all(function(cg) | ||
cg.server = server:new() | ||
cg.server:start() | ||
cg.server:exec(function() | ||
local netbox = require('net.box') | ||
|
||
local a = { | ||
b = { | ||
c = function() return 'c' end, | ||
[555] = function() return 555 end | ||
}, | ||
[777] = { | ||
d = { | ||
[444] = function() return 444 end, | ||
e = function() return 'e' end | ||
}, | ||
[666] = function() return 666 end | ||
}, | ||
[555] = function() return 555 end, | ||
[-1] = function() return -1 end, | ||
[333] = netbox.self, | ||
f = function() return 'f' end, | ||
g = netbox.self | ||
} | ||
rawset(_G, 'a', a) | ||
end) | ||
end) | ||
|
||
g.after_all(function(cg) | ||
cg.server:drop() | ||
end) | ||
|
||
-- Checks that procedure resolution for Lua calls works correctly. | ||
g.test_procedure_resolution = function(cg) | ||
cg.server:exec(function() | ||
local netbox = require('net.box') | ||
local function test(proc) | ||
t.assert_equals(netbox.self:call(proc), | ||
netbox.self:eval('return ' .. proc .. '()')) | ||
end | ||
|
||
test('a.b.c') | ||
test('a.b.c') | ||
test('a.b["c"]') | ||
test('a.b[\'c\']') | ||
test('a.b[555]') | ||
test('a[777].d[444]') | ||
test('a[777].d.e') | ||
test('a[777][666]') | ||
test('a[555]') | ||
test('a[555.]') | ||
test('a[-1]') | ||
test('a[333]:ping') | ||
test('a.f') | ||
test('a.g:ping') | ||
end) | ||
end | ||
|
||
-- Checks that error detection in procedure resolution for Lua calls works | ||
-- correctly. | ||
g.test_procedure_resolution_errors = function(cg) | ||
cg.server:exec(function() | ||
local netbox = require('net.box') | ||
local function test(proc) | ||
t.assert_error(function() netbox.self:call(proc) end) | ||
end | ||
|
||
test('') | ||
test('.') | ||
test(':') | ||
test('[') | ||
test(']') | ||
test('[]') | ||
test('a.') | ||
test('l:') | ||
test('a.b.') | ||
test('a[b]') | ||
test('a[[]') | ||
test('a[[777]') | ||
test('a["b]') | ||
test('a["b\']') | ||
test('a[\'b]') | ||
test('a[\'b"]') | ||
test('a[\'\']') | ||
test('a[""]') | ||
test('a[\'\']') | ||
test('a["b""]') | ||
test('a["b"\']') | ||
test('a[\'b"\']') | ||
test('a["b\'"]') | ||
test('a[333]:') | ||
test('a[333]:ping:') | ||
test('a:[333]:ping:') | ||
test('a:[333]:') | ||
test('a[555].') | ||
test('a[555].') | ||
test('a[777].[666]') | ||
test('a[777]d[444]') | ||
test('a[777].d.[444]') | ||
test('a[777][666]e') | ||
test('a[555') | ||
test('a[555]..') | ||
test('a[555]..') | ||
test('a[777]..[666]') | ||
test('a[777].][666]') | ||
test('a]555[') | ||
test('a]555]') | ||
test('a]]') | ||
test('a[[555]') | ||
test('a[[555]]') | ||
test('a.b[c]') | ||
end) | ||
end |