mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-22 21:32:31 +00:00
Add minor improvements and cleanup
This commit is contained in:
parent
9e3e985ae5
commit
feed0d2b0e
163 changed files with 2286 additions and 2245 deletions
|
@ -29,7 +29,6 @@
|
|||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/conv/itoa.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/escape/escape.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/math.h"
|
||||
|
|
|
@ -73,4 +73,5 @@ TEST(malloc, test) {
|
|||
for (i = 0; i < ARRAYLEN(A); ++i) free(A[i]);
|
||||
for (i = 0; i < ARRAYLEN(maps); ++i) munmap(maps[i], mapsizes[i]);
|
||||
for (i = 0; i < ARRAYLEN(fds); ++i) close(fds[i]);
|
||||
malloc_trim(0);
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/escape/escape.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(cescapec, test) {
|
||||
|
|
|
@ -37,8 +37,8 @@ TEST(strclen, testAegeanNumberSupplementaryPlane) {
|
|||
EXPECT_EQ(18, strlen16(u"𐄷𐄸𐄹𐄺𐄻𐄼𐄽𐄾𐄿"));
|
||||
EXPECT_EQ(9, wcslen(L"𐄷𐄸𐄹𐄺𐄻𐄼𐄽𐄾𐄿"));
|
||||
EXPECT_EQ(9, strclen("𐄷𐄸𐄹𐄺𐄻𐄼𐄽𐄾𐄿"));
|
||||
EXPECT_EQ(9, strclen(u"𐄷𐄸𐄹𐄺𐄻𐄼𐄽𐄾𐄿"));
|
||||
EXPECT_EQ(9, strclen(L"𐄷𐄸𐄹𐄺𐄻𐄼𐄽𐄾𐄿"));
|
||||
EXPECT_EQ(9, strclen16(u"𐄷𐄸𐄹𐄺𐄻𐄼𐄽𐄾𐄿"));
|
||||
EXPECT_EQ(9, wcslen(L"𐄷𐄸𐄹𐄺𐄻𐄼𐄽𐄾𐄿"));
|
||||
}
|
||||
|
||||
TEST(strlen16, testCoolKidNulTerminator) {
|
||||
|
|
41
test/libc/str/strcpy_test.c
Normal file
41
test/libc/str/strcpy_test.c
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*-*- 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 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(strcpy, test) {
|
||||
char buf[64];
|
||||
EXPECT_STREQ("hello", strcpy(buf, "hello"));
|
||||
EXPECT_STREQ("hello there what's up", strcpy(buf, "hello there what's up"));
|
||||
}
|
||||
|
||||
BENCH(strcpy, bench) {
|
||||
extern char *strcpy_(char *, const char *) asm("strcpy");
|
||||
static char buf[1024], buf2[1024];
|
||||
memset(buf2, -1, sizeof(buf2) - 1);
|
||||
EZBENCH2("strcpy 1", donothing, strcpy_(buf, ""));
|
||||
EZBENCH2("strcpy 2", donothing, strcpy_(buf, "1"));
|
||||
EZBENCH2("strcpy 7", donothing, strcpy_(buf, "123456"));
|
||||
EZBENCH2("strcpy 8", donothing, strcpy_(buf, "1234567"));
|
||||
EZBENCH2("strcpy 9", donothing, strcpy_(buf, "12345678"));
|
||||
EZBENCH2("strcpy 16", donothing, strcpy_(buf, "123456781234567"));
|
||||
EZBENCH2("strcpy 1023", donothing, strcpy_(buf, buf2));
|
||||
}
|
|
@ -21,6 +21,7 @@
|
|||
#include "libc/macros.h"
|
||||
#include "libc/nexgen32e/tinystrlen.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
char u8[] = "utf-8 ☻";
|
||||
|
@ -129,3 +130,16 @@ TEST(tinystrnlen16, test) {
|
|||
EXPECT_EQ(2, tinystrnlen16(u"123", 2));
|
||||
EXPECT_EQ(3, tinystrnlen16(u"123", 4));
|
||||
}
|
||||
|
||||
BENCH(strlen, bench) {
|
||||
extern size_t strlen_(const char *) asm("strlen");
|
||||
static char b[1024];
|
||||
memset(b, -1, sizeof(b) - 1);
|
||||
EZBENCH2("strlen 1", donothing, strlen_(""));
|
||||
EZBENCH2("strlen 2", donothing, strlen_("1"));
|
||||
EZBENCH2("strlen 7", donothing, strlen_("123456"));
|
||||
EZBENCH2("strlen 8", donothing, strlen_("1234567"));
|
||||
EZBENCH2("strlen 9", donothing, strlen_("12345678"));
|
||||
EZBENCH2("strlen 16", donothing, strlen_("123456781234567"));
|
||||
EZBENCH2("strlen 1023", donothing, strlen_(b));
|
||||
}
|
||||
|
|
|
@ -17,27 +17,11 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/hyperion.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/unicode/unicode.h"
|
||||
|
||||
#if 0
|
||||
void *isnotplaintext(const void *, size_t)
|
||||
__attribute__((__pure__, __leaf__, __nothrow__));
|
||||
#endif
|
||||
|
||||
TEST(isnotplaintext, test) {
|
||||
EXPECT_EQ(NULL, isnotplaintext(kHyperion, kHyperionSize));
|
||||
EXPECT_STREQ("", isnotplaintext(kHyperion, kHyperionSize + 1));
|
||||
}
|
||||
|
||||
char *doit(char *data, size_t size) {
|
||||
data = isnotplaintext(data, size);
|
||||
asm volatile("" : "+r"(data));
|
||||
return data;
|
||||
}
|
||||
|
||||
BENCH(isnotplaintext, bench) {
|
||||
EZBENCH(donothing, doit(kHyperion, kHyperionSize));
|
||||
TEST(strwidth, test) {
|
||||
EXPECT_EQ(5, strwidth("hello"));
|
||||
EXPECT_EQ(5, strwidth("\1he\e[0;0mllo\e#8"));
|
||||
EXPECT_EQ(10, strwidth("HELLO"));
|
||||
}
|
|
@ -62,10 +62,6 @@ TEST(wcwidth, testCjkWidesAndCombiningLowLines_widthIsNotLength) {
|
|||
/*────────────────────────────────────────────────────┴─*/
|
||||
}
|
||||
|
||||
TEST(strwidth, tab) {
|
||||
EXPECT_EQ(32, strwidth("mov 0x0(%rip),%rcx \t"));
|
||||
}
|
||||
|
||||
TEST(wcwidth, block) {
|
||||
EXPECT_EQ(1, wcwidth(u'▄'));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue