Mercurial > pub > dyncall > dyncall
comparison test/suite_aggrs/rand-sig.lua @ 432:167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
still missing:
- unions
- arrays
- aggregates as return values
author | Tassilo Philipp |
---|---|
date | Fri, 21 Jan 2022 15:42:29 +0100 |
parents | |
children | 3d2c5d156d78 |
comparison
equal
deleted
inserted
replaced
431:1cb8a65ea27f | 432:167faab0c0be |
---|---|
1 require"config" | |
2 | |
3 -- assure aggr chars are present in pairs (can be weighted, though), to avoid | |
4 -- inf loops | |
5 if string.match(types,'{') and not string.match(types,'}') then types = types..'}' end | |
6 | |
7 rtypes = "v"..types | |
8 | |
9 | |
10 function mkstruct(n_nest) | |
11 local s = "{" | |
12 | |
13 repeat | |
14 local id = math.random(#types) | |
15 local t = types:sub(id,id) | |
16 s = s..mktype(t, n_nest) | |
17 until t == '}' | |
18 | |
19 return s | |
20 end | |
21 | |
22 function mktype(t, n_nest) | |
23 -- ignore new structs if above depth limit | |
24 if t == '{' then | |
25 if n_nest < maxaggrdepth then | |
26 return mkstruct(n_nest + 1) | |
27 else | |
28 return '' | |
29 end | |
30 end | |
31 | |
32 -- if '}', without any open, use empty struct | |
33 if n_nest == 0 and t == '}' then | |
34 return "{}" | |
35 end | |
36 | |
37 return t | |
38 end | |
39 | |
40 | |
41 math.randomseed(seed) | |
42 local id | |
43 for i = 1, ncases do | |
44 id = math.random(#rtypes) | |
45 local nargs = math.random(minargs,maxargs) | |
46 local sig = { mktype(rtypes:sub(id,id), 0) } | |
47 for j = 1, nargs do | |
48 id = math.random(#types) | |
49 sig[#sig+1] = mktype(types:sub(id,id), 0) | |
50 end | |
51 io.write(table.concat(sig)) | |
52 io.write("\n") | |
53 end | |
54 |