]> pd.if.org Git - lice/blob - tests/literal.c
autocommit for files dated 2014-11-17 20:13:36
[lice] / tests / literal.c
1 // literals
2
3 struct s1 {
4     int a;
5 };
6
7 struct s2 {
8     int a;
9     struct s3 {
10         int a[2];
11     } *b;
12 };
13
14
15 int        a = (int)  { 42 };
16 int       *b = &(int) { 42 };
17 struct s1 *c = &(struct s1) { 42 };
18 struct s2 *d = &(struct s2) { 42 , &(struct s3) { 42, 42 } };
19
20 int main(void) {
21     expecti('a', 97);
22     expecti('A', 65);
23
24     //expecti('\0', 0);
25     expecti('\a', 7);
26     expecti('\b', 8);
27     expecti('\t', 9);
28     expecti('\n', 10);
29     expecti('\v', 11);
30     expecti('\f', 12);
31     expecti('\r', 13);
32
33     expecti('\7', 7);
34     expecti('\17', 15);
35     expecti('\235', -99);
36
37     expecti('\x0', 0);
38     expecti('\xff', -1);
39     expecti('\x012', 18);
40
41
42     expectstr("hello world", "hello world");
43     expecti("hello world"[5], ' ');
44     expecti("hello world"[11], 0); // null terminator
45
46     expectstr(
47         (char []) { 'h', 'e', 'l', 'l', 'o', 0 },
48         "hello"
49     );
50
51     expecti(L'c', 'c');
52     expectstr(L"butt", "butt");
53
54     // lexer could fail for 'L' so we need to ensure that it can be
55     // used as an identifier still.
56     int L = 1337;
57     expecti(L, 1337);
58     int L1 = L;
59     expecti(L1, L);
60
61     expecti(a,          42);
62     expecti(*b,         42);
63     expecti(c->a,       42);
64     expecti(d->a,       42);
65     expecti(d->b->a[0], 42);
66     expecti(d->b->a[1], 42);
67
68     // universal (unicode / host defined)
69     expecti(L'\u0024', '$');
70     expecti(L'\U00000024', '$');
71     expectstr("\u0024", "$");
72     expectstr("\U00000024", "$");
73
74     return 0;
75 }