diff options
author | Mitya Selivanov <automainint@guattari.tech> | 2023-09-17 00:40:34 +0200 |
---|---|---|
committer | Mitya Selivanov <automainint@guattari.tech> | 2023-09-17 00:40:34 +0200 |
commit | 8499b75fb011d72eeb5acbd85bcf41e4ee51e9a7 (patch) | |
tree | a98f9a16b1deb05b949f44a13f9a30c97c812589 /source/tests/xml.test.c | |
parent | 3f7f888e81cc8f34520bc23145422eadb0affad4 (diff) | |
download | kit-8499b75fb011d72eeb5acbd85bcf41e4ee51e9a7.zip |
XML
Diffstat (limited to 'source/tests/xml.test.c')
-rw-r--r-- | source/tests/xml.test.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/source/tests/xml.test.c b/source/tests/xml.test.c new file mode 100644 index 0000000..7d2151c --- /dev/null +++ b/source/tests/xml.test.c @@ -0,0 +1,61 @@ +#include "../kit/xml.h" + +#define KIT_TEST_FILE xml +#include "../kit/kit_test.h" + +TEST("xml parse tag") { + is_handle_t is = IS_WRAP_STRING(SZ("<foo> </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"))); + 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); + + REQUIRE_EQ(res.status, KIT_ERROR_INTERNAL); + + if (res.status == KIT_OK) + xml_destroy(&res.xml); + + is_destroy(is); +} + +TEST("xml parse tag text") { + is_handle_t is = IS_WRAP_STRING(SZ("<foo> 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(AR_EQUAL(res.xml.text, SZ(" bar "))); + xml_destroy(&res.xml); + } + + is_destroy(is); +} + +TEST("xml parse empty tag") { + 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(AR_EQUAL(res.xml.tag, SZ("foo"))); + xml_destroy(&res.xml); + } + + is_destroy(is); +} + +#undef KIT_TEST_FILE |