mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 05:42:29 +00:00
Do code cleanup use duff device linenoise i/o
This commit is contained in:
parent
6ff46ca373
commit
2f56ebfe78
79 changed files with 1393 additions and 1484 deletions
|
@ -46,6 +46,13 @@ TEST(open, eexist) {
|
|||
ASSERT_SYS(EEXIST, -1, open("exists", O_WRONLY | O_CREAT | O_EXCL));
|
||||
}
|
||||
|
||||
TEST(open, enametoolong) {
|
||||
size_t n = 260;
|
||||
char *s = gc(xcalloc(1, n + 1));
|
||||
memset(s, 'J', n);
|
||||
ASSERT_SYS(ENAMETOOLONG, -1, creat(s, 0644));
|
||||
}
|
||||
|
||||
TEST(open, testOpenExistingForWriteOnly_seeksToStart) {
|
||||
char buf[8] = {0};
|
||||
ASSERT_SYS(0, 0, xbarf("hello.txt", "hello", -1));
|
||||
|
|
|
@ -22,29 +22,29 @@
|
|||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(int64toarray_radix10, test) {
|
||||
TEST(FormatInt64, test) {
|
||||
char buf[21];
|
||||
EXPECT_EQ(1, int64toarray_radix10(0, buf));
|
||||
EXPECT_EQ(1, FormatInt64(buf, 0) - buf);
|
||||
EXPECT_STREQ("0", buf);
|
||||
EXPECT_EQ(1, int64toarray_radix10(1, buf));
|
||||
EXPECT_EQ(1, FormatInt64(buf, 1) - buf);
|
||||
EXPECT_STREQ("1", buf);
|
||||
EXPECT_EQ(2, int64toarray_radix10(-1, buf));
|
||||
EXPECT_EQ(2, FormatInt64(buf, -1) - buf);
|
||||
EXPECT_STREQ("-1", buf);
|
||||
EXPECT_EQ(19, int64toarray_radix10(INT64_MAX, buf));
|
||||
EXPECT_EQ(19, FormatInt64(buf, INT64_MAX) - buf);
|
||||
EXPECT_STREQ("9223372036854775807", buf);
|
||||
EXPECT_EQ(20, int64toarray_radix10(INT64_MIN, buf));
|
||||
EXPECT_EQ(20, FormatInt64(buf, INT64_MIN) - buf);
|
||||
EXPECT_STREQ("-9223372036854775808", buf);
|
||||
}
|
||||
|
||||
TEST(uint64toarray_radix10, test) {
|
||||
TEST(FormatUint64, test) {
|
||||
char buf[21];
|
||||
EXPECT_EQ(1, uint64toarray_radix10(0, buf));
|
||||
EXPECT_EQ(1, FormatUint64(buf, 0) - buf);
|
||||
EXPECT_STREQ("0", buf);
|
||||
EXPECT_EQ(4, uint64toarray_radix10(1024, buf));
|
||||
EXPECT_EQ(4, FormatUint64(buf, 1024) - buf);
|
||||
EXPECT_STREQ("1024", buf);
|
||||
EXPECT_EQ(20, uint64toarray_radix10(UINT64_MAX, buf));
|
||||
EXPECT_EQ(20, FormatUint64(buf, UINT64_MAX) - buf);
|
||||
EXPECT_STREQ("18446744073709551615", buf);
|
||||
EXPECT_EQ(19, uint64toarray_radix10(INT64_MIN, buf));
|
||||
EXPECT_EQ(19, FormatUint64(buf, INT64_MIN) - buf);
|
||||
EXPECT_STREQ("9223372036854775808", buf);
|
||||
}
|
||||
|
||||
|
@ -70,5 +70,5 @@ TEST(uint128toarray_radix10, test) {
|
|||
|
||||
BENCH(itoa64radix10, bench) {
|
||||
char b[21];
|
||||
EZBENCH2("itoa64radix10", donothing, uint64toarray_radix10(UINT64_MAX, b));
|
||||
EZBENCH2("itoa64radix10", donothing, FormatUint64(b, UINT64_MAX));
|
||||
}
|
|
@ -76,8 +76,6 @@ TEST(FormatInt64Thousands, testNegative) {
|
|||
|
||||
BENCH(FormatInt64Thousands, bench) {
|
||||
char s[27];
|
||||
EZBENCH2("int64toarray_radix10(MAX)", donothing,
|
||||
int64toarray_radix10(INT64_MAX, s));
|
||||
EZBENCH2("FormatInt64Thousands(MAX)", donothing,
|
||||
FormatInt64Thousands(s, INT64_MAX));
|
||||
EZBENCH2("FormatInt64Thousands(MIN)", donothing,
|
||||
|
|
57
test/libc/fmt/formatoctal32_test.c
Normal file
57
test/libc/fmt/formatoctal32_test.c
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*-*- 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 2022 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/fmt/itoa.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
char buf[13];
|
||||
|
||||
void SetUp(void) {
|
||||
memset(buf, 0x55, sizeof(buf));
|
||||
}
|
||||
|
||||
TEST(FormatOctal32, test1) {
|
||||
EXPECT_EQ(1, FormatOctal32(buf, 0, true) - buf);
|
||||
EXPECT_STREQ("0", buf);
|
||||
}
|
||||
|
||||
TEST(FormatOctal32, test2) {
|
||||
EXPECT_EQ(1, FormatOctal32(buf, 0, false) - buf);
|
||||
EXPECT_STREQ("0", buf);
|
||||
}
|
||||
|
||||
TEST(FormatOctal32, test3) {
|
||||
EXPECT_EQ(2, FormatOctal32(buf, 1, true) - buf);
|
||||
EXPECT_STREQ("01", buf);
|
||||
}
|
||||
|
||||
TEST(FormatOctal32, test4) {
|
||||
EXPECT_EQ(1, FormatOctal32(buf, 1, false) - buf);
|
||||
EXPECT_STREQ("1", buf);
|
||||
}
|
||||
|
||||
TEST(FormatOctal32, test5) {
|
||||
EXPECT_EQ(12, FormatOctal32(buf, 037777777777, true) - buf);
|
||||
EXPECT_STREQ("037777777777", buf);
|
||||
}
|
||||
|
||||
TEST(FormatOctal32, test6) {
|
||||
EXPECT_EQ(11, FormatOctal32(buf, 037777777777, false) - buf);
|
||||
EXPECT_STREQ("37777777777", buf);
|
||||
}
|
66
test/libc/fmt/formatoctal64_test.c
Normal file
66
test/libc/fmt/formatoctal64_test.c
Normal file
|
@ -0,0 +1,66 @@
|
|||
/*-*- 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 2022 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/fmt/itoa.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
char buf[25];
|
||||
|
||||
void SetUp(void) {
|
||||
memset(buf, 0x55, sizeof(buf));
|
||||
}
|
||||
|
||||
TEST(FormatOctal64, test1) {
|
||||
EXPECT_EQ(1, FormatOctal64(buf, 0, true) - buf);
|
||||
EXPECT_STREQ("0", buf);
|
||||
}
|
||||
|
||||
TEST(FormatOctal64, test2) {
|
||||
EXPECT_EQ(1, FormatOctal64(buf, 0, false) - buf);
|
||||
EXPECT_STREQ("0", buf);
|
||||
}
|
||||
|
||||
TEST(FormatOctal64, test3) {
|
||||
EXPECT_EQ(2, FormatOctal64(buf, 1, true) - buf);
|
||||
EXPECT_STREQ("01", buf);
|
||||
}
|
||||
|
||||
TEST(FormatOctal64, test4) {
|
||||
EXPECT_EQ(1, FormatOctal64(buf, 1, false) - buf);
|
||||
EXPECT_STREQ("1", buf);
|
||||
}
|
||||
|
||||
TEST(FormatOctal64, test5) {
|
||||
EXPECT_EQ(23, FormatOctal64(buf, 01777777777777777777777UL, true) - buf);
|
||||
EXPECT_STREQ("01777777777777777777777", buf);
|
||||
}
|
||||
|
||||
TEST(FormatOctal64, test6) {
|
||||
EXPECT_EQ(22, FormatOctal64(buf, 01777777777777777777777UL, false) - buf);
|
||||
EXPECT_STREQ("1777777777777777777777", buf);
|
||||
}
|
||||
|
||||
BENCH(FormatOctal64, bench) {
|
||||
EZBENCH2("FormatUint64", donothing,
|
||||
FormatUint64(buf, 01777777777777777777777UL));
|
||||
EZBENCH2("FormatOctal64", donothing,
|
||||
FormatOctal64(buf, 01777777777777777777777UL, true));
|
||||
EZBENCH2("FormatOctal32", donothing, FormatOctal32(buf, 037777777777U, true));
|
||||
}
|
|
@ -641,6 +641,7 @@ BENCH(palandprintf, bench) {
|
|||
EZBENCH2("%g M_PI", donothing, Format("%g", VEIL("x", M_PI)));
|
||||
EZBENCH2("%a M_PI", donothing, Format("%a", VEIL("x", M_PI)));
|
||||
EZBENCH2("%e M_PI", donothing, Format("%e", VEIL("x", M_PI)));
|
||||
EZBENCH2("ULONG_MAX %lo", donothing, Format("%lo", VEIL("r", ULONG_MAX)));
|
||||
EZBENCH2("INT_MIN %x", donothing, Format("%x", VEIL("r", INT_MIN)));
|
||||
EZBENCH2("INT_MIN %d", donothing, Format("%d", VEIL("r", INT_MIN)));
|
||||
EZBENCH2("INT_MIN %,d", donothing, Format("%,d", VEIL("r", INT_MIN)));
|
||||
|
@ -649,7 +650,6 @@ BENCH(palandprintf, bench) {
|
|||
EZBENCH2("LONG_MIN %ld", donothing, Format("%ld", VEIL("r", LONG_MIN)));
|
||||
EZBENCH2("INT128_MIN %jjd", donothing, Format("%jjd", INT128_MIN));
|
||||
EZBENCH2("INT128_MIN %jjx", donothing, Format("%jjx", INT128_MIN));
|
||||
EZBENCH2("int64toarray 23", donothing, int64toarray_radix10(23, buffer));
|
||||
EZBENCH2("int64toarray min", donothing,
|
||||
int64toarray_radix10(INT_MIN, buffer));
|
||||
EZBENCH2("int64toarray 23", donothing, FormatInt64(buffer, 23));
|
||||
EZBENCH2("int64toarray min", donothing, FormatInt64(buffer, INT_MIN));
|
||||
}
|
||||
|
|
|
@ -43,7 +43,8 @@
|
|||
*/
|
||||
static uint64_t Rando(void) {
|
||||
uint64_t x;
|
||||
do x = lemur64();
|
||||
do
|
||||
x = lemur64();
|
||||
while (((x ^ READ64LE("!!!!!!!!")) - 0x0101010101010101) &
|
||||
~(x ^ READ64LE("!!!!!!!!")) & 0x8080808080808080);
|
||||
return x;
|
||||
|
@ -375,6 +376,8 @@ BENCH(printf, bench) {
|
|||
kusnprintf(b, 128, "%hs\n", u"𐌰𐌱𐌲𐌳𐌴𐌵𐌶𐌷"));
|
||||
EZBENCH2("snprintf astral", donothing,
|
||||
snprintf_(b, 128, "%hs\n", u"𐌰𐌱𐌲𐌳𐌴𐌵𐌶𐌷"));
|
||||
EZBENCH2("kusnprintf octal", donothing,
|
||||
kusnprintf(b, 128, "%#lo", ULONG_MAX));
|
||||
EZBENCH2("kusnprintf long", donothing, kusnprintf(b, 128, "%ld", LONG_MAX));
|
||||
EZBENCH2("snprintf long", donothing, snprintf_(b, 128, "%ld", LONG_MAX));
|
||||
EZBENCH2("kusnprintf thou", donothing, kusnprintf(b, 128, "%'ld", LONG_MAX));
|
||||
|
|
|
@ -33,6 +33,14 @@ STATIC_YOINK("usr/share/zoneinfo/New_York");
|
|||
|
||||
char testlib_enable_tmp_setup_teardown;
|
||||
|
||||
DIR *dir;
|
||||
struct dirent *ent;
|
||||
|
||||
void SetUp(void) {
|
||||
dir = 0;
|
||||
ent = 0;
|
||||
}
|
||||
|
||||
TEST(opendir, efault) {
|
||||
ASSERT_SYS(EFAULT, NULL, opendir(0));
|
||||
if (!IsAsan()) return; // not possible
|
||||
|
@ -50,10 +58,8 @@ TEST(opendir, enotdir) {
|
|||
}
|
||||
|
||||
TEST(dirstream, testDots) {
|
||||
DIR *dir;
|
||||
int hasdot = 0;
|
||||
int hasdotdot = 0;
|
||||
struct dirent *ent;
|
||||
ASSERT_SYS(0, 0, close(creat("foo", 0644)));
|
||||
ASSERT_NE(NULL, (dir = opendir(".")));
|
||||
while ((ent = readdir(dir))) {
|
||||
|
@ -72,8 +78,6 @@ TEST(dirstream, testDots) {
|
|||
}
|
||||
|
||||
TEST(dirstream, test) {
|
||||
DIR *dir;
|
||||
struct dirent *ent;
|
||||
bool hasfoo = false;
|
||||
bool hasbar = false;
|
||||
char *dpath, *file1, *file2;
|
||||
|
@ -104,21 +108,17 @@ TEST(dirstream, test) {
|
|||
|
||||
TEST(dirstream, zipTest) {
|
||||
bool foundNewYork = false;
|
||||
DIR *d;
|
||||
struct dirent *e;
|
||||
const char *path = "/zip/usr/share/zoneinfo/";
|
||||
ASSERT_NE(0, _gc(xiso8601ts(NULL)));
|
||||
ASSERT_NE(NULL, (d = opendir(path)));
|
||||
while ((e = readdir(d))) {
|
||||
foundNewYork |= !strcmp(e->d_name, "New_York");
|
||||
ASSERT_NE(NULL, (dir = opendir(path)));
|
||||
while ((ent = readdir(dir))) {
|
||||
foundNewYork |= !strcmp(ent->d_name, "New_York");
|
||||
}
|
||||
closedir(d);
|
||||
closedir(dir);
|
||||
EXPECT_TRUE(foundNewYork);
|
||||
}
|
||||
|
||||
TEST(rewinddir, test) {
|
||||
DIR *dir;
|
||||
struct dirent *ent;
|
||||
bool hasfoo = false;
|
||||
bool hasbar = false;
|
||||
char *dpath, *file1, *file2;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue