on master help sign in
More tests and an off-by-one error
370ce52Neil Mitchell
gen/test.c+5−5
@@ -256,6 +256,7 @@ static inline str gap(const char* ref, const char* start, const char* end)
256#define P_Abort(x) return x
256#define P_Abort(x) return x
257#define P_Tag \
257#define P_Tag \
258 node_alloc(&d->nodes, 1); \
258 node_alloc(&d->nodes, 1); \
259+ d->nodes.used_back++; \
259 me = &d->nodes.nodes[d->nodes.size - d->nodes.used_back]; \
260 me = &d->nodes.nodes[d->nodes.size - d->nodes.used_back]; \
260 me->outer = gap(d->body, p, p);
261 me->outer = gap(d->body, p, p);
261#define P_NameStart name_start = p
262#define P_NameStart name_start = p
@@ -277,9 +278,7 @@ static inline str gap(const char* ref, const char* start, const char* end)
277#define P_TagClose printf("TagClose %s\n", p)
278#define P_TagClose printf("TagClose %s\n", p)
278#define P_TagOpenClose \
279#define P_TagOpenClose \
279 me->nodes = start_end(0, 0); \
280 me->nodes = start_end(0, 0); \
280− printf("TagOpenClose %s\n", p)
281+ me->outer.length = gap(d->body, p, p).length;
281−// d->nodes.nodes[d->nodes.used_front].outer = gap(d->body, tag_start, p); \
282−
283
282
284// Given the parsed string, return either NULL (success) or an error message (failure)
283// Given the parsed string, return either NULL (success) or an error message (failure)
285static const char* parser(const char* p, document* d)
284static const char* parser(const char* p, document* d)
@@ -343,13 +342,14 @@ document* hexml_document_parse(const char* s, int slen)
343int main()
342int main()
344{
343{
345 setbuf(stdout, NULL);
344 setbuf(stdout, NULL);
346− const char* example = "<bob />"; // "<test foo='123 xyz' bar='t'><inner /> value</test>";
345+ const char* example = "<test foo = '123 xyz' bar = 't'><inner / > value< / test>";
347− const document* d = hexml_document_parse(example, -1);
346+ document* d = hexml_document_parse(example, -1);
348 char buf[1000];
347 char buf[1000];
349 int len = hexml_node_render(d, hexml_document_node(d), buf, sizeof(buf));
348 int len = hexml_node_render(d, hexml_document_node(d), buf, sizeof(buf));
350 buf[len] = 0;
349 buf[len] = 0;
351 printf("Result = %s\n", buf);
350 printf("Result = %s\n", buf);
352 printf("Used nodes = %i, attributes = %i\n", d->nodes.used_front, d->attrs.used);
351 printf("Used nodes = %i, attributes = %i\n", d->nodes.used_front, d->attrs.used);
352+ hexml_document_free(d);
353 return 0;
353 return 0;
354}
354}
355
355