comparison test/suite_aggrs/rand-sig.lua @ 462:653b65580cb4

suite_aggr: - added arrays (inside of structs/unions, only, as only way to pass/return them by value) - cleanups and pregen of source
author Tassilo Philipp
date Tue, 01 Feb 2022 21:44:18 +0100
parents 236015fdf7a8
children bd8f5da2c74b
comparison
equal deleted inserted replaced
461:236015fdf7a8 462:653b65580cb4
3 -- assure aggr chars are present in pairs (can be weighted, though), to avoid 3 -- assure aggr chars are present in pairs (can be weighted, though), to avoid
4 -- inf loops; closing chars are allowe to appear alone, as they are ignored 4 -- inf loops; closing chars are allowe to appear alone, as they are ignored
5 -- without any opening char (does not make a lot of sense, though) 5 -- without any opening char (does not make a lot of sense, though)
6 pairs_op = { '{', '<' } --, '[' } 6 pairs_op = { '{', '<' } --, '[' }
7 pairs_cl = { '}', '>' } --, ']' } 7 pairs_cl = { '}', '>' } --, ']' }
8
9 aggr_op_pattern = '[%'..table.concat(pairs_op,'%')..']'
8 10
9 for i = 1, #pairs_op do 11 for i = 1, #pairs_op do
10 if string.find(types, '%'..pairs_op[i]) and not string.find(types, '%'..pairs_cl[i]) then 12 if string.find(types, '%'..pairs_op[i]) and not string.find(types, '%'..pairs_cl[i]) then
11 types = types..pairs_cl[i] 13 types = types..pairs_cl[i]
12 end 14 end
19 21
20 repeat 22 repeat
21 local id = math.random(#types) 23 local id = math.random(#types)
22 local t = types:sub(id,id) 24 local t = types:sub(id,id)
23 s = s..mktype(t, n_nest, maxdepth, o) 25 s = s..mktype(t, n_nest, maxdepth, o)
26
27 -- member (which cannot be first char) as array? Disallow multidimensional arrays
28 if #s > 1 and t ~= c and s:sub(-1) ~= ']' and math.random(arraydice) == 1 then
29 s = s..'['..math.random(maxarraylen)..']'
30 end
24 until t == c 31 until t == c
25 32
26 return s 33 return s
27 end 34 end
28 35
71 end 78 end
72 79
73 math.randomseed(seed) 80 math.randomseed(seed)
74 local id 81 local id
75 local uniq_sigs = { } 82 local uniq_sigs = { }
76 local aggr_op_pattern = '[%'..table.concat(pairs_op,'%')..']'
77 for i = 1, ncases do 83 for i = 1, ncases do
78 local l = '' 84 local l = ''
79 repeat 85 repeat
80 local nargs = math.random(minargs,maxargs) 86 local nargs = math.random(minargs,maxargs)
81 id = math.random(#rtypes) 87 id = math.random(#rtypes)