summaryrefslogtreecommitdiff
path: root/source/tests
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2023-09-22 18:34:05 +0200
committerMitya Selivanov <automainint@guattari.tech>2023-09-22 18:34:05 +0200
commita6b362e7bedca7f0dfe9e352ea7a895e4ac7e3c4 (patch)
treea14b9f2e24c0dafbbc1a1605564f1acddbb38c55 /source/tests
parentbbb397d327f84be61f90cb2744c3f29d395857fd (diff)
downloadkit-a6b362e7bedca7f0dfe9e352ea7a895e4ac7e3c4.zip
xml escapes; xml full text
Diffstat (limited to 'source/tests')
-rw-r--r--source/tests/xml.test.c106
1 files changed, 106 insertions, 0 deletions
diff --git a/source/tests/xml.test.c b/source/tests/xml.test.c
index e477acb..2a0b114 100644
--- a/source/tests/xml.test.c
+++ b/source/tests/xml.test.c
@@ -161,6 +161,26 @@ TEST("xml parse child") {
is_destroy(is);
}
+TEST("xml parse child with text and tail") {
+ is_handle_t is = IS_WRAP_STRING(SZ("<foo>text<bar /> tail</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(AR_EQUAL(res.xml.text, SZ("text")));
+ REQUIRE_EQ(res.xml.children.size, 1);
+ if (res.xml.children.size == 1) {
+ REQUIRE(AR_EQUAL(res.xml.children.values[0].tag, SZ("bar")));
+ REQUIRE(AR_EQUAL(res.xml.children.values[0].tail, SZ(" tail")));
+ }
+ xml_destroy(&res.xml);
+ }
+
+ is_destroy(is);
+}
+
TEST("xml parse declaration") {
is_handle_t is = IS_WRAP_STRING(SZ("<?foo ?>"));
xml_parse_result_t res = xml_parse(is, NULL);
@@ -300,4 +320,90 @@ TEST("xml parse comment tail between text") {
is_destroy(is);
}
+TEST("xml parse escaped text") {
+ is_handle_t is = IS_WRAP_STRING(SZ("&lt;foo&gt;"));
+ xml_parse_result_t res = xml_parse(is, NULL);
+
+ REQUIRE_EQ(res.status, KIT_OK);
+
+ if (res.status == KIT_OK) {
+ REQUIRE_EQ(res.xml.is_declaration, 0);
+ REQUIRE(AR_EQUAL(res.xml.text, SZ("<foo>")));
+ xml_destroy(&res.xml);
+ }
+
+ is_destroy(is);
+}
+
+TEST("xml parse escaped quote property") {
+ is_handle_t is = IS_WRAP_STRING(SZ("<foo bar=\"&amp;&quot;\" />"));
+ xml_parse_result_t res = xml_parse(is, NULL);
+
+ REQUIRE_EQ(res.status, KIT_OK);
+
+ if (res.status == KIT_OK) {
+ REQUIRE_EQ(res.xml.is_declaration, 0);
+ 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("&\"")));
+ }
+ xml_destroy(&res.xml);
+ }
+
+ is_destroy(is);
+}
+
+TEST("xml parse escaped apostrophe property") {
+ is_handle_t is = IS_WRAP_STRING(SZ("<foo bar='&amp;&apos;' />"));
+ xml_parse_result_t res = xml_parse(is, NULL);
+
+ REQUIRE_EQ(res.status, KIT_OK);
+
+ if (res.status == KIT_OK) {
+ REQUIRE_EQ(res.xml.is_declaration, 0);
+ 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("&'")));
+ }
+ xml_destroy(&res.xml);
+ }
+
+ is_destroy(is);
+}
+
+TEST("xml parse invalid escape") {
+ is_handle_t is = IS_WRAP_STRING(SZ("&foobar;"));
+ xml_parse_result_t res = xml_parse(is, NULL);
+
+ REQUIRE_EQ(res.status, KIT_ERROR_INTERNAL);
+
+ if (res.status == KIT_OK)
+ xml_destroy(&res.xml);
+
+ is_destroy(is);
+}
+
+TEST("xml full text") {
+ is_handle_t is = IS_WRAP_STRING(
+ SZ("<tag>foo <a>text</a> bar <b>text</b> tail</tag>"));
+ xml_parse_result_t res = xml_parse(is, NULL);
+
+ REQUIRE_EQ(res.status, KIT_OK);
+
+ if (res.status == KIT_OK) {
+ xml_text_t text = xml_full_text(&res.xml, NULL);
+ REQUIRE_EQ(text.status, KIT_OK);
+ REQUIRE(AR_EQUAL(text.text, SZ("foo text bar text tail")));
+ DA_DESTROY(text.text);
+ xml_destroy(&res.xml);
+ }
+
+ is_destroy(is);
+}
+
#undef KIT_TEST_FILE