summaryrefslogtreecommitdiff
path: root/src/xml/xml.test.c
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-02-04 00:27:55 -0600
committersanine <sanine.not@pm.me>2023-02-04 00:27:55 -0600
commit0bb180e4ddeebf6d219a38b862ce3e8238f99c54 (patch)
tree9556fd77d16cdcee69ff0c9c0765c408ee88ae19 /src/xml/xml.test.c
parent6292c2bce712dcca01ded960dc5f93528da2b9ce (diff)
add kai_tag_attr_to_dup()
Diffstat (limited to 'src/xml/xml.test.c')
-rw-r--r--src/xml/xml.test.c33
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()