comparison test/common/rand-sig.lua @ 496:da5232da6270

- test code: rand-sig now spitting out dyncallish sigs (with ')' end delim and rettype at end), purely for consistency
author Tassilo Philipp
date Mon, 21 Mar 2022 18:11:38 +0100
parents 45ac093ca822
children 3fc677ff16e5
comparison
equal deleted inserted replaced
495:45ac093ca822 496:da5232da6270
61 if(#s_ > 0) then 61 if(#s_ > 0) then
62 nfields = nfields + 1 62 nfields = nfields + 1
63 end 63 end
64 s = s..s_ 64 s = s..s_
65 65
66 -- member (which cannot be first char) as array? Disallow multidimensional arrays @@@STRUCT allow multidim? 66 -- member (which cannot be first char) as array? Disallow multidimensional arrays
67 if #s > 1 and t ~= c and s:sub(-1) ~= ']' and math.random(arraydice) == 1 then 67 if #s > 1 and t ~= c and s:sub(-1) ~= ']' and math.random(arraydice) == 1 then
68 s = s..'['..math.random(maxarraylen)..']' 68 s = s..'['..math.random(maxarraylen)..']'
69 end 69 end
70 until t == c 70 until t == c
71 71
115 local uniq_sigs = { } 115 local uniq_sigs = { }
116 for i = 1, ncases do 116 for i = 1, ncases do
117 local l = '' 117 local l = ''
118 repeat 118 repeat
119 local nargs = math.random(minargs,maxargs) 119 local nargs = math.random(minargs,maxargs)
120 id = math.random(#rtypes) 120 local sig = { }
121 local sig = { mktype(rtypes:sub(id,id), 0, math.random(maxaggrdepth), nil) } -- random depth avoids excessive nesting
122 for j = 1, nargs do 121 for j = 1, nargs do
123 id = math.random(#types) 122 id = math.random(#types)
124 sig[#sig+1] = mktype(types:sub(id,id), 0, math.random(maxaggrdepth), nil) -- random depth avoids excessive nesting 123 sig[#sig+1] = mktype(types:sub(id,id), 0, math.random(maxaggrdepth), nil) -- random depth avoids excessive nesting
125 end 124 end
125 r = ''
126 repeat
127 id = math.random(#rtypes)
128 r = mktype(rtypes:sub(id,id), 0, math.random(maxaggrdepth), nil) -- random depth avoids excessive nesting
129 until r ~= ''
130 sig[#sig+1] = ')'..r
126 l = table.concat(sig) 131 l = table.concat(sig)
127 -- reject dupes, sigs without any aggregate (as this is about aggrs after all), and empty ones (if not wanted) 132 -- reject dupes, sigs without any aggregate (as this is about aggrs after all), and empty ones (if not wanted)
128 until (reqaggrinsig ~= true or string.match(l, aggr_op_pattern) ~= nil) and uniq_sigs[l] == nil 133 until (reqaggrinsig ~= true or string.match(l, aggr_op_pattern) ~= nil) and uniq_sigs[l] == nil
129 uniq_sigs[l] = 1 134 uniq_sigs[l] = 1
130 135
131 -- @@@ hack: if included from callback_suite, 'mode' is set, and has value "random"; make sig 136 io.write(l.."\n")
132 -- be in expected format
133 -- @@@ all sigs should follow that dyncally format
134 if mode ~= nil and mode == 'random' then
135 io.write(l:sub(2)..')'..l:sub(1,1).."\n")
136 else
137 io.write(l.."\n")
138 end
139 end 137 end
140 138