Mercurial > pub > dyncall > dyncall
changeset 625:3fc677ff16e5
- lua signature generator for test code: support for generating '.' vararg sigs
author | Tassilo Philipp |
---|---|
date | Fri, 28 Oct 2022 13:53:11 +0200 |
parents | d28b09fa2ff9 |
children | 667fe7b2be62 |
files | test/common/rand-sig.lua |
diffstat | 1 files changed, 11 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/test/common/rand-sig.lua Fri Oct 28 12:22:12 2022 +0200 +++ b/test/common/rand-sig.lua Fri Oct 28 13:53:11 2022 +0200 @@ -9,6 +9,7 @@ -- optional: -- rtypes (if not set, it'll be 'v'..types) +-- ellipsis -- optional (when including aggregate generation): -- minaggrfields @@ -57,7 +58,7 @@ until t ~= c or nfields >= minaggrfields end - s_ = mktype(t, n_nest, maxdepth, o) + s_ = mktype(t, n_nest, maxdepth, o) or '' if(#s_ > 0) then nfields = nfields + 1 end @@ -87,7 +88,7 @@ if n_nest < maxdepth then return mkaggr(n_nest + 1, maxdepth, pairs_op[aggr_i], pairs_cl[aggr_i]) else - return '' + return nil end end @@ -101,7 +102,7 @@ -- if closing char, without any open, ignore if aggr_i ~= 0 and (aggr_open == nil or pairs_op[aggr_i] ~= aggr_open) then - return '' + return nil end return t @@ -117,16 +118,21 @@ local l = '' repeat local nargs = math.random(minargs,maxargs) + local varargstart = (ellipsis and nargs > 0 and math.random(0,ellipsis) == 0) and math.random(0,nargs-1) or nargs -- generate vararg sigs? local sig = { } for j = 1, nargs do id = math.random(#types) sig[#sig+1] = mktype(types:sub(id,id), 0, math.random(maxaggrdepth), nil) -- random depth avoids excessive nesting + -- start vararg part? + if j > varargstart and #sig > 0 then + sig[#sig+1] = "." + varargstart = nargs + end end - r = '' repeat id = math.random(#rtypes) r = mktype(rtypes:sub(id,id), 0, math.random(maxaggrdepth), nil) -- random depth avoids excessive nesting - until r ~= '' + until r sig[#sig+1] = ')'..r l = table.concat(sig) -- reject dupes, sigs without any aggregate (as this is about aggrs after all), and empty ones (if not wanted)