1 | #include "mycpp/common.h"
|
2 | #include "vendor/greatest.h"
|
3 |
|
4 | TEST libc_demo() {
|
5 | int x = strcmp("a", "b");
|
6 | log("strcmp = %d", x);
|
7 | x = strcmp("a", "a");
|
8 | log("strcmp = %d", x);
|
9 |
|
10 | // Functions to test with:
|
11 | // - different LANG settings
|
12 | // - musl libc vs. GNU libc, etc.
|
13 | //
|
14 | // glob() and fnmatch()
|
15 | // regexec()
|
16 | // strcoll()
|
17 | // int toupper(), tolower(), toupper_l() can be passed locale
|
18 | //
|
19 | // See doc/unicode.md
|
20 |
|
21 | // We could have pyext/libc.c wrappers for this, rather than using Python
|
22 | // str.upper(). Maybe remove Str::{upper,lower}() from the Yaks language,
|
23 | // since it depends on Unicode.
|
24 |
|
25 | int c;
|
26 | c = toupper((unsigned char)'a');
|
27 | log("toupper %c", c);
|
28 |
|
29 | c = tolower((unsigned char)c);
|
30 | log("tolower %c", c);
|
31 | }
|
32 |
|
33 | TEST isspace_demo() {
|
34 | int x;
|
35 |
|
36 | // 0xa0 from
|
37 | // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#white_space
|
38 | //
|
39 | // Somehow it's false
|
40 | //
|
41 | // In Python we have
|
42 | // >>> '\u00a0'.isspace()
|
43 | // True
|
44 |
|
45 | // U+00A0 is non-breaking space
|
46 | // U+FEFF is zero-width no break space - this is true
|
47 | int cases[] = {'\0', '\t', '\v', '\f', ' ', 'a', 0xa0, 0xfeff};
|
48 | int n = sizeof(cases) / sizeof(cases[0]);
|
49 |
|
50 | for (int i = 0; i < n; ++i) {
|
51 | int x = isspace(cases[i]);
|
52 | log("isspace %x %d", cases[i], x);
|
53 | }
|
54 | PASS();
|
55 | }
|
56 |
|
57 | GREATEST_MAIN_DEFS();
|
58 |
|
59 | int main(int argc, char **argv) {
|
60 | // gHeap.Init();
|
61 |
|
62 | GREATEST_MAIN_BEGIN();
|
63 |
|
64 | RUN_TEST(libc_demo);
|
65 | RUN_TEST(isspace_demo);
|
66 |
|
67 | // gHeap.CleanProcessExit();
|
68 |
|
69 | GREATEST_MAIN_END();
|
70 | return 0;
|
71 | }
|