mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 05:42:29 +00:00
Improve backwards compatibility with GNU Make
This commit is contained in:
parent
fabf7f9f02
commit
1f2288be6e
18 changed files with 412 additions and 96 deletions
|
@ -19,34 +19,101 @@
|
|||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
#define T(NAME) NAME
|
||||
#define S(S) S
|
||||
#define C(C) C
|
||||
#include "test/libc/str/strrchr_test.inc"
|
||||
#undef C
|
||||
#undef S
|
||||
#undef T
|
||||
TEST(strrchr, test) {
|
||||
EXPECT_EQ(NULL, strrchr("hello", 'z'));
|
||||
EXPECT_STREQ("lo", strrchr("hello", 'l'));
|
||||
EXPECT_STREQ("llo", strchr("hello", 'l'));
|
||||
EXPECT_STREQ("hello", strrchr("hello", 'h'));
|
||||
EXPECT_STREQ("ello", strrchr("hello", 'e'));
|
||||
EXPECT_STREQ("o", strrchr("hello", 'o'));
|
||||
}
|
||||
|
||||
#define T(NAME) NAME##16
|
||||
#define S(S) u##S
|
||||
#define C(C) u##C
|
||||
#define strrchr(x, y) strrchr16(x, y)
|
||||
#define strchr(x, y) strchr16(x, y)
|
||||
#include "test/libc/str/strrchr_test.inc"
|
||||
#undef strchr
|
||||
#undef strrchr
|
||||
#undef C
|
||||
#undef S
|
||||
#undef T
|
||||
TEST(strrchr, simdVectorStuffIsntBroken) {
|
||||
EXPECT_EQ(NULL, strrchr("--------------------------------", 'x'));
|
||||
EXPECT_STREQ("x", strrchr("-------------------------------x", 'x'));
|
||||
EXPECT_STREQ("x-------------------------------",
|
||||
strrchr("x-------------------------------", 'x'));
|
||||
EXPECT_STREQ("x"
|
||||
"z-------------------------------",
|
||||
strrchr("x"
|
||||
"z-------------------------------",
|
||||
'x'));
|
||||
EXPECT_STREQ("x-------------------------------"
|
||||
"y-------------------------------",
|
||||
strrchr("x-------------------------------"
|
||||
"y-------------------------------",
|
||||
'x'));
|
||||
EXPECT_STREQ("x"
|
||||
"z-------------------------------"
|
||||
"y-------------------------------",
|
||||
strrchr("x"
|
||||
"z-------------------------------"
|
||||
"y-------------------------------",
|
||||
'x'));
|
||||
}
|
||||
|
||||
#define T(NAME) NAME##32
|
||||
#define S(S) L##S
|
||||
#define C(C) L##C
|
||||
#define strchr(x, y) wcschr(x, y)
|
||||
#define strrchr(x, y) wcsrchr(x, y)
|
||||
#include "test/libc/str/strrchr_test.inc"
|
||||
#undef strchr
|
||||
#undef strrchr
|
||||
#undef C
|
||||
#undef S
|
||||
#undef T
|
||||
TEST(strrchr16, test) {
|
||||
EXPECT_EQ(NULL, strrchr16(u"hello", 'z'));
|
||||
EXPECT_STREQ(u"lo", strrchr16(u"hello", 'l'));
|
||||
EXPECT_STREQ(u"llo", strchr16(u"hello", 'l'));
|
||||
EXPECT_STREQ(u"hello", strrchr16(u"hello", 'h'));
|
||||
EXPECT_STREQ(u"ello", strrchr16(u"hello", 'e'));
|
||||
EXPECT_STREQ(u"o", strrchr16(u"hello", 'o'));
|
||||
}
|
||||
|
||||
TEST(strrchr16, simdVectorStuffIsntBroken) {
|
||||
EXPECT_EQ(NULL, strrchr16(u"--------------------------------", 'x'));
|
||||
EXPECT_STREQ(u"x", strrchr16(u"-------------------------------x", 'x'));
|
||||
EXPECT_STREQ(u"x-------------------------------",
|
||||
strrchr16(u"x-------------------------------", 'x'));
|
||||
EXPECT_STREQ(u"x"
|
||||
u"z-------------------------------",
|
||||
strrchr16(u"x"
|
||||
u"z-------------------------------",
|
||||
'x'));
|
||||
EXPECT_STREQ(u"x-------------------------------"
|
||||
u"y-------------------------------",
|
||||
strrchr16(u"x-------------------------------"
|
||||
u"y-------------------------------",
|
||||
'x'));
|
||||
EXPECT_STREQ(u"x"
|
||||
u"z-------------------------------"
|
||||
u"y-------------------------------",
|
||||
strrchr16(u"x"
|
||||
u"z-------------------------------"
|
||||
u"y-------------------------------",
|
||||
'x'));
|
||||
}
|
||||
|
||||
TEST(wcsrchr, test) {
|
||||
EXPECT_EQ(NULL, wcsrchr(L"hello", 'z'));
|
||||
EXPECT_STREQ(L"lo", wcsrchr(L"hello", 'l'));
|
||||
EXPECT_STREQ(L"llo", wcschr(L"hello", 'l'));
|
||||
EXPECT_STREQ(L"hello", wcsrchr(L"hello", 'h'));
|
||||
EXPECT_STREQ(L"ello", wcsrchr(L"hello", 'e'));
|
||||
EXPECT_STREQ(L"o", wcsrchr(L"hello", 'o'));
|
||||
}
|
||||
|
||||
TEST(wcsrchr, simdVectorStuffIsntBroken) {
|
||||
EXPECT_EQ(NULL, wcsrchr(L"--------------------------------", 'x'));
|
||||
EXPECT_STREQ(L"x", wcsrchr(L"-------------------------------x", 'x'));
|
||||
EXPECT_STREQ(L"x-------------------------------",
|
||||
wcsrchr(L"x-------------------------------", 'x'));
|
||||
EXPECT_STREQ(L"x"
|
||||
L"z-------------------------------",
|
||||
wcsrchr(L"x"
|
||||
L"z-------------------------------",
|
||||
'x'));
|
||||
EXPECT_STREQ(L"x-------------------------------"
|
||||
L"y-------------------------------",
|
||||
wcsrchr(L"x-------------------------------"
|
||||
L"y-------------------------------",
|
||||
'x'));
|
||||
EXPECT_STREQ(L"x"
|
||||
L"z-------------------------------"
|
||||
L"y-------------------------------",
|
||||
wcsrchr(L"x"
|
||||
L"z-------------------------------"
|
||||
L"y-------------------------------",
|
||||
'x'));
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include "libc/nexgen32e/x86feature.h"
|
||||
#include "libc/runtime/gc.internal.h"
|
||||
#include "libc/str/internal.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/hyperion.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
#define MAKESTRING(NAME, VALUE) \
|
||||
|
@ -75,3 +77,11 @@ TEST(strstr, test) {
|
|||
ASSERT_EQ(NULL, strstr("-Wl,--gc-sections", "sanitize"));
|
||||
ASSERT_STREQ("x", strstr("x", "x"));
|
||||
}
|
||||
|
||||
BENCH(strstr, bench) {
|
||||
EZBENCH2("strstr", donothing, EXPROPRIATE(strstr(kHyperion, "THE END")));
|
||||
EZBENCH2("strstr", donothing,
|
||||
EXPROPRIATE(strstr(
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab",
|
||||
"aaaaaab")));
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*-*- 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 │
|
||||
│ 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 │
|
||||
|
@ -16,31 +16,27 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/hyperion.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
TEST(T(strrchr), test) {
|
||||
EXPECT_EQ(NULL, strrchr(S("hello"), C('z')));
|
||||
EXPECT_STREQ(S("lo"), strrchr(S("hello"), C('l')));
|
||||
EXPECT_STREQ(S("llo"), strchr(S("hello"), C('l')));
|
||||
EXPECT_STREQ(S("hello"), strrchr(S("hello"), C('h')));
|
||||
EXPECT_STREQ(S("ello"), strrchr(S("hello"), C('e')));
|
||||
EXPECT_STREQ(S("o"), strrchr(S("hello"), C('o')));
|
||||
TEST(utf16toutf8, test) {
|
||||
EXPECT_STREQ("hello☻♥", gc(utf16toutf8(u"hello☻♥", -1, 0)));
|
||||
EXPECT_STREQ("hello☻♥hello☻♥h", gc(utf16toutf8(u"hello☻♥hello☻♥h", -1, 0)));
|
||||
EXPECT_STREQ("hello☻♥hello☻♥hi", gc(utf16toutf8(u"hello☻♥hello☻♥hi", -1, 0)));
|
||||
EXPECT_STREQ("hello☻♥hello☻♥hello☻♥hello☻♥hello☻♥",
|
||||
gc(utf16toutf8(u"hello☻♥hello☻♥hello☻♥hello☻♥hello☻♥", -1, 0)));
|
||||
EXPECT_STREQ("hello--hello--h", gc(utf16toutf8(u"hello--hello--h", -1, 0)));
|
||||
EXPECT_STREQ("hello--hello--hi", gc(utf16toutf8(u"hello--hello--hi", -1, 0)));
|
||||
EXPECT_STREQ("hello--hello--hello--hello--hello--",
|
||||
gc(utf16toutf8(u"hello--hello--hello--hello--hello--", -1, 0)));
|
||||
}
|
||||
|
||||
TEST(T(strrchr), simdVectorStuffIsntBroken) {
|
||||
EXPECT_EQ(NULL, strrchr(S("--------------------------------"), C('x')));
|
||||
EXPECT_STREQ(S("x"), strrchr(S("-------------------------------x"), C('x')));
|
||||
EXPECT_STREQ(S("x-------------------------------"),
|
||||
strrchr(S("x-------------------------------"), C('x')));
|
||||
EXPECT_STREQ(S("x") S("z-------------------------------"),
|
||||
strrchr(S("x") S("z-------------------------------"), C('x')));
|
||||
EXPECT_STREQ(S("x-------------------------------")
|
||||
S("y-------------------------------"),
|
||||
strrchr(S("x-------------------------------")
|
||||
S("y-------------------------------"),
|
||||
C('x')));
|
||||
EXPECT_STREQ(S("x") S("z-------------------------------")
|
||||
S("y-------------------------------"),
|
||||
strrchr(S("x") S("z-------------------------------")
|
||||
S("y-------------------------------"),
|
||||
C('x')));
|
||||
BENCH(utf16toutf8, bench) {
|
||||
size_t n;
|
||||
char16_t *h;
|
||||
h = utf8toutf16(kHyperion, kHyperionSize, &n);
|
||||
EZBENCH2("utf16toutf8", donothing, free(utf16toutf8(h, n, 0)));
|
||||
}
|
40
test/libc/x/utf8toutf16_test.c
Normal file
40
test/libc/x/utf8toutf16_test.c
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*-*- 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/mem/mem.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/hyperion.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
TEST(utf8toutf16, test) {
|
||||
EXPECT_STREQ(u"hello☻♥", gc(utf8toutf16("hello☻♥", -1, 0)));
|
||||
EXPECT_STREQ(u"hello☻♥hello☻♥h", gc(utf8toutf16("hello☻♥hello☻♥h", -1, 0)));
|
||||
EXPECT_STREQ(u"hello☻♥hello☻♥hi", gc(utf8toutf16("hello☻♥hello☻♥hi", -1, 0)));
|
||||
EXPECT_STREQ(u"hello☻♥hello☻♥hello☻♥hello☻♥hello☻♥",
|
||||
gc(utf8toutf16("hello☻♥hello☻♥hello☻♥hello☻♥hello☻♥", -1, 0)));
|
||||
EXPECT_STREQ(u"hello--hello--h", gc(utf8toutf16("hello--hello--h", -1, 0)));
|
||||
EXPECT_STREQ(u"hello--hello--hi", gc(utf8toutf16("hello--hello--hi", -1, 0)));
|
||||
EXPECT_STREQ(u"hello--hello--hello--hello--hello--",
|
||||
gc(utf8toutf16("hello--hello--hello--hello--hello--", -1, 0)));
|
||||
}
|
||||
|
||||
BENCH(utf8toutf16, bench) {
|
||||
EZBENCH2("utf8toutf16", donothing,
|
||||
free(utf8toutf16(kHyperion, kHyperionSize, 0)));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue