summaryrefslogtreecommitdiff
path: root/source/tests/xml.test.c
blob: 7d2151cdfd940aec8f97c6b7c5b535688c78bec1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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