-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathse-test.c
More file actions
92 lines (73 loc) · 1.68 KB
/
se-test.c
File metadata and controls
92 lines (73 loc) · 1.68 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* S-Expressions Test
*
* Copyright (c) 2019-2023 Alexei A. Smekalkine
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <err.h>
#include <stdio.h>
#include <data/se.h>
static const char *strings[] = {
"test string #1",
"Lorem ipsum dolor sit amet",
"consectetur adipiscing elit",
"sed do eiusmod tempor incididunt",
"ut labore et dolore magna aliqua",
"test string #2",
NULL,
};
static void test_atom (struct se_scope *scope, const char *name)
{
struct se *o;
if ((o = se_atom (scope, name)) == NULL)
err (1, "cannot allocate atom");
printf ("%p: %s\n", o, se_atom_name (o));
}
static void test_atoms (void)
{
struct se_scope *scope;
const char **p;
if ((scope = se_scope_alloc (0)) == NULL)
err (1, "cannot allocate scope");
for (p = strings; *p != NULL; ++p)
test_atom (scope, *p);
test_atom (scope, strings[1]);
test_atom (scope, strings[3]);
se_scope_free (scope);
}
static void test_pairs (void)
{
struct se_scope *s;
struct se *o = NULL;
if ((s = se_scope_alloc (0)) == NULL)
err (1, "cannot allocate scope");
o = se_list (
se_atom (s, "add"), se_atom (s, "13"), se_atom (s, "72"),
se_list (
se_atom (s, "mul"), se_atom (s, "x yz"),
se_atom (s, "\003"),
se_atom (s, "5"), se_atom (s, "m"), NULL
),
se_atom (s, "string \"in quotes\" with \\-func"),
NULL
);
se_show (o, stdout);
printf ("\n");
o = se_pair (o, se_atom (s, "non-nil"));
se_show (o, stdout);
printf ("\n");
o = se_pair (NULL, o);
se_show (o, stdout);
printf ("\n");
se_free (o);
se_scope_free (s);
}
int main (int argc, char *argv[])
{
printf ("test atom table:\n\n");
test_atoms ();
printf ("\ntest se pairs and lists:\n\n");
test_pairs ();
return 0;
}