From bbb397d327f84be61f90cb2744c3f29d395857fd Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Fri, 22 Sep 2023 16:50:23 +0200 Subject: xml: comments --- source/tests/xml.test.c | 157 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) (limited to 'source/tests') 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(" ")); + 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("")); 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("")); + 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("")); + 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(" 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.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 ")); + 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 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.text, SZ("foo bar"))); + xml_destroy(&res.xml); + } + + is_destroy(is); +} + +TEST("xml parse comment tail") { + is_handle_t is = IS_WRAP_STRING(SZ("")); + 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(" 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(" 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 between text") { + 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("tag"))); + REQUIRE(AR_EQUAL(res.xml.tail, SZ("foo bar"))); + xml_destroy(&res.xml); + } + + is_destroy(is); +} + #undef KIT_TEST_FILE -- cgit v1.2.3