summaryrefslogtreecommitdiff
path: root/source/tests
diff options
context:
space:
mode:
Diffstat (limited to 'source/tests')
-rw-r--r--source/tests/input_buffer.test.c8
-rw-r--r--source/tests/xml.test.c85
2 files changed, 89 insertions, 4 deletions
diff --git a/source/tests/input_buffer.test.c b/source/tests/input_buffer.test.c
index 237d60d..89717d1 100644
--- a/source/tests/input_buffer.test.c
+++ b/source/tests/input_buffer.test.c
@@ -56,7 +56,7 @@ TEST("input buffer read twice") {
is_destroy(in);
}
-static i8 is_integer_(str_t const data) {
+static i8 is_integer_(str_t const data, void *_) {
for (ptrdiff_t i = 0; i < data.size; i++)
if (data.values[i] < '0' || data.values[i] > '9')
return 0;
@@ -69,7 +69,7 @@ TEST("input buffer read integer once") {
is_handle_t in = IS_WRAP_STRING(text);
ib_t first = IB_WRAP(in);
- ib_t second = ib_while(first, is_integer_);
+ ib_t second = ib_while(first, is_integer_, NULL);
REQUIRE(second.status == KIT_OK);
REQUIRE(second.data.size == 5);
@@ -87,9 +87,9 @@ TEST("input buffer read integer twice") {
is_handle_t in = IS_WRAP_STRING(text);
ib_t first = IB_WRAP(in);
- ib_t second = ib_while(first, is_integer_);
+ ib_t second = ib_while(first, is_integer_, NULL);
ib_t third = ib_read(second, 1);
- ib_t fourth = ib_while(third, is_integer_);
+ ib_t fourth = ib_while(third, is_integer_, NULL);
REQUIRE(fourth.status == KIT_OK);
REQUIRE(second.data.size == 3);
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