mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-30 17:22:27 +00:00
Improve some unicode functions
This commit is contained in:
parent
b9187061a7
commit
1b5a5719c3
33 changed files with 8366 additions and 197 deletions
|
@ -83,24 +83,29 @@ TEST(regex, testIpExtended) {
|
|||
regfree(&rx);
|
||||
}
|
||||
|
||||
TEST(regex, testUnicodeCharacterClass) {
|
||||
regex_t rx;
|
||||
EXPECT_EQ(REG_OK, regcomp(&rx, "^[[:alpha:]][[:alpha:]]$", 0));
|
||||
EXPECT_EQ(REG_OK, regexec(&rx, "𝐵𝑏", 0, 0, 0));
|
||||
EXPECT_NE(REG_OK, regexec(&rx, "₀₁", 0, 0, 0));
|
||||
regfree(&rx);
|
||||
}
|
||||
|
||||
void A(void) {
|
||||
regex_t rx;
|
||||
regcomp(&rx, "^[-._0-9A-Za-z]*$", REG_EXTENDED);
|
||||
regexec(&rx, "foo.com", 0, NULL, 0);
|
||||
regfree(&rx);
|
||||
}
|
||||
|
||||
void B(regex_t *rx) {
|
||||
regexec(rx, "foo.com", 0, NULL, 0);
|
||||
}
|
||||
|
||||
void C(void) {
|
||||
regex_t rx;
|
||||
regcomp(&rx, "^[-._0-9A-Za-z]*$", 0);
|
||||
regexec(&rx, "foo.com", 0, NULL, 0);
|
||||
regfree(&rx);
|
||||
}
|
||||
|
||||
void D(regex_t *rx, regmatch_t *m) {
|
||||
regexec(rx, "127.0.0.1", rx->re_nsub + 1, m, 0);
|
||||
}
|
||||
|
@ -113,7 +118,6 @@ BENCH(regex, bench) {
|
|||
regfree(&rx);
|
||||
EZBENCH2("easy api extended", donothing, A());
|
||||
EZBENCH2("easy api basic", donothing, C());
|
||||
|
||||
EXPECT_EQ(REG_OK, regcomp(&rx,
|
||||
"^"
|
||||
"\\([0-9][0-9]*\\)\\."
|
||||
|
@ -126,7 +130,6 @@ BENCH(regex, bench) {
|
|||
EZBENCH2("precompiled basic match", donothing, D(&rx, m));
|
||||
free(m);
|
||||
regfree(&rx);
|
||||
|
||||
EXPECT_EQ(REG_OK, regcomp(&rx,
|
||||
"^"
|
||||
"([0-9]{1,3})\\."
|
||||
|
@ -139,7 +142,6 @@ BENCH(regex, bench) {
|
|||
EZBENCH2("precompiled extended match", donothing, D(&rx, m));
|
||||
free(m);
|
||||
regfree(&rx);
|
||||
|
||||
EXPECT_EQ(REG_OK, regcomp(&rx,
|
||||
"^"
|
||||
"([0-9]{1,3})\\."
|
||||
|
|
74
test/libc/str/towupper_test.c
Normal file
74
test/libc/str/towupper_test.c
Normal file
|
@ -0,0 +1,74 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dce.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(towupper, test) {
|
||||
EXPECT_EQ(u'!', towupper(u'!'));
|
||||
EXPECT_EQ(u'A', towupper(u'a'));
|
||||
EXPECT_EQ(u'À', towupper(u'à'));
|
||||
if (IsTiny()) return;
|
||||
EXPECT_EQ(L'𝛥', towupper(L'𝛿'));
|
||||
EXPECT_EQ(L'B', towupper(L'b'));
|
||||
}
|
||||
|
||||
TEST(towlower, test) {
|
||||
EXPECT_EQ(u'!', towlower(u'!'));
|
||||
EXPECT_EQ(u'a', towlower(u'A'));
|
||||
EXPECT_EQ(u'à', towlower(u'À'));
|
||||
if (IsTiny()) return;
|
||||
EXPECT_EQ(L'𝛿', towlower(L'𝛥'));
|
||||
EXPECT_EQ(L'b', towlower(L'B'));
|
||||
}
|
||||
|
||||
BENCH(towupper, bench) {
|
||||
EZBENCH2("towupper ascii", donothing, EXPROPRIATE(towupper(VEIL("r", L'a'))));
|
||||
EZBENCH2("towupper latin1", donothing,
|
||||
EXPROPRIATE(towupper(VEIL("r", u'A'))));
|
||||
if (IsTiny()) return;
|
||||
EZBENCH2("towupper astral", donothing,
|
||||
EXPROPRIATE(towupper(VEIL("r", L'𝛿'))));
|
||||
}
|
||||
|
||||
BENCH(towlower, bench) {
|
||||
EZBENCH2("towlower ascii", donothing, EXPROPRIATE(towlower(VEIL("r", L'a'))));
|
||||
EZBENCH2("towlower latin1", donothing,
|
||||
EXPROPRIATE(towlower(VEIL("r", u'A'))));
|
||||
if (IsTiny()) return;
|
||||
EZBENCH2("towlower astral", donothing,
|
||||
EXPROPRIATE(towlower(VEIL("r", L'𝛿'))));
|
||||
}
|
||||
|
||||
BENCH(iswupper, bench) {
|
||||
EZBENCH2("iswupper ascii", donothing, EXPROPRIATE(iswupper(VEIL("r", L'A'))));
|
||||
EZBENCH2("iswupper latin1", donothing,
|
||||
EXPROPRIATE(iswupper(VEIL("r", u'A'))));
|
||||
EZBENCH2("iswupper astral", donothing,
|
||||
EXPROPRIATE(iswupper(VEIL("r", L'𝛿'))));
|
||||
}
|
||||
|
||||
BENCH(iswlower, bench) {
|
||||
EZBENCH2("iswlower ascii", donothing, EXPROPRIATE(iswlower(VEIL("r", L'a'))));
|
||||
EZBENCH2("iswlower latin1", donothing,
|
||||
EXPROPRIATE(iswlower(VEIL("r", u'A'))));
|
||||
EZBENCH2("iswlower astral", donothing,
|
||||
EXPROPRIATE(iswlower(VEIL("r", L'𝛿'))));
|
||||
}
|
|
@ -32,6 +32,7 @@
|
|||
#include "libc/sysv/consts/shut.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/sysv/consts/sock.h"
|
||||
#include "libc/sysv/consts/tcp.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
#include "third_party/regex/regex.h"
|
||||
|
@ -58,13 +59,27 @@ void SetUpOnce(void) {
|
|||
close(fdin);
|
||||
}
|
||||
|
||||
void Tune(int fd, int a, int b, int x) {
|
||||
if (!b) return;
|
||||
setsockopt(fd, a, b, &x, sizeof(x));
|
||||
}
|
||||
|
||||
int Socket(void) {
|
||||
int fd;
|
||||
if ((fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) != -1) {
|
||||
Tune(fd, IPPROTO_TCP, TCP_CORK, 0);
|
||||
Tune(fd, IPPROTO_TCP, TCP_NODELAY, 1);
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
char *SendHttpRequest(const char *s) {
|
||||
int fd;
|
||||
char *p;
|
||||
size_t n;
|
||||
ssize_t rc;
|
||||
struct sockaddr_in addr = {AF_INET, htons(port), {htonl(INADDR_LOOPBACK)}};
|
||||
EXPECT_NE(-1, (fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)));
|
||||
EXPECT_NE(-1, (fd = Socket()));
|
||||
EXPECT_NE(-1, connect(fd, &addr, sizeof(addr)));
|
||||
n = strlen(s);
|
||||
EXPECT_EQ(n, write(fd, s, n));
|
||||
|
@ -114,10 +129,52 @@ TEST(redbean, testOptions) {
|
|||
"Accept-Charset: utf-8,ISO-8859-1;q=0\\.7,\\*;q=0\\.5\r\n"
|
||||
"Allow: GET, HEAD, POST, PUT, DELETE, OPTIONS\r\n"
|
||||
"Date: .*\r\n"
|
||||
"Server: redbean/0\\.4\r\n"
|
||||
"Server: redbean/.*\r\n"
|
||||
"Content-Length: 0\r\n"
|
||||
"\r\n",
|
||||
gc(SendHttpRequest("OPTIONS * HTTP/1.1\n\n"))));
|
||||
EXPECT_NE(-1, kill(pid, SIGTERM));
|
||||
EXPECT_NE(-1, wait(0));
|
||||
}
|
||||
|
||||
TEST(redbean, testPipeline) {
|
||||
if (IsWindows()) return;
|
||||
char portbuf[16];
|
||||
int pid, pipefds[2];
|
||||
sigset_t chldmask, savemask;
|
||||
sigaddset(&chldmask, SIGCHLD);
|
||||
sigprocmask(SIG_BLOCK, &chldmask, &savemask);
|
||||
ASSERT_NE(-1, pipe(pipefds));
|
||||
ASSERT_NE(-1, (pid = vfork()));
|
||||
if (!pid) {
|
||||
close(pipefds[0]);
|
||||
dup2(pipefds[1], 1);
|
||||
sigprocmask(SIG_SETMASK, &savemask, NULL);
|
||||
execv("bin/redbean.com",
|
||||
(char *const[]){"bin/redbean.com", "-szp0", "-l127.0.0.1", 0});
|
||||
_exit(127);
|
||||
}
|
||||
EXPECT_NE(-1, close(pipefds[1]));
|
||||
EXPECT_NE(-1, read(pipefds[0], portbuf, sizeof(portbuf)));
|
||||
port = atoi(portbuf);
|
||||
EXPECT_TRUE(Matches("HTTP/1\\.1 200 OK\r\n"
|
||||
"Accept: \\*/\\*\r\n"
|
||||
"Accept-Charset: utf-8,ISO-8859-1;q=0\\.7,\\*;q=0\\.5\r\n"
|
||||
"Allow: GET, HEAD, POST, PUT, DELETE, OPTIONS\r\n"
|
||||
"Date: .*\r\n"
|
||||
"Server: redbean/.*\r\n"
|
||||
"Content-Length: 0\r\n"
|
||||
"\r\n"
|
||||
"HTTP/1\\.1 200 OK\r\n"
|
||||
"Accept: \\*/\\*\r\n"
|
||||
"Accept-Charset: utf-8,ISO-8859-1;q=0\\.7,\\*;q=0\\.5\r\n"
|
||||
"Allow: GET, HEAD, POST, PUT, DELETE, OPTIONS\r\n"
|
||||
"Date: .*\r\n"
|
||||
"Server: redbean/.*\r\n"
|
||||
"Content-Length: 0\r\n"
|
||||
"\r\n",
|
||||
gc(SendHttpRequest("OPTIONS * HTTP/1.1\n\n"
|
||||
"OPTIONS * HTTP/1.1\n\n"))));
|
||||
EXPECT_NE(-1, kill(pid, SIGTERM));
|
||||
EXPECT_NE(-1, wait(0));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue