diff options
Diffstat (limited to 'src/xml/xml.test.c')
-rw-r--r-- | src/xml/xml.test.c | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/xml/xml.test.c b/src/xml/xml.test.c index 58784be..78a806c 100644 --- a/src/xml/xml.test.c +++ b/src/xml/xml.test.c @@ -106,5 +106,98 @@ LILY_TEST("count xml tag children") #include LILY_PUSH_TEST() +LILY_TEST("find first child with specified type") +{ + struct kai_tag_t *t, *child; + + t = kai_parse_string("<no_children />"); + child = kai_tag_get_first_child_with_type(t, "xxx"); + CHECK_EQ(child, NULL, "%p"); + kai_tag_destroy(t); + + t = kai_parse_string( + "<tag>" + " <xxx />" + "</tag>" + ); + child = kai_tag_get_first_child_with_type(t, "xxx"); + REQUIRE_NEQ(child, NULL, "%p"); + CHECK_EQS(child->type, "xxx"); + kai_tag_destroy(t); + child = NULL; + + t = kai_parse_string( + "<tag>" + " <qqq />" + " <xxx />" + " <yyy />" + "</tag>" + ); + child = kai_tag_get_first_child_with_type(t, "xxx"); + REQUIRE_NEQ(child, NULL, "%p"); + CHECK_EQS(child->type, "xxx"); + kai_tag_destroy(t); + child = NULL; + + t = kai_parse_string( + "<tag>" + " <qqq />" + " <yyy />" + "</tag>" + ); + child = kai_tag_get_first_child_with_type(t, "xxx"); + CHECK_EQ(child, NULL, "%p"); + kai_tag_destroy(t); +} +#include LILY_PUSH_TEST() + + +LILY_TEST("find next sibling with specified type") +{ + struct kai_tag_t *t, *child; + + t = kai_parse_string( + "<tag>" + " <qqq />" + " <xxx />" + "</tag>" + ); + child = t->children; + child = kai_tag_get_next_sibling_with_type(child, "xxx"); + REQUIRE_NEQ(child, NULL, "%p"); + CHECK_EQS(child->type, "xxx"); + kai_tag_destroy(t); + child = NULL; + + t = kai_parse_string( + "<tag>" + " <qqq />" + " <xxx />" + " <yyy />" + "</tag>" + ); + child = t->children; + child = kai_tag_get_next_sibling_with_type(child, "xxx"); + REQUIRE_NEQ(child, NULL, "%p"); + CHECK_EQS(child->type, "xxx"); + kai_tag_destroy(t); + child = NULL; + + t = kai_parse_string( + "<tag>" + " <qqq />" + " <yyy />" + "</tag>" + ); + child = t->children; + child = kai_tag_get_next_sibling_with_type(child, "xxx"); + CHECK_EQ(child, NULL, "%p"); + kai_tag_destroy(t); +} +#include LILY_PUSH_TEST() + + + + #define LILY_FILE_END #include LILY_REGISTER_TESTS() |