mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 13:52:28 +00:00
Apply some touchups
This commit is contained in:
parent
9f149e1de3
commit
2f3bd90216
139 changed files with 1188 additions and 1154 deletions
|
@ -17,6 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/sysv/consts/map.h"
|
||||
#include "libc/sysv/consts/msync.h"
|
||||
|
|
|
@ -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,51 +16,13 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/progn.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/str/tpencode.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
char buf[8];
|
||||
|
||||
TEST(tpencode, testNul) {
|
||||
ASSERT_BINEQ(u" ", PROGN(ASSERT_EQ(1, tpencode(buf, 8, 0, false)), buf));
|
||||
ASSERT_BINEQ(u" ", PROGN(ASSERT_EQ(1, (tpencode)(buf, 8, 0, false)), buf));
|
||||
}
|
||||
|
||||
TEST(tpencode, testSpace) {
|
||||
ASSERT_BINEQ(u" ", PROGN(ASSERT_EQ(1, tpencode(buf, 8, 0x20, false)), buf));
|
||||
ASSERT_BINEQ(u" ", PROGN(ASSERT_EQ(1, (tpencode)(buf, 8, 0x20, false)), buf));
|
||||
}
|
||||
|
||||
TEST(tpencode, testGlyph) {
|
||||
ASSERT_EQ(3, tpencode(buf, 8, u'→', false));
|
||||
ASSERT_BINEQ(u"→", buf);
|
||||
ASSERT_EQ(3, (tpencode)(buf, 8, u'→', false));
|
||||
ASSERT_BINEQ(u"→", buf);
|
||||
}
|
||||
|
||||
TEST(tpencode, testMathematicalNotMuhPolicyDrivenBehavior_negativeOne) {
|
||||
ASSERT_BINEQ(u"λ┐┐┐┐┐",
|
||||
PROGN(ASSERT_EQ(6, tpencode(buf, 8, -1, false)), buf));
|
||||
ASSERT_BINEQ(u"λ┐┐┐┐┐",
|
||||
PROGN(ASSERT_EQ(6, (tpencode)(buf, 8, -1, false)), buf));
|
||||
}
|
||||
|
||||
TEST(tpencode, testMathematicalNotMuhPolicyDrivenBehavior_twosComplementBane) {
|
||||
ASSERT_BINEQ(u"■ÇÇÇÇÇ",
|
||||
PROGN(ASSERT_EQ(6, tpencode(buf, 8, 0x80000000, false)), buf));
|
||||
ASSERT_BINEQ(u"■ÇÇÇÇÇ",
|
||||
PROGN(ASSERT_EQ(6, (tpencode)(buf, 8, 0x80000000, false)), buf));
|
||||
}
|
||||
|
||||
TEST(tpencode, testMathematicalNotMuhPolicyDrivenBehavior_nonCanonicalNul) {
|
||||
ASSERT_BINEQ(u"└Ç", PROGN(ASSERT_EQ(2, tpencode(buf, 8, 0, true)), buf));
|
||||
ASSERT_BINEQ(u"└Ç", PROGN(ASSERT_EQ(2, (tpencode)(buf, 8, 0, true)), buf));
|
||||
}
|
||||
|
||||
TEST(tpencode, testC1Csi) {
|
||||
ASSERT_BINEQ(u"›", PROGN(ASSERT_EQ(2, tpencode(buf, 8, 0x9B, false)), buf));
|
||||
TEST(getenv, test) {
|
||||
putenv("x=y");
|
||||
EXPECT_STREQ("y", getenv("x"));
|
||||
unsetenv("x");
|
||||
EXPECT_EQ(NULL, getenv("x"));
|
||||
}
|
|
@ -23,6 +23,8 @@
|
|||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(dirname, test) {
|
||||
EXPECT_STREQ("/usr/lib", dirname(gc(strdup("/usr/lib/foo.bar"))));
|
||||
EXPECT_STREQ("/usr", dirname(gc(strdup("/usr/lib"))));
|
||||
EXPECT_STREQ("/usr", dirname(gc(strdup("/usr/lib"))));
|
||||
EXPECT_STREQ("usr", dirname(gc(strdup("usr/lib"))));
|
||||
EXPECT_STREQ("/", dirname(gc(strdup("/usr/"))));
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
int main(int argc, char *argv[]) {
|
||||
int rc;
|
||||
char *s;
|
||||
FILE *f;
|
||||
s = strdup(argv[0]);
|
||||
f = fopen("/dev/null", "w");
|
||||
fprintf(f, "hello world %d\n", argc);
|
||||
fprintf(f, "hello world %d %s\n", argc, s);
|
||||
fclose(f);
|
||||
rc = system("exit 42");
|
||||
CHECK_NE(-1, rc);
|
||||
CHECK_EQ(42, WEXITSTATUS(rc));
|
||||
free(s);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ o/$(MODE)/test/libc/release/smoke.com.dbg: \
|
|||
o/$(MODE)/libc/crt/crt.o \
|
||||
o/$(MODE)/ape/ape.o \
|
||||
o/$(MODE)/cosmopolitan.a
|
||||
@ACTION=CC build/compile $(CC) \
|
||||
@ACTION=CC $(COMPILE) $(CC) \
|
||||
-o $@ \
|
||||
-Os \
|
||||
-static \
|
||||
|
@ -49,7 +49,7 @@ o/$(MODE)/test/libc/release/smokecxx.com.dbg: \
|
|||
o/$(MODE)/libc/crt/crt.o \
|
||||
o/$(MODE)/ape/ape.o \
|
||||
o/$(MODE)/cosmopolitan.a
|
||||
@ACTION=CXX build/compile $(CXX) \
|
||||
@ACTION=CXX $(COMPILE) $(CXX) \
|
||||
-o $@ \
|
||||
-Os \
|
||||
-static \
|
||||
|
@ -74,7 +74,7 @@ o/$(MODE)/test/libc/release/smokeansi.com.dbg: \
|
|||
o/$(MODE)/libc/crt/crt.o \
|
||||
o/$(MODE)/ape/ape.o \
|
||||
o/$(MODE)/cosmopolitan.a
|
||||
@ACTION=ANSI build/compile $(CC) \
|
||||
@ACTION=ANSI $(COMPILE) $(CC) \
|
||||
-o $@ \
|
||||
-Os \
|
||||
-ansi \
|
||||
|
@ -100,7 +100,7 @@ o/$(MODE)/test/libc/release/smokeclang.com.dbg: \
|
|||
o/$(MODE)/libc/crt/crt.o \
|
||||
o/$(MODE)/ape/ape.o \
|
||||
o/$(MODE)/cosmopolitan.a
|
||||
@ACTION=CLANG build/compile clang \
|
||||
@ACTION=CLANG $(COMPILE) clang \
|
||||
-o $@ \
|
||||
-Os \
|
||||
-static \
|
||||
|
@ -125,4 +125,6 @@ o/$(MODE)/test/libc/release: \
|
|||
o/$(MODE)/test/libc/release/smokecxx.com \
|
||||
o/$(MODE)/test/libc/release/smokecxx.com.runs \
|
||||
o/$(MODE)/test/libc/release/smokeansi.com \
|
||||
o/$(MODE)/test/libc/release/smokeansi.com.runs
|
||||
o/$(MODE)/test/libc/release/smokeansi.com.runs \
|
||||
o/$(MODE)/test/libc/release/smokeclang.com \
|
||||
o/$(MODE)/test/libc/release/smokeclang.com.runs
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/progn.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/sock/sock.h"
|
||||
#include "libc/sysv/consts/af.h"
|
||||
|
@ -25,8 +24,8 @@
|
|||
|
||||
TEST(inet_pton, testLocalhost) {
|
||||
uint32_t addr;
|
||||
EXPECT_EQ(htonl(INADDR_LOOPBACK),
|
||||
PROGN(ASSERT_EQ(1, inet_pton(AF_INET, "127.0.0.1", &addr)), addr));
|
||||
ASSERT_EQ(1, inet_pton(AF_INET, "127.0.0.1", &addr));
|
||||
EXPECT_EQ(htonl(INADDR_LOOPBACK), addr);
|
||||
}
|
||||
|
||||
TEST(inet_pton, testBadAddresses) {
|
||||
|
|
|
@ -172,12 +172,12 @@ void *MemCpy(void *, const void *, size_t);
|
|||
free(s); \
|
||||
} while (0)
|
||||
|
||||
#define BB(N) \
|
||||
do { \
|
||||
B(memmove_pure, N); \
|
||||
B(memcpy, N); \
|
||||
B(MemCpy, N); \
|
||||
fprintf(stderr, "\n"); \
|
||||
#define BB(N) \
|
||||
do { \
|
||||
B(memmove_pure, N); \
|
||||
B(memcpy, N); \
|
||||
B(MemCpy, N); \
|
||||
(fprintf)(stderr, "\n"); \
|
||||
} while (0)
|
||||
|
||||
BENCH(memcpy, bench) {
|
||||
|
|
|
@ -23,20 +23,15 @@
|
|||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
void *(*memmemi)(const void *, size_t, const void *, size_t) = memmem;
|
||||
FIXTURE(memmem, tiny) {
|
||||
memmemi = tinymemmem;
|
||||
}
|
||||
|
||||
#define MakeMemory(SL) memcpy(malloc(sizeof(SL) - 1), SL, sizeof(SL) - 1)
|
||||
|
||||
TEST(memmem, test) {
|
||||
char *needle = MakeMemory("abcdefgh");
|
||||
char *haystk = MakeMemory("acccccccbbbbbbbbabcdefghdddddddd");
|
||||
EXPECT_BINEQ(u"abcdefghdddddddd", memmemi(haystk, 32, needle, 8));
|
||||
EXPECT_BINEQ(u"abcdefghdddddddd", memmem(haystk, 32, needle, 8));
|
||||
memcpy(needle, "aaaaaaaa", 8);
|
||||
memcpy(haystk, "acccccccbbbbbbbbaaaaaaaadddddddd", 32);
|
||||
EXPECT_BINEQ(u"aaaaaaaadddddddd", memmemi(haystk, 32, needle, 8));
|
||||
EXPECT_BINEQ(u"aaaaaaaadddddddd", memmem(haystk, 32, needle, 8));
|
||||
free(haystk);
|
||||
free(needle);
|
||||
}
|
||||
|
@ -44,7 +39,7 @@ TEST(memmem, test) {
|
|||
TEST(memmem, testNoMatch) {
|
||||
char *needle = MakeMemory("abcdefzh");
|
||||
char *haystk = MakeMemory("acccccccbbbbbbbbabcdefghdddddddd");
|
||||
EXPECT_EQ(NULL, memmemi(haystk, 32, needle, 8));
|
||||
EXPECT_EQ(NULL, memmem(haystk, 32, needle, 8));
|
||||
free(haystk);
|
||||
free(needle);
|
||||
}
|
||||
|
@ -52,7 +47,7 @@ TEST(memmem, testNoMatch) {
|
|||
TEST(memmem, testStartOfMemory) {
|
||||
char *needle = MakeMemory("acccc");
|
||||
char *haystk = MakeMemory("acccccccbbbbbbbbabcdefghdddddddd");
|
||||
EXPECT_EQ(&haystk[0], memmemi(haystk, 32, needle, 5));
|
||||
EXPECT_EQ(&haystk[0], memmem(haystk, 32, needle, 5));
|
||||
free(haystk);
|
||||
free(needle);
|
||||
}
|
||||
|
@ -60,7 +55,7 @@ TEST(memmem, testStartOfMemory) {
|
|||
TEST(memmem, testEndOfMemory) {
|
||||
char *needle = MakeMemory("123");
|
||||
char *haystk = MakeMemory("abc123");
|
||||
EXPECT_EQ(&haystk[3], memmemi(haystk, 6, needle, 3));
|
||||
EXPECT_EQ(&haystk[3], memmem(haystk, 6, needle, 3));
|
||||
free(haystk);
|
||||
free(needle);
|
||||
}
|
||||
|
@ -68,7 +63,7 @@ TEST(memmem, testEndOfMemory) {
|
|||
TEST(memmem, testCrossesSseRegister) {
|
||||
char *needle = MakeMemory("eeeeeeeeeeeeefffffffffffff");
|
||||
char *haystk = MakeMemory("eeeeeeeeeeeeeeeeffffffffffffffffrrrrrrrrrrrrrrrr");
|
||||
EXPECT_EQ(&haystk[3], memmemi(haystk, 16 * 3, needle, 26));
|
||||
EXPECT_EQ(&haystk[3], memmem(haystk, 16 * 3, needle, 26));
|
||||
free(haystk);
|
||||
free(needle);
|
||||
}
|
||||
|
@ -77,7 +72,7 @@ TEST(memmem, testHasNulCharacters) {
|
|||
char *needle = MakeMemory("eeeeeeeeeeeee\0ffffffffffff");
|
||||
char *haystk =
|
||||
MakeMemory("eeeeeeeeeeeeeeee\0fffffffffffffffrrrrrrrrrrrrrrrr");
|
||||
EXPECT_EQ(&haystk[3], memmemi(haystk, 16 * 3, needle, 26));
|
||||
EXPECT_EQ(&haystk[3], memmem(haystk, 16 * 3, needle, 26));
|
||||
free(haystk);
|
||||
free(needle);
|
||||
}
|
||||
|
@ -85,7 +80,7 @@ TEST(memmem, testHasNulCharacters) {
|
|||
TEST(memmem, testWeird) {
|
||||
char *needle = MakeMemory("-*-+-+-+-+-+-+-+");
|
||||
char *haystk = MakeMemory("-+-+-+-+-+-+-+-*-+-+-+-+-+-+-+-+");
|
||||
EXPECT_EQ(14, (intptr_t)memmemi(haystk, 32, needle, 16) - (intptr_t)haystk);
|
||||
EXPECT_EQ(14, (intptr_t)memmem(haystk, 32, needle, 16) - (intptr_t)haystk);
|
||||
free(haystk);
|
||||
free(needle);
|
||||
}
|
||||
|
@ -93,7 +88,7 @@ TEST(memmem, testWeird) {
|
|||
TEST(memmem, testEmptyNeedle_matchesStartOfHaystack) {
|
||||
char *needle = malloc(0);
|
||||
char *haystk = MakeMemory("-+-+-+-+-+-+-+-*-+-+-+-+-+-+-+-+");
|
||||
EXPECT_EQ(0, (intptr_t)memmemi(haystk, 32, needle, 0) - (intptr_t)haystk);
|
||||
EXPECT_EQ(0, (intptr_t)memmem(haystk, 32, needle, 0) - (intptr_t)haystk);
|
||||
free(haystk);
|
||||
free(needle);
|
||||
}
|
||||
|
@ -101,8 +96,8 @@ TEST(memmem, testEmptyNeedle_matchesStartOfHaystack) {
|
|||
TEST(memmem, testEmptyHaystack_alwaysReturnsNull) {
|
||||
char *needle = MakeMemory("-*-+-+-+-+-+-+-+");
|
||||
char *haystk = malloc(0);
|
||||
EXPECT_EQ(NULL, memmemi(haystk, 0, needle, 16));
|
||||
EXPECT_EQ(NULL, memmemi(haystk, 0, needle, 1));
|
||||
EXPECT_EQ(NULL, memmem(haystk, 0, needle, 16));
|
||||
EXPECT_EQ(NULL, memmem(haystk, 0, needle, 1));
|
||||
free(haystk);
|
||||
free(needle);
|
||||
}
|
||||
|
@ -110,7 +105,11 @@ TEST(memmem, testEmptyHaystack_alwaysReturnsNull) {
|
|||
TEST(memmem, testEmptyHaystackAndNeedle_returnsHaystack) {
|
||||
char *needle = malloc(0);
|
||||
char *haystk = malloc(0);
|
||||
EXPECT_EQ(haystk, memmemi(haystk, 0, needle, 0));
|
||||
EXPECT_EQ(haystk, memmem(haystk, 0, needle, 0));
|
||||
free(haystk);
|
||||
free(needle);
|
||||
}
|
||||
|
||||
TEST(memmem, testWut) {
|
||||
ASSERT_STREQ("x", memmem("x", 1, "x", 1));
|
||||
}
|
||||
|
|
|
@ -32,52 +32,46 @@ char *strstr_kmp(const char *haystak, const char *needle) {
|
|||
return memmem(haystak, strlen(haystak), needle, strlen(needle));
|
||||
}
|
||||
|
||||
char *(*strstri)(const char *, const char *) = strstr_kmp;
|
||||
|
||||
FIXTURE(strstr, sse42_) {
|
||||
if (X86_HAVE(SSE4_2)) {
|
||||
strstri = strstr_sse42;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(strstr, test_emptyString_isFoundAtBeginning) {
|
||||
MAKESTRING(haystack, "abc123def");
|
||||
ASSERT_STREQ(&haystack[0], strstri(haystack, gc(strdup(""))));
|
||||
ASSERT_STREQ(&haystack[0], strstr(haystack, gc(strdup(""))));
|
||||
free(haystack);
|
||||
}
|
||||
|
||||
TEST(strstr, test_notFound) {
|
||||
MAKESTRING(haystack, "abc123def");
|
||||
ASSERT_EQ(NULL, strstri(haystack, gc(strdup("xyz"))));
|
||||
ASSERT_EQ(NULL, strstr(haystack, gc(strdup("xyz"))));
|
||||
free(haystack);
|
||||
}
|
||||
|
||||
TEST(strstr, test_middleOfString) {
|
||||
MAKESTRING(haystack, "abc123def");
|
||||
ASSERT_STREQ(&haystack[3], strstri(haystack, gc(strdup("123"))));
|
||||
ASSERT_STREQ(&haystack[3], strstr(haystack, gc(strdup("123"))));
|
||||
free(haystack);
|
||||
}
|
||||
|
||||
TEST(strstr, test_endOfString) {
|
||||
MAKESTRING(haystack, "abc123def");
|
||||
ASSERT_STREQ(&haystack[8], strstri(haystack, gc(strdup("f"))));
|
||||
ASSERT_STREQ(&haystack[8], strstr(haystack, gc(strdup("f"))));
|
||||
free(haystack);
|
||||
}
|
||||
|
||||
TEST(strstr, test_secondXmmWord) {
|
||||
MAKESTRING(haystack, "eeeeeeeeeeeeeeeebbbbbbbbbbb123");
|
||||
ASSERT_STREQ(&haystack[27], strstri(haystack, gc(strdup("123"))));
|
||||
ASSERT_STREQ(&haystack[27], strstr(haystack, gc(strdup("123"))));
|
||||
free(haystack);
|
||||
}
|
||||
|
||||
TEST(strstr, test_overlapsXmmWords) {
|
||||
MAKESTRING(haystack, "eeeeeeeeeeeeeeeebbbbbbbbbbbbbbb");
|
||||
ASSERT_STREQ(&haystack[15], strstri(haystack, gc(strdup("eb"))));
|
||||
ASSERT_STREQ(&haystack[15], strstr(haystack, gc(strdup("eb"))));
|
||||
free(haystack);
|
||||
}
|
||||
|
||||
TEST(strstr, test) {
|
||||
ASSERT_EQ(NULL, strstr("x86_64-linux-musl-gcc", "clang"));
|
||||
ASSERT_STREQ("gcc", strstr("x86_64-linux-musl-gcc", "gcc"));
|
||||
ASSERT_EQ(NULL, strstr("-Wl,--gc-sections", "stack-protector"));
|
||||
ASSERT_EQ(NULL, strstr("-Wl,--gc-sections", "sanitize"));
|
||||
ASSERT_STREQ("x", strstr("x", "x"));
|
||||
}
|
||||
|
|
|
@ -1,86 +0,0 @@
|
|||
/*-*- 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 │
|
||||
│ │
|
||||
│ 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/bits/bits.h"
|
||||
#include "libc/bits/progn.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/bing.internal.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/str/tpdecode.internal.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
wint_t wc;
|
||||
|
||||
TEST(tpdecode, testEmptyString_consumesNulTerminator) {
|
||||
wc = 123;
|
||||
EXPECT_EQ(1, tpdecode("", &wc));
|
||||
EXPECT_EQ(0, wc);
|
||||
}
|
||||
|
||||
TEST(tpdecode, testGlyph) {
|
||||
EXPECT_EQ(u'→', PROGN(ASSERT_EQ(3, tpdecode("→", &wc)), wc));
|
||||
EXPECT_EQ(L'𐌰', PROGN(ASSERT_EQ(4, tpdecode("𐌰𐌱𐌲𐌳", &wc)), wc));
|
||||
EXPECT_EQ(u'ち', PROGN(ASSERT_EQ(3, tpdecode("ち", &wc)), wc));
|
||||
EXPECT_EQ(u'‱', PROGN(ASSERT_EQ(3, tpdecode("‱", &wc)), wc));
|
||||
}
|
||||
|
||||
TEST(tpdecode, testNul_canonicalizesWithFiniteOverlongConsumption) {
|
||||
EXPECT_EQ('\0', PROGN(ASSERT_EQ(1, tpdecode("\0\0\0\0", &wc)), wc));
|
||||
EXPECT_EQ('\0',
|
||||
PROGN(ASSERT_EQ(2, tpdecode(gc(unbingstr(u"└ÇÇÇÇÇ")), &wc)), wc));
|
||||
EXPECT_EQ('\0',
|
||||
PROGN(ASSERT_EQ(3, tpdecode(gc(unbingstr(u"αÇÇÇÇÇ")), &wc)), wc));
|
||||
EXPECT_EQ('\0',
|
||||
PROGN(ASSERT_EQ(4, tpdecode(gc(unbingstr(u"≡ÇÇÇÇÇ")), &wc)), wc));
|
||||
EXPECT_EQ('\0',
|
||||
PROGN(ASSERT_EQ(5, tpdecode(gc(unbingstr(u"°ÇÇÇÇÇ")), &wc)), wc));
|
||||
EXPECT_EQ('\0',
|
||||
PROGN(ASSERT_EQ(6, tpdecode(gc(unbingstr(u"ⁿÇÇÇÇÇ")), &wc)), wc));
|
||||
}
|
||||
|
||||
TEST(tpdecode, testSynchronization_skipsLeadingContinuations) {
|
||||
EXPECT_EQ('a',
|
||||
PROGN(EXPECT_EQ(7, tpdecode(gc(unbingstr(u"Ç╗╝╜╛┐a")), &wc)), wc));
|
||||
}
|
||||
|
||||
TEST(tpdecode, testSpace) {
|
||||
EXPECT_EQ(0x20, PROGN(ASSERT_EQ(1, tpdecode(" ", &wc)), wc));
|
||||
}
|
||||
|
||||
TEST(tpdecode, testNegativeNumbers) {
|
||||
EXPECT_EQ(-1, PROGN(ASSERT_EQ(6, tpdecode(gc(unbingstr(u"λ┐┐┐┐┐")), &wc)),
|
||||
(wchar_t)wc));
|
||||
EXPECT_EQ(INT_MIN,
|
||||
PROGN(ASSERT_EQ(6, tpdecode(gc(unbingstr(u"■ÇÇÇÇÇ")), &wc)),
|
||||
(wchar_t)wc));
|
||||
EXPECT_EQ(0x80000000u,
|
||||
PROGN(ASSERT_EQ(6, tpdecode(gc(unbingstr(u"■ÇÇÇÇÇ")), &wc)), wc));
|
||||
EXPECT_EQ(0xC0000000u,
|
||||
PROGN(ASSERT_EQ(6, tpdecode(gc(unbingstr(u"λÇÇÇÇÇ")), &wc)), wc));
|
||||
}
|
||||
|
||||
TEST(tpdecode, testInvalidEncoding_endOfString) {
|
||||
EXPECT_EQ(u'<EFBFBD>', PROGN(EXPECT_EQ(-1, tpdecode(gc(unbingstr(u"≡")), &wc)), wc));
|
||||
}
|
||||
|
||||
TEST(tpdecode, testInvalidEncoding_tooFewContinuations) {
|
||||
EXPECT_EQ(u'<EFBFBD>', PROGN(EXPECT_EQ(-1, tpdecode(gc(unbingstr(u"≡")), &wc)), wc));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue