summaryrefslogtreecommitdiff
path: root/source/tests
diff options
context:
space:
mode:
Diffstat (limited to 'source/tests')
-rw-r--r--source/tests/xml.test.c157
1 files changed, 157 insertions, 0 deletions
diff --git a/source/tests/xml.test.c b/source/tests/xml.test.c
index 52ff7c0..e477acb 100644
--- a/source/tests/xml.test.c
+++ b/source/tests/xml.test.c
@@ -10,6 +10,7 @@ TEST("xml parse tag") {
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")));
xml_destroy(&res.xml);
}
@@ -17,6 +18,21 @@ TEST("xml parse tag") {
is_destroy(is);
}
+TEST("xml parse tag with dash") {
+ is_handle_t is = IS_WRAP_STRING(SZ("<foo-bar> </foo-bar>"));
+ 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-bar")));
+ xml_destroy(&res.xml);
+ }
+
+ is_destroy(is);
+}
+
TEST("xml parse tag not closed") {
is_handle_t is = IS_WRAP_STRING(SZ("<foo>"));
xml_parse_result_t res = xml_parse(is, NULL);
@@ -36,6 +52,7 @@ TEST("xml parse tag text") {
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(AR_EQUAL(res.xml.text, SZ(" bar ")));
xml_destroy(&res.xml);
@@ -51,6 +68,7 @@ TEST("xml parse empty tag") {
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")));
xml_destroy(&res.xml);
}
@@ -143,4 +161,143 @@ TEST("xml parse child") {
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);
+
+ REQUIRE_EQ(res.status, KIT_OK);
+
+ if (res.status == KIT_OK) {
+ REQUIRE_EQ(res.xml.is_declaration, 1);
+ REQUIRE(AR_EQUAL(res.xml.tag, SZ("foo")));
+ xml_destroy(&res.xml);
+ }
+
+ is_destroy(is);
+}
+
+TEST("xml parse comment") {
+ 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_EQ(res.xml.is_declaration, 0);
+ REQUIRE(AR_EQUAL(res.xml.tag, SZ("bar")));
+ xml_destroy(&res.xml);
+ }
+
+ is_destroy(is);
+}
+
+TEST("xml parse comment before text") {
+ is_handle_t is = IS_WRAP_STRING(SZ("<!-- foo --> bar <tag />"));
+ 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(" bar ")));
+ xml_destroy(&res.xml);
+ }
+
+ is_destroy(is);
+}
+
+TEST("xml parse comment after text") {
+ is_handle_t is = IS_WRAP_STRING(SZ("foo <!-- bar --><tag />"));
+ 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 comment between text") {
+ is_handle_t is = IS_WRAP_STRING(
+ SZ("foo<!-- comment --> bar<tag />"));
+ 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 bar")));
+ xml_destroy(&res.xml);
+ }
+
+ is_destroy(is);
+}
+
+TEST("xml parse comment tail") {
+ is_handle_t is = IS_WRAP_STRING(SZ("<foo /><!-- tail -->"));
+ 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")));
+ xml_destroy(&res.xml);
+ }
+
+ is_destroy(is);
+}
+
+TEST("xml parse comment tail before text") {
+ is_handle_t is = IS_WRAP_STRING(SZ("<foo /><!-- tail --> bar"));
+ 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(AR_EQUAL(res.xml.tail, SZ(" bar")));
+ xml_destroy(&res.xml);
+ }
+
+ is_destroy(is);
+}
+
+TEST("xml parse comment tail after text") {
+ is_handle_t is = IS_WRAP_STRING(SZ("<foo /> bar <!-- tail -->"));
+ 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(AR_EQUAL(res.xml.tail, SZ(" bar ")));
+ xml_destroy(&res.xml);
+ }
+
+ is_destroy(is);
+}
+
+TEST("xml parse comment tail between text") {
+ is_handle_t is = IS_WRAP_STRING(SZ("<tag />foo<!-- tail --> bar"));
+ 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("tag")));
+ REQUIRE(AR_EQUAL(res.xml.tail, SZ("foo bar")));
+ xml_destroy(&res.xml);
+ }
+
+ is_destroy(is);
+}
+
#undef KIT_TEST_FILE