mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-30 01:02:29 +00:00
Get more Python tests passing (#141)
This commit is contained in:
parent
916f19eea1
commit
59e1c245d1
141 changed files with 3536 additions and 1203 deletions
|
@ -22,6 +22,8 @@
|
|||
|
||||
TEST(strcasecmp, test) {
|
||||
EXPECT_EQ(0, strcasecmp("HELLO", "hello"));
|
||||
EXPECT_EQ(0, strcasecmp("HELLOHELLOHELLOHELLOHELLOHELLO",
|
||||
"hellohellohellohellohellohello"));
|
||||
EXPECT_EQ(-17, strcasecmp("HELLO", "yello"));
|
||||
EXPECT_EQ(-17, strcasecmp("HELLO", "YELLO"));
|
||||
EXPECT_EQ(+17, strcasecmp("yello", "HELLO"));
|
||||
|
@ -29,7 +31,10 @@ TEST(strcasecmp, test) {
|
|||
}
|
||||
|
||||
BENCH(strcasecmp, bench) {
|
||||
EZBENCH2("strcasecmp 16 eq", donothing,
|
||||
EZBENCH2("strcasecmp 16 eq (same)", donothing,
|
||||
EXPROPRIATE(
|
||||
strcasecmp(VEIL("r", "abcdefghijklmnop"), "abcdefghijklmnop")));
|
||||
EZBENCH2("strcasecmp 16 eq (evil)", donothing,
|
||||
EXPROPRIATE(
|
||||
strcasecmp(VEIL("r", "abcdefghijklmnop"), "ABCDEFGHIJKLMNOP")));
|
||||
}
|
||||
|
|
62
test/libc/str/strcat_test.c
Normal file
62
test/libc/str/strcat_test.c
Normal file
|
@ -0,0 +1,62 @@
|
|||
/*-*- 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/str/str.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(strcat, test) {
|
||||
char buf[128];
|
||||
EXPECT_STREQ("hello", strcpy(buf, "hello"));
|
||||
EXPECT_STREQ("hellothere", strcat(buf, "there"));
|
||||
EXPECT_STREQ("hellothere", buf);
|
||||
}
|
||||
|
||||
TEST(strcat16, test) {
|
||||
char16_t buf[128];
|
||||
EXPECT_STREQ(u"hello", strcpy16(buf, u"hello"));
|
||||
EXPECT_STREQ(u"hellothere", strcat16(buf, u"there"));
|
||||
EXPECT_STREQ(u"hellothere", buf);
|
||||
}
|
||||
|
||||
TEST(wcscat, test) {
|
||||
wchar_t buf[128];
|
||||
EXPECT_STREQ(L"hello", wcscpy(buf, L"hello"));
|
||||
EXPECT_STREQ(L"hellothere", wcscat(buf, L"there"));
|
||||
EXPECT_STREQ(L"hellothere", buf);
|
||||
}
|
||||
|
||||
TEST(strncat, test) {
|
||||
char buf[128];
|
||||
EXPECT_STREQ("hello", strcpy(buf, "hello"));
|
||||
EXPECT_STREQ("hellothe", strncat(buf, "there", 3));
|
||||
EXPECT_STREQ("hellothe", buf);
|
||||
}
|
||||
|
||||
TEST(strncat16, test) {
|
||||
char16_t buf[128];
|
||||
EXPECT_STREQ(u"hello", strcpy16(buf, u"hello"));
|
||||
EXPECT_STREQ(u"hellothe", strncat16(buf, u"there", 3));
|
||||
EXPECT_STREQ(u"hellothe", buf);
|
||||
}
|
||||
|
||||
TEST(wcsncat, test) {
|
||||
wchar_t buf[128];
|
||||
EXPECT_STREQ(L"hello", wcscpy(buf, L"hello"));
|
||||
EXPECT_STREQ(L"hellothe", wcsncat(buf, L"there", 3));
|
||||
EXPECT_STREQ(L"hellothe", buf);
|
||||
}
|
|
@ -67,6 +67,15 @@ TEST(wcscasecmp, emptyString) {
|
|||
EXPECT_NE(0, wcscasecmp(L"", L"a"));
|
||||
}
|
||||
|
||||
TEST(strncmp, nullString) {
|
||||
char *s1 = malloc(0);
|
||||
char *s2 = malloc(0);
|
||||
ASSERT_NE(s1, s2);
|
||||
ASSERT_EQ(0, strncmp(s1, s2, 0));
|
||||
free(s2);
|
||||
free(s1);
|
||||
}
|
||||
|
||||
TEST(strncmp, emptyString) {
|
||||
char *s1 = strcpy(malloc(1), "");
|
||||
char *s2 = strcpy(malloc(1), "");
|
||||
|
@ -537,44 +546,37 @@ BENCH(bench_00_strcmp, bench) {
|
|||
data = gc(malloc(size));
|
||||
dupe = gc(malloc(size));
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
EZBENCH2("strcmp [identity]", longstringislong(size, data),
|
||||
EXPROPRIATE(strcmp(VEIL("r", data), data)));
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
EZBENCH2("strcmp [2 diff]", donothing,
|
||||
EXPROPRIATE(strcmp(VEIL("r", "hi"), VEIL("r", "there"))));
|
||||
EZBENCH2("strcmp_pure [2 diff]", donothing,
|
||||
EXPROPRIATE(strcmp_pure(VEIL("r", "hi"), VEIL("r", "there"))));
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
EZBENCH2("strcmp [2 dupe]", randomize_buf2str_dupe(2, data, dupe),
|
||||
EXPROPRIATE(strcmp(VEIL("r", data), VEIL("r", dupe))));
|
||||
EZBENCH2("strcmp_pure [2 dupe]", randomize_buf2str_dupe(2, data, dupe),
|
||||
EXPROPRIATE(strcmp_pure(VEIL("r", data), VEIL("r", dupe))));
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
EZBENCH2("strcmp [4 dupe]", randomize_buf2str_dupe(4, data, dupe),
|
||||
EXPROPRIATE(strcmp(VEIL("r", data), VEIL("r", dupe))));
|
||||
EZBENCH2("strcmp_pure [4 dupe]", randomize_buf2str_dupe(4, data, dupe),
|
||||
EXPROPRIATE(strcmp_pure(VEIL("r", data), VEIL("r", dupe))));
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
EZBENCH2("strcmp [8 dupe]", randomize_buf2str_dupe(8, data, dupe),
|
||||
EXPROPRIATE(strcmp(VEIL("r", data), VEIL("r", dupe))));
|
||||
EZBENCH2("strcmp_pure [8 dupe]", randomize_buf2str_dupe(8, data, dupe),
|
||||
EXPROPRIATE(strcmp_pure(VEIL("r", data), VEIL("r", dupe))));
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
EZBENCH2("strcmp [short dupe]", randomize_buf2str_dupe(size, data, dupe),
|
||||
EZBENCH2("strcmp [sdupe]", randomize_buf2str_dupe(size, data, dupe),
|
||||
EXPROPRIATE(strcmp(VEIL("r", data), VEIL("r", dupe))));
|
||||
EZBENCH2("strcmp_pure [short dupe]", randomize_buf2str_dupe(size, data, dupe),
|
||||
EZBENCH2("strcmp_pure [sdupe]", randomize_buf2str_dupe(size, data, dupe),
|
||||
EXPROPRIATE(strcmp_pure(VEIL("r", data), VEIL("r", dupe))));
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
EZBENCH2("strcmp [long dupe]", longstringislong_dupe(size, data, dupe),
|
||||
EZBENCH2("strcmp [ldupe]", longstringislong_dupe(size, data, dupe),
|
||||
EXPROPRIATE(strcmp(VEIL("r", data), VEIL("r", dupe))));
|
||||
EZBENCH2("strcmp_pure [long dupe]", longstringislong_dupe(size, data, dupe),
|
||||
EZBENCH2("strcmp_pure [ldupe]", longstringislong_dupe(size, data, dupe),
|
||||
EXPROPRIATE(strcmp_pure(VEIL("r", data), VEIL("r", dupe))));
|
||||
}
|
||||
|
||||
|
@ -586,22 +588,17 @@ BENCH(bench_01_strcasecmp, bench) {
|
|||
data = gc(malloc(size));
|
||||
dupe = gc(malloc(size));
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
EZBENCH2("strcasecmp [identity]", longstringislong(size, data),
|
||||
EXPROPRIATE(strcasecmp(VEIL("r", data), data)));
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
EZBENCH2("strcasecmp [short dupe]", randomize_buf2str_dupe(size, data, dupe),
|
||||
EZBENCH2("strcasecmp [sdupe]", randomize_buf2str_dupe(size, data, dupe),
|
||||
EXPROPRIATE(strcasecmp(VEIL("r", data), VEIL("r", dupe))));
|
||||
EZBENCH2("strcasecmp_pure [short dupe]",
|
||||
randomize_buf2str_dupe(size, data, dupe),
|
||||
EZBENCH2("strcasecmp_pure [sdupe]", randomize_buf2str_dupe(size, data, dupe),
|
||||
EXPROPRIATE(strcasecmp_pure(VEIL("r", data), VEIL("r", dupe))));
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
EZBENCH2("strcasecmp [long dupe]", longstringislong_dupe(size, data, dupe),
|
||||
EZBENCH2("strcasecmp [ldupe]", longstringislong_dupe(size, data, dupe),
|
||||
EXPROPRIATE(strcasecmp(VEIL("r", data), VEIL("r", dupe))));
|
||||
EZBENCH2("strcasecmp_pure [long dupe]",
|
||||
longstringislong_dupe(size, data, dupe),
|
||||
EZBENCH2("strcasecmp_pure [ldupe]", longstringislong_dupe(size, data, dupe),
|
||||
EXPROPRIATE(strcasecmp_pure(VEIL("r", data), VEIL("r", dupe))));
|
||||
}
|
||||
|
||||
|
|
28
test/libc/str/wcsrchr_test.c
Normal file
28
test/libc/str/wcsrchr_test.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*-*- 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/str/str.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(wcsrchr, test) {
|
||||
EXPECT_STREQ(L"/there", wcsrchr(L"sup/hello/there", L'/'));
|
||||
EXPECT_STREQ(L"/there",
|
||||
wcsrchr(L"sup/hello/theresup/hello/theresup/hello/there", L'/'));
|
||||
EXPECT_STREQ(L"p/hello/there",
|
||||
wcsrchr(L"sup/hello/theresup/hello/theresup/hello/there", L'p'));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue