5
void populate_sources(const char *filter, std::vector<std::vector<char> > &sources)
8
for (int i = 1; i < 64; ++i)
10
sprintf(filename, filter, i);
11
FILE *fp = fopen(filename, "rb");
14
fseek(fp, 0, SEEK_END);
16
fseek(fp, 0, SEEK_SET);
17
std::vector<char> buffer(size + 1);
18
fread (&buffer[0], 1, size, fp);
20
sources.push_back(buffer);
28
printf("Loaded %d json files\n", sources.size());
31
#define IDENT(n) for (int i = 0; i < n; ++i) printf(" ")
33
void print(json_value *value, int ident = 0)
36
if (value->name) printf("\"%s\" = ", value->name);
44
printf(value->type == JSON_OBJECT ? "{\n" : "[\n");
45
for (json_value *it = value->first_child; it; it = it->next_sibling)
50
printf(value->type == JSON_OBJECT ? "}\n" : "]\n");
53
printf("\"%s\"\n", value->string_value);
56
printf("%d\n", value->int_value);
59
printf("%f\n", value->float_value);
62
printf(value->int_value ? "true\n" : "false\n");
67
bool parse(char *source)
72
block_allocator allocator(1 << 10);
74
json_value *root = json_parse(source, &errorPos, &errorDesc, &errorLine, &allocator);
81
printf("Error at line %d: %s\n%s\n\n", errorLine, errorDesc, errorPos);
85
int main(int argc, char **argv)
88
printf("===FAIL===\n\n");
89
std::vector<std::vector<char> > sources;
90
populate_sources("test/fail%d.json", sources);
92
for (size_t i = 0; i < sources.size(); ++i)
94
printf("Parsing %d\n", i + 1);
95
if (parse(&sources[i][0]))
100
printf("Passed %d from %d tests\n", passed, sources.size());
104
printf("\n===PASS===\n\n");
105
populate_sources("test/pass%d.json", sources);
107
for (size_t i = 0; i < sources.size(); ++i)
109
printf("Parsing %d\n", i + 1);
110
if (parse(&sources[i][0]))
115
printf("Passed %d from %d tests\n", passed, sources.size());