sexp-test.c 2.54 KB
Newer Older
1
2
3
4
5
6
7
8
#include "testutils.h"
#include "sexp.h"

int
test_main(void)
{
  struct sexp_iterator i;

9
10
  ASSERT(sexp_iterator_first(&i, LDATA("")));
  ASSERT(i.type == SEXP_END);
11

12
13
  ASSERT(sexp_iterator_first(&i, LDATA("()")));
  ASSERT(i.type == SEXP_LIST
14
	 && sexp_iterator_enter_list(&i)
15
	 && i.type == SEXP_END
16
	 && sexp_iterator_exit_list(&i)
17
	 && i.type == SEXP_END);
18

19
20
  ASSERT(sexp_iterator_first(&i, LDATA("(")));
  ASSERT(i.type == SEXP_LIST
21
	 && !sexp_iterator_enter_list(&i));
22

23
  ASSERT(sexp_iterator_first(&i, LDATA("3:foo0:[3:bar]12:xxxxxxxxxxxx")));
24
  ASSERT(i.type == SEXP_ATOM
25
26
27
28
29
30
31
32
33
	 && !i.display_length && !i.display
	 && i.atom_length == 3 && MEMEQ(3, "foo", i.atom)

	 && sexp_iterator_next(&i) && i.type == SEXP_ATOM
	 && !i.display_length && !i.display
	 && !i.atom_length && i.atom

	 && sexp_iterator_next(&i) && i.type == SEXP_ATOM
	 && i.display_length == 3 && MEMEQ(3, "bar", i.display)
34
	 && i.atom_length == 12 && MEMEQ(12, "xxxxxxxxxxxx", i.atom)
35

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
	 && sexp_iterator_next(&i) && i.type == SEXP_END);
  
  /* Same data, transport encoded. */
  
  ASSERT(sexp_transport_iterator_first
	 (&i, LDUP("{Mzpmb28=} {MDo=} {WzM6YmFyXTEyOnh4eHh4eHh4eHh4eA==}")));
  ASSERT(i.type == SEXP_ATOM
	 && !i.display_length && !i.display
	 && i.atom_length == 3 && MEMEQ(3, "foo", i.atom)

	 && sexp_iterator_next(&i) && i.type == SEXP_ATOM
	 && !i.display_length && !i.display
	 && !i.atom_length && i.atom

	 && sexp_iterator_next(&i) && i.type == SEXP_ATOM
	 && i.display_length == 3 && MEMEQ(3, "bar", i.display)
	 && i.atom_length == 12 && MEMEQ(12, "xxxxxxxxxxxx", i.atom)

	 && sexp_iterator_next(&i) && i.type == SEXP_END);
  
56
  {
Niels Möller's avatar
Niels Möller committed
57
    static const uint8_t *keys[2] = { "n", "e" };
58
59
    struct sexp_iterator v[2];
    
60
61
    ASSERT(sexp_iterator_first(&i, LDATA("((1:n2:xx3:foo)0:(1:y)(1:e))")));
    ASSERT(sexp_iterator_enter_list(&i)
62
	   && sexp_iterator_assoc(&i, 2, keys, v));
63

64
    ASSERT(v[0].type == SEXP_ATOM
65
66
67
68
69
70
71
72
	   && !v[0].display_length && !v[0].display
	   && v[0].atom_length == 2 && MEMEQ(2, "xx", v[0].atom)

	   && sexp_iterator_next(&v[0]) && v[0].type == SEXP_ATOM
	   && !v[0].display_length && !v[0].display
	   && v[0].atom_length == 3 && MEMEQ(3, "foo", v[0].atom)

	   && sexp_iterator_next(&v[0]) && v[0].type == SEXP_END);
73

74
    ASSERT(v[1].type == SEXP_END);
75

76
77
    ASSERT(sexp_iterator_first(&i, LDATA("((1:n))")));
    ASSERT(sexp_iterator_enter_list(&i)
78
79
	   && !sexp_iterator_assoc(&i, 2, keys, v));

80
81
    ASSERT(sexp_iterator_first(&i, LDATA("((1:n)(1:n3:foo))")));
    ASSERT(sexp_iterator_enter_list(&i)
Niels Möller's avatar
Niels Möller committed
82
	   && !sexp_iterator_assoc(&i, 2, keys, v));    
83
  }
Niels Möller's avatar
Niels Möller committed
84

85
86
  SUCCESS();
}