summaryrefslogtreecommitdiff
path: root/source/tests/xml.test.c
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2023-09-19 05:34:00 +0200
committerMitya Selivanov <automainint@guattari.tech>2023-09-19 05:34:00 +0200
commit18c419ffb4e750c3c9ea8570cf18f3099267b1bb (patch)
treea1d936834a54934cb4407f870d2ac1dbaa87cd3b /source/tests/xml.test.c
parent8499b75fb011d72eeb5acbd85bcf41e4ee51e9a7 (diff)
downloadkit-18c419ffb4e750c3c9ea8570cf18f3099267b1bb.zip
Update xml parsing
Diffstat (limited to 'source/tests/xml.test.c')
-rw-r--r--source/tests/xml.test.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/source/tests/xml.test.c b/source/tests/xml.test.c
index 7d2151c..52ff7c0 100644
--- a/source/tests/xml.test.c
+++ b/source/tests/xml.test.c
@@ -58,4 +58,89 @@ TEST("xml parse empty tag") {
is_destroy(is);
}
+TEST("xml parse tail") {
+ is_handle_t is = IS_WRAP_STRING(SZ("<foo></foo> bar"));
+ xml_parse_result_t res = xml_parse(is, NULL);
+
+ REQUIRE_EQ(res.status, KIT_OK);
+
+ if (res.status == KIT_OK) {
+ REQUIRE(AR_EQUAL(res.xml.tag, SZ("foo")));
+ REQUIRE(AR_EQUAL(res.xml.tail, SZ(" bar")));
+ xml_destroy(&res.xml);
+ }
+
+ is_destroy(is);
+}
+
+TEST("xml parse empty tail") {
+ is_handle_t is = IS_WRAP_STRING(SZ("<foo /> bar"));
+ xml_parse_result_t res = xml_parse(is, NULL);
+
+ REQUIRE_EQ(res.status, KIT_OK);
+
+ if (res.status == KIT_OK) {
+ REQUIRE(AR_EQUAL(res.xml.tag, SZ("foo")));
+ REQUIRE(AR_EQUAL(res.xml.tail, SZ(" bar")));
+ xml_destroy(&res.xml);
+ }
+
+ is_destroy(is);
+}
+
+TEST("xml parse property") {
+ is_handle_t is = IS_WRAP_STRING(SZ("<foo bar=\"42\"></foo>"));
+ xml_parse_result_t res = xml_parse(is, NULL);
+
+ REQUIRE_EQ(res.status, KIT_OK);
+
+ if (res.status == KIT_OK) {
+ REQUIRE(AR_EQUAL(res.xml.tag, SZ("foo")));
+ REQUIRE_EQ(res.xml.properties.size, 1);
+ if (res.xml.properties.size == 1) {
+ REQUIRE(AR_EQUAL(res.xml.properties.values[0].name, SZ("bar")));
+ REQUIRE(AR_EQUAL(res.xml.properties.values[0].value, SZ("42")));
+ }
+ xml_destroy(&res.xml);
+ }
+
+ is_destroy(is);
+}
+
+TEST("xml parse empty property") {
+ is_handle_t is = IS_WRAP_STRING(SZ("<foo bar=\"42\" />"));
+ xml_parse_result_t res = xml_parse(is, NULL);
+
+ REQUIRE_EQ(res.status, KIT_OK);
+
+ if (res.status == KIT_OK) {
+ REQUIRE(AR_EQUAL(res.xml.tag, SZ("foo")));
+ REQUIRE_EQ(res.xml.properties.size, 1);
+ if (res.xml.properties.size == 1) {
+ REQUIRE(AR_EQUAL(res.xml.properties.values[0].name, SZ("bar")));
+ REQUIRE(AR_EQUAL(res.xml.properties.values[0].value, SZ("42")));
+ }
+ xml_destroy(&res.xml);
+ }
+
+ is_destroy(is);
+}
+
+TEST("xml parse child") {
+ is_handle_t is = IS_WRAP_STRING(SZ("<foo><bar></bar></foo>"));
+ xml_parse_result_t res = xml_parse(is, NULL);
+
+ REQUIRE_EQ(res.status, KIT_OK);
+
+ if (res.status == KIT_OK) {
+ REQUIRE(AR_EQUAL(res.xml.tag, SZ("foo")));
+ REQUIRE_EQ(res.xml.children.size, 1);
+ if (res.xml.children.size == 1)
+ REQUIRE(AR_EQUAL(res.xml.children.values[0].tag, SZ("bar")));
+ xml_destroy(&res.xml);
+ }
+
+ is_destroy(is);
+}
+
#undef KIT_TEST_FILE