From 3e092b5e709c0d6d882c78a310339bb78333dba7 Mon Sep 17 00:00:00 2001 From: Andrew Sidwell Date: Fri, 11 Jul 2008 09:16:39 +0000 Subject: Get the test harness concatenating adjacent text nodes. svn path=/trunk/hubbub/; revision=4582 --- test/tree2.c | 56 +++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 13 deletions(-) (limited to 'test/tree2.c') diff --git a/test/tree2.c b/test/tree2.c index a56304f..8527642 100644 --- a/test/tree2.c +++ b/test/tree2.c @@ -433,6 +433,8 @@ int append_child(void *ctx, void *parent, void *child, void **result) node_print(NULL, tparent, 0); #endif + *result = child; + if (parent == (void *)1) { if (Document) { insert = Document; @@ -452,12 +454,18 @@ int append_child(void *ctx, void *parent, void *child, void **result) insert = insert->next; } - insert->next = tchild; - tchild->prev = insert; + if (tchild->type == CHARACTER && insert->type == CHARACTER) { + insert->data.content = realloc(insert->data.content, + strlen(insert->data.content) + + strlen(tchild->data.content) + 1); + strcat(insert->data.content, tchild->data.content); + *result = insert; + } else { + insert->next = tchild; + tchild->prev = insert; + } } - *result = child; - return 0; } @@ -469,18 +477,40 @@ int insert_before(void *ctx, void *parent, void *child, void *ref_child, node_t *tchild = child; node_t *tref = ref_child; - tchild->parent = parent; +#ifndef NDEBUG + printf("inserting (%x):\n", (unsigned)tchild); + node_print(NULL, tchild, 0); + printf("before:\n"); + node_print(NULL, tref, 0); + printf("under:\n"); + if (parent != (void *)1) + node_print(NULL, tparent, 0); +#endif - tchild->prev = tref->prev; - tchild->next = tref; - tref->prev = tchild; + if (tchild->type == CHARACTER && tref->prev && + tref->prev->type == CHARACTER) { + node_t *insert = tref->prev; - if (tchild->prev) - tchild->prev->next = tchild; - else - tparent->child = tchild; + insert->data.content = realloc(insert->data.content, + strlen(insert->data.content) + + strlen(tchild->data.content) + 1); + strcat(insert->data.content, tchild->data.content); - *result = child; + *result = insert; + } else { + tchild->parent = parent; + + tchild->prev = tref->prev; + tchild->next = tref; + tref->prev = tchild; + + if (tchild->prev) + tchild->prev->next = tchild; + else + tparent->child = tchild; + + *result = child; + } return 0; } -- cgit v1.2.3