X-Git-Url: https://pd.if.org/git/?p=lice;a=blobdiff_plain;f=tests%2Fliteral.c;fp=tests%2Fliteral.c;h=201710f5c751754e02a3da77c288889a25aa74ad;hp=0000000000000000000000000000000000000000;hb=946bdbe1d5dd89ab671391fbe429a1c2c48ecaa7;hpb=f1abb26903687c7967cf37c3f6c830051bdeb371 diff --git a/tests/literal.c b/tests/literal.c new file mode 100644 index 0000000..201710f --- /dev/null +++ b/tests/literal.c @@ -0,0 +1,75 @@ +// literals + +struct s1 { + int a; +}; + +struct s2 { + int a; + struct s3 { + int a[2]; + } *b; +}; + + +int a = (int) { 42 }; +int *b = &(int) { 42 }; +struct s1 *c = &(struct s1) { 42 }; +struct s2 *d = &(struct s2) { 42 , &(struct s3) { 42, 42 } }; + +int main(void) { + expecti('a', 97); + expecti('A', 65); + + //expecti('\0', 0); + expecti('\a', 7); + expecti('\b', 8); + expecti('\t', 9); + expecti('\n', 10); + expecti('\v', 11); + expecti('\f', 12); + expecti('\r', 13); + + expecti('\7', 7); + expecti('\17', 15); + expecti('\235', -99); + + expecti('\x0', 0); + expecti('\xff', -1); + expecti('\x012', 18); + + + expectstr("hello world", "hello world"); + expecti("hello world"[5], ' '); + expecti("hello world"[11], 0); // null terminator + + expectstr( + (char []) { 'h', 'e', 'l', 'l', 'o', 0 }, + "hello" + ); + + expecti(L'c', 'c'); + expectstr(L"butt", "butt"); + + // lexer could fail for 'L' so we need to ensure that it can be + // used as an identifier still. + int L = 1337; + expecti(L, 1337); + int L1 = L; + expecti(L1, L); + + expecti(a, 42); + expecti(*b, 42); + expecti(c->a, 42); + expecti(d->a, 42); + expecti(d->b->a[0], 42); + expecti(d->b->a[1], 42); + + // universal (unicode / host defined) + expecti(L'\u0024', '$'); + expecti(L'\U00000024', '$'); + expectstr("\u0024", "$"); + expectstr("\U00000024", "$"); + + return 0; +}