File: string.c

package info (click to toggle)
chibicc 1.0.23.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,832 kB
  • sloc: ansic: 62,911; sh: 275; makefile: 92
file content (72 lines) | stat: -rwxr-xr-x 1,692 bytes parent folder | download | duplicates (3)
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
#include "test.h"

int main() {
  ASSERT(0, ""[0]);
  ASSERT(1, sizeof(""));

  ASSERT(97, "abc"[0]);
  ASSERT(98, "abc"[1]);
  ASSERT(99, "abc"[2]);
  ASSERT(0, "abc"[3]);
  ASSERT(4, sizeof("abc"));

  ASSERT(7, "\a"[0]);
  ASSERT(8, "\b"[0]);
  ASSERT(9, "\t"[0]);
  ASSERT(10, "\n"[0]);
  ASSERT(11, "\v"[0]);
  ASSERT(12, "\f"[0]);
  ASSERT(13, "\r"[0]);
  ASSERT(27, "\e"[0]);

  ASSERT(106, "\j"[0]);
  ASSERT(107, "\k"[0]);
  ASSERT(108, "\l"[0]);

  ASSERT(7, "\ax\ny"[0]);
  ASSERT(120, "\ax\ny"[1]);
  ASSERT(10, "\ax\ny"[2]);
  ASSERT(121, "\ax\ny"[3]);

  ASSERT(0, "\0"[0]);
  ASSERT(16, "\20"[0]);
  ASSERT(65, "\101"[0]);
  ASSERT(104, "\1500"[0]);
  ASSERT(0, "\x00"[0]);
  ASSERT(119, "\x77"[0]);

  ASSERT(7, sizeof("abc" "def"));
  ASSERT(9, sizeof("abc" "d" "efgh"));
  ASSERT(0, strcmp("abc" "d" "\nefgh", "abcd\nefgh"));
  ASSERT(0, !strcmp("abc" "d", "abcd\nefgh"));
  ASSERT(0, strcmp("\x9" "0", "\t0"));

  ASSERT(16, sizeof(L"abc" ""));

  ASSERT(28, sizeof(L"abc" "def"));
  ASSERT(28, sizeof(L"abc" L"def"));
  ASSERT(14, sizeof(u"abc" "def"));
  ASSERT(14, sizeof(u"abc" u"def"));

  ASSERT(L'a', (L"abc" "def")[0]);
  ASSERT(L'd', (L"abc" "def")[3]);
  ASSERT(L'\0', (L"abc" "def")[6]);

  ASSERT(u'a', (u"abc" "def")[0]);
  ASSERT(u'd', (u"abc" "def")[3]);
  ASSERT(u'\0', (u"abc" "def")[6]);

  ASSERT(L'あ', ("あ" L"")[0]);
  ASSERT(0343, ("\343\201\202" L"")[0]);
  ASSERT(0201, ("\343\201\202" L"")[1]);
  ASSERT(0202, ("\343\201\202" L"")[2]);
  ASSERT(0, ("\343\201\202" L"")[3]);

  ASSERT(L'a', ("a" "b" L"c")[0]);
  ASSERT(L'b', ("a" "b" L"c")[1]);
  ASSERT(L'c', ("a" "b" L"c")[2]);
  ASSERT(0, ("a" "b" L"c")[3]);

  printf("OK\n");
  return 0;
}