diff options
Diffstat (limited to 'src/xml/xml.test.c')
-rw-r--r-- | src/xml/xml.test.c | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/src/xml/xml.test.c b/src/xml/xml.test.c index 11c85c9..d3b8360 100644 --- a/src/xml/xml.test.c +++ b/src/xml/xml.test.c @@ -36,22 +36,37 @@ LILY_TEST("convert xml attribute to long") "<tag attr1=\"10\" qq=\"12\"></tag>" ); - int n = kai_tag_attr_to_long(t, "attr1", 0, NULL); + int n = kai_tag_attr_to_long(t, "attr1", 0); CHECK_EQ(n, 10, "%d"); - int m = kai_tag_attr_to_long(t, "attr2", 14, NULL); + int m = kai_tag_attr_to_long(t, "attr2", 14); CHECK_EQ(m, 14, "%d"); - int flag = -1; - int qq = kai_tag_attr_to_long(t, "qq", 0, &flag); - CHECK_EQ(qq, 12, "%d"); - CHECK_EQ(flag, 0, "%d"); + kai_tag_destroy(t); +} +#include LILY_PUSH_TEST() - int k = kai_tag_attr_to_long(t, "dne", 22, &flag); - CHECK_EQ(k, 22, "%d"); - CHECK_EQ(flag, 1, "%d"); +LILY_TEST("duplicate xml attributes") +{ + struct kai_tag_t *t = kai_parse_string( + "<tag attr1=\"hello\"></tag>" + ); + + char *a = kai_tag_attr_to_dup(t, "attr1"); + char *b = kai_tag_attr_to_dup(t, "attr1"); + char *c = kai_tag_attr_to_dup(t, "dne"); kai_tag_destroy(t); + + REQUIRE_NEQ(a, NULL, "%p"); + REQUIRE_NEQ(b, NULL, "%p"); + CHECK_EQ(c, NULL, "%p"); + + CHECK_EQS(a, "hello"); + CHECK_EQS(b, "hello"); + CHECK_NEQ(a, b, "%p"); + + free(a); free(b); } #include LILY_PUSH_TEST() |