6 #define EMAX 128 // maximum arguments
7 #define SPLIT_CALL 8 // argument count to split by newline on function calls
8 #define SPLIT_ARG 4 // argument count to split by newline in function decls
11 FILE *fp = fopen("tests/args.c", "w");
12 fprintf(fp, "// function arguments\n\n");
14 const char *types[] = {
15 "int", "short", "long",
19 table_t *table = table_create(NULL); // table for last thing
21 for (int e = 0; e < sizeof(types)/sizeof(types[0]); e++) {
22 if (types[e][0] != '$')
23 fprintf(fp, "void test_%s(", types[e]);
25 fprintf(fp, "void test_mix(");
27 for (int i = 1; i < EMAX; i++) {
28 if (types[e][0] != '$')
29 fprintf(fp, "%-6s value%-3d", types[e], i);
31 string_t *string = string_create();
32 const char *type = types[rand() % (sizeof(types)/sizeof(types[0]) - 1)];
33 fprintf(fp, "%-6s value%-3d", type, i);
34 string_catf(string, "%d", i);
35 table_insert(table, string_buffer(string), (void*)type);
39 if (i % SPLIT_ARG == 0) {
41 if (types[e][0] != '$') {
42 fprintf(fp, " "); // void test_ whitespace
43 for (int j = 0; j < strlen(types[e]); j++)
52 for (int i = 1; i < EMAX; i++) {
55 string_t *key = string_create();
56 string_catf(key, "%d", i);
57 const char *type = table_find(table, string_buffer(key));
60 if (types[e][0] == 'd')
61 fprintf(fp, " expect%c(value%d, 0.%d);\n", t, i, i);
62 else if (types[e][0] == 'f')
63 fprintf(fp, " expect%c(value%d, 0.%d);\n", t, i, i);
65 fprintf(fp, " expect%c(value%d, %d);\n", t, i, i);
70 fprintf(fp, "int main() {\n");
71 for (int i = 0; i < sizeof(types)/sizeof(types[0]) - 1; i++) {
72 fprintf(fp, " test_%s(", types[i]);
73 for (int j = 1; j < EMAX; j++) {
74 if (types[i][0] == 'f') {
75 string_t *len = string_create();
76 string_catf(len, "0.%df", j);
77 fprintf(fp, string_buffer(len), j);
78 for (int p = strlen(string_buffer(len)); p <= 5; p++)
80 } else if (types[i][0] == 'd')
81 fprintf(fp, "0.%-3d", j);
83 fprintf(fp, "%-3d", j);
88 if (j % SPLIT_CALL == 0) {
90 fprintf(fp, " "); // test_
91 for (int k = 0; k < strlen(types[i]); k++)
95 fprintf(fp, "\n );\n");
97 // mix is special since it needs to align everything
98 // at 0.ffff <-- six things
99 fprintf(fp, " test_mix(");
100 for (int j = 1; j < EMAX; j++) {
101 string_t *key = string_create();
102 string_catf(key, "%d", j);
103 const char *type = table_find(table, string_buffer(key));
105 if (type[0] == 'f') {
106 string_t *len = string_create();
107 string_catf(len, "0.%df", j);
108 fprintf(fp, string_buffer(len), j);
109 for (int p = strlen(string_buffer(len)); p <= 5; p++)
111 } else if (type[0] == 'd')
112 fprintf(fp, "0.%-4d", j);
114 fprintf(fp, "%-6d", j);
119 if (j % SPLIT_CALL == 0) {
121 fprintf(fp, " "); // test_mix
124 fprintf(fp, "\n );\n");
125 fprintf(fp, " return 0;\n}\n");