Skip to content

Commit ad55326

Browse files
committed
test: add true/false diagnostic test for float precision and keyword boundaries
1 parent 34904fe commit ad55326

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

tests/test_truefalse.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// test_truefalse.c — diagnostic tests for float precision and keyword boundaries.
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
#include <string.h>
5+
#include "cjsonx.h"
6+
7+
void dump_doc(cjsonx_doc* doc) {
8+
printf("nodes count: %zu\n", doc->node_count);
9+
for (size_t i = 0; i < doc->node_count; i++) {
10+
cjsonx_node_t* n = &doc->nodes[i];
11+
printf("node %zu: type=%d, len=%d, next_sibling=%u, val.f64=%g, val.str=%s\n",
12+
i, cjsonx_node_type(n), cjsonx_node_length(n), n->next_sibling, n->val.f64,
13+
(cjsonx_node_type(n) == CJSONX_STRING) ? n->val.str : "null");
14+
}
15+
}
16+
17+
int main() {
18+
cjsonx_doc* doc1 = cjsonx_parse("{\"a\": 1}", 8);
19+
cjsonx_doc* doc2 = cjsonx_parse("{\"a\": 2}", 8);
20+
21+
printf("--- doc1 before merge ---\n");
22+
dump_doc(doc1);
23+
24+
cjsonx_val res = cjsonx_merge_patch(doc1->root, doc2->root);
25+
26+
printf("--- doc1 after merge ---\n");
27+
dump_doc(doc1);
28+
29+
cjsonx_val res_val = cjsonx_get(res, "a");
30+
printf("res_val: type=%d, val=%g\n", cjsonx_get_type(res_val), cjsonx_num(res_val));
31+
32+
cjsonx_doc_free(doc1);
33+
cjsonx_doc_free(doc2);
34+
return 0;
35+
}

0 commit comments

Comments
 (0)