summaryrefslogtreecommitdiff
path: root/test/tree2.c
diff options
context:
space:
mode:
authorAndrew Sidwell <andy@entai.co.uk>2008-07-11 09:16:39 +0000
committerAndrew Sidwell <andy@entai.co.uk>2008-07-11 09:16:39 +0000
commit3e092b5e709c0d6d882c78a310339bb78333dba7 (patch)
tree8aca243cfb48eba843010e2b708d96c36c375984 /test/tree2.c
parentbcc6a34137bd032497531026d1f97a01a52f22c7 (diff)
downloadlibhubbub-3e092b5e709c0d6d882c78a310339bb78333dba7.tar.gz
libhubbub-3e092b5e709c0d6d882c78a310339bb78333dba7.tar.bz2
Get the test harness concatenating adjacent text nodes.
svn path=/trunk/hubbub/; revision=4582
Diffstat (limited to 'test/tree2.c')
-rw-r--r--test/tree2.c56
1 files changed, 43 insertions, 13 deletions
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;
}