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 square brackets in procedure resolution for Lua calls
With the addition of square brackets, procedure resolution for Lua calls is essentially parsing a JSON path ('*' placeholder forbidden) with a special colon case for object methods, which we handle separately: refactor the existing code to reuse JSON lexer. Closes tarantool#8604 @TarantoolBot document Title: JSON paths in procedure resolution for Lua calls With the addition of square brackets to procedure resolution, Lua calls now resolve any JSON path to a procedure. This is applicable to `net.box` connection objects `call` method as well as `box.schema.func.call`. Examples of JSON path function calls are provided in the test.
- Loading branch information
1 parent
0b7e5e8
commit 9b2b670
Showing
3 changed files
with
242 additions
and
47 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
180 changes: 180 additions & 0 deletions
180
...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,180 @@ | ||
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() | ||
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') | ||
|
||
rawset(_G, '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, | ||
[333] = netbox.self, | ||
f = function() return 'f' end, | ||
g = netbox.self | ||
}) | ||
|
||
t.assert_equals(netbox.self:call('a.b.c'), a.b.c()) | ||
t.assert_equals(netbox.self:call('a.b["c"]'), a.b["c"]()) | ||
t.assert_equals(netbox.self:call('a.b[\'c\']'), a.b['c']()) | ||
t.assert_equals(netbox.self:call('a.b[555]'), a.b[555]()) | ||
t.assert_equals(netbox.self:call('a[777].d[444]'), a[777].d[444]()) | ||
t.assert_equals(netbox.self:call('a[777].d.e'), a[777].d.e()) | ||
t.assert_equals(netbox.self:call('a[777][666]'), a[777][666]()) | ||
t.assert_equals(netbox.self:call('a[555]'), a[555]()) | ||
t.assert_equals(netbox.self:call('a[333]:ping'), a[333]:ping()) | ||
t.assert_equals(netbox.self:call('a.f'), a.f()) | ||
t.assert_equals(netbox.self:call('a.g:ping'), a.g:ping()) | ||
|
||
t.assert_error(function() | ||
netbox.self:call('') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('.') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call(':') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('[') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call(']') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('[]') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a.') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a.b.') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a[b]') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a[[]') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a[[777]') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a["b]') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a["b\']') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a[\'b]') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a[\'b"]') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a[\'\']') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a[""]') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a[\'\']') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a["b""]') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a["b"\']') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a[\'b"\']') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a["b\'"]') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a[333]:') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a[333]:ping:') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a:[333]:ping:') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a:[333]:') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a[555].') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a[555].') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a[777].[666]') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a[777]d[444]') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a[777].d.[444]') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a[777][666]e') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a[555') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a[555]..') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a[555]..') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a[777]..[666]') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a[777].][666]') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a]555[') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a]555]') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a]]') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a[[555]') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a[[555]]') | ||
end) | ||
t.assert_error(function() | ||
netbox.self:call('a.b[c]') | ||
end) | ||
end) | ||
end |