Make terminal ui binaries work well everywhere

Here's some screenshots of an emulator tui program that was compiled on
Linux, then scp'd it to Windows, Mac, and FreeBSD.

https://justine.storage.googleapis.com/blinkenlights-cmdexe.png
https://justine.storage.googleapis.com/blinkenlights-imac.png
https://justine.storage.googleapis.com/blinkenlights-freebsd.png
https://justine.storage.googleapis.com/blinkenlights-lisp.png

How is this even possible that we have a nontrivial ui binary that just
works on Mac, Windows, Linux, and BSD? Surely a first ever achievement.

Fixed many bugs. Bootstrapped John McCarthy's metacircular evaluator on
bare metal in half the size of Altair BASIC (about 2.5kb) and ran it in
emulator for fun and profit.
This commit is contained in:
Justine Tunney 2020-10-10 21:18:53 -07:00
parent 680daf1210
commit 9e3e985ae5
276 changed files with 7026 additions and 3790 deletions

View file

@ -676,16 +676,24 @@ TEST(snprintf, formatStringLiteral) {
EXPECT_EQ('\\' | 'n' << 8, cescapec('\n'));
EXPECT_EQ('\\' | '3' << 8 | '7' << 16 | '7' << 24, cescapec('\377'));
EXPECT_STREQ("\"hi\\n\"", Format("%`'s", "hi\n"));
EXPECT_STREQ("\"\\000\"", Format("%`'.*s", 1, "\0"));
}
TEST(palandprintf, precisionStillRespectsNulTerminatorIfNotEscOrRepr) {
EXPECT_STREQ("Makefile - 25 lines ",
Format("%.20s - %d lines %s", "Makefile", 25, ""));
}
BENCH(palandprintf, bench) {
EZBENCH2("23 %x", donothing, Format("%x", VEIL("r", 23)));
EZBENCH2("23 %d", donothing, Format("%d", VEIL("r", 23)));
EZBENCH2("INT_MIN %x", donothing, Format("%x", VEIL("r", INT_MIN)));
EZBENCH2("INT_MIN %d", donothing, Format("%d", VEIL("r", INT_MIN)));
EZBENCH2("ascii %s", donothing, Format("%s", VEIL("r", "hiuhcreohucreo")));
EZBENCH2("utf8 %s", donothing, Format("%s", VEIL("r", "hi (╯°□°)╯")));
EZBENCH2("snprintf %hs", donothing, Format("%hs", VEIL("r", u"hi (╯°□°)╯")));
EZBENCH2("snprintf %ls", donothing, Format("%ls", VEIL("r", L"hi (╯°□°)╯")));
EZBENCH2("int64toarray", donothing, int64toarray_radix10(-3, buffer));
EZBENCH2("23 %x", donothing, Format("%x", VEIL("r", 23)));
EZBENCH2("23 %d", donothing, Format("%d", VEIL("r", 23)));
EZBENCH2("INT_MIN %x", donothing, Format("%x", VEIL("r", INT_MIN)));
EZBENCH2("INT_MIN %d", donothing, Format("%d", VEIL("r", INT_MIN)));
EZBENCH2("23 int64toarray", donothing, int64toarray_radix10(23, buffer));
EZBENCH2("INT_MIN int64toarray", donothing,
int64toarray_radix10(INT_MIN, buffer));
}

View file

@ -1342,7 +1342,7 @@ TEST(paddusw, fuzz) {
TEST(psubb, fuzz) {
int i, j;
int8_t x[16], y[16], a[16], b[16];
uint8_t x[16], y[16], a[16], b[16];
for (i = 0; i < 100; ++i) {
RngSet(x, sizeof(x));
RngSet(y, sizeof(y));

View file

@ -0,0 +1,33 @@
/*-*- 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/escape/escape.h"
#include "libc/testlib/testlib.h"
TEST(cescapec, test) {
EXPECT_EQ(' ', cescapec(0x20));
EXPECT_EQ('~', cescapec(0x7E));
EXPECT_EQ('\\' | 'r' << 8, cescapec('\r'));
EXPECT_EQ('\\' | 'n' << 8, cescapec('\n'));
EXPECT_EQ('\\' | '0' << 8 | '0' << 16 | '0' << 24, cescapec(0));
EXPECT_EQ('\\' | '1' << 8 | '7' << 16 | '7' << 24, cescapec(0x7F));
EXPECT_EQ('\\' | '3' << 8 | '7' << 16 | '7' << 24, cescapec(0xFF));
EXPECT_EQ('\\' | '3' << 8 | '7' << 16 | '7' << 24, cescapec(0xFFFF));
EXPECT_EQ('\\' | '3' << 8 | '7' << 16 | '7' << 24, cescapec(-1));
}

View file

@ -20,34 +20,34 @@
#include "libc/runtime/internal.h"
#include "libc/testlib/testlib.h"
TEST(getdosargv, empty) {
TEST(GetDosArgv, empty) {
size_t max = 4;
size_t size = ARG_MAX;
char *buf = tmalloc(size * sizeof(char));
char **argv = tmalloc(max * sizeof(char *));
EXPECT_EQ(0, getdosargv(u"", buf, size, argv, max));
EXPECT_EQ(0, GetDosArgv(u"", buf, size, argv, max));
EXPECT_EQ(NULL, argv[0]);
tfree(argv);
tfree(buf);
}
TEST(getdosargv, emptyish) {
TEST(GetDosArgv, emptyish) {
size_t max = 4;
size_t size = ARG_MAX;
char *buf = tmalloc(size * sizeof(char));
char **argv = tmalloc(max * sizeof(char *));
EXPECT_EQ(0, getdosargv(u" ", buf, size, argv, max));
EXPECT_EQ(0, GetDosArgv(u" ", buf, size, argv, max));
EXPECT_EQ(NULL, argv[0]);
tfree(argv);
tfree(buf);
}
TEST(getdosargv, basicUsage) {
TEST(GetDosArgv, basicUsage) {
size_t max = 4;
size_t size = ARG_MAX;
char *buf = tmalloc(size * sizeof(char));
char **argv = tmalloc(max * sizeof(char *));
EXPECT_EQ(3, getdosargv(u"a\t \"b c\" d ", buf, size, argv, max));
EXPECT_EQ(3, GetDosArgv(u"a\t \"b c\" d ", buf, size, argv, max));
EXPECT_STREQ("a", argv[0]);
EXPECT_STREQ("b c", argv[1]);
EXPECT_STREQ("d", argv[2]);
@ -56,12 +56,12 @@ TEST(getdosargv, basicUsage) {
tfree(buf);
}
TEST(getdosargv, advancedUsage) {
TEST(GetDosArgv, advancedUsage) {
size_t max = 4;
size_t size = ARG_MAX;
char *buf = tmalloc(size * sizeof(char));
char **argv = tmalloc(max * sizeof(char *));
EXPECT_EQ(2, getdosargv(u"(╯°□°)╯︵ ┻━┻", buf, size, argv, max));
EXPECT_EQ(2, GetDosArgv(u"(╯°□°)╯︵ ┻━┻", buf, size, argv, max));
EXPECT_STREQ("(╯°□°)╯︵", argv[0]);
EXPECT_STREQ("┻━┻", argv[1]);
EXPECT_EQ(NULL, argv[2]);
@ -69,12 +69,12 @@ TEST(getdosargv, advancedUsage) {
tfree(buf);
}
TEST(getdosargv, testAegeanGothicSupplementaryPlanes) {
TEST(GetDosArgv, testAegeanGothicSupplementaryPlanes) {
size_t max = 4; /* these symbols are almost as old as dos */
size_t size = ARG_MAX;
char *buf = tmalloc(size * sizeof(char));
char **argv = tmalloc(max * sizeof(char *));
EXPECT_EQ(2, getdosargv(u"𐄷𐄸𐄹𐄺𐄻𐄼 𐌰𐌱𐌲𐌳𐌴𐌵𐌶𐌷", buf, size, argv, max));
EXPECT_EQ(2, GetDosArgv(u"𐄷𐄸𐄹𐄺𐄻𐄼 𐌰𐌱𐌲𐌳𐌴𐌵𐌶𐌷", buf, size, argv, max));
EXPECT_STREQ("𐄷𐄸𐄹𐄺𐄻𐄼", argv[0]);
EXPECT_STREQ("𐌰𐌱𐌲𐌳𐌴𐌵𐌶𐌷", argv[1]);
EXPECT_EQ(NULL, argv[2]);
@ -82,12 +82,12 @@ TEST(getdosargv, testAegeanGothicSupplementaryPlanes) {
tfree(buf);
}
TEST(getdosargv, realWorldUsage) {
TEST(GetDosArgv, realWorldUsage) {
size_t max = 512;
size_t size = ARG_MAX;
char *buf = tmalloc(size * sizeof(char));
char **argv = tmalloc(max * sizeof(char *));
EXPECT_EQ(5, getdosargv(u"C:\\Users\\jtunn\\printargs.com oh yes yes yes",
EXPECT_EQ(5, GetDosArgv(u"C:\\Users\\jtunn\\printargs.com oh yes yes yes",
buf, size, argv, max));
EXPECT_STREQ("C:\\Users\\jtunn\\printargs.com", argv[0]);
EXPECT_STREQ("oh", argv[1]);
@ -99,12 +99,12 @@ TEST(getdosargv, realWorldUsage) {
tfree(buf);
}
TEST(getdosargv, bufferOverrun_countIsStillAccurate_truncatesMemoryWithGrace) {
TEST(GetDosArgv, bufferOverrun_countIsStillAccurate_truncatesMemoryWithGrace) {
size_t max = 3;
size_t size = 7;
char *buf = tmalloc(size * sizeof(char));
char **argv = tmalloc(max * sizeof(char *));
EXPECT_EQ(3, getdosargv(u"a\t \"b c\" d ", buf, size, argv, max));
EXPECT_EQ(3, GetDosArgv(u"a\t \"b c\" d ", buf, size, argv, max));
EXPECT_STREQ("a", argv[0]);
EXPECT_STREQ("b c", argv[1]);
EXPECT_EQ(NULL, argv[2]);
@ -112,44 +112,44 @@ TEST(getdosargv, bufferOverrun_countIsStillAccurate_truncatesMemoryWithGrace) {
tfree(buf);
}
TEST(getdosargv, pureScanningMode) {
TEST(GetDosArgv, pureScanningMode) {
size_t max = 0;
size_t size = 0;
char *buf = NULL;
char **argv = NULL;
EXPECT_EQ(3, getdosargv(u"a b c", buf, size, argv, max));
EXPECT_EQ(3, GetDosArgv(u"a b c", buf, size, argv, max));
}
TEST(getdosargv, justSlashQuote) {
TEST(GetDosArgv, justSlashQuote) {
size_t max = 4, size = 16;
char *buf = tmalloc(size * sizeof(char));
char **argv = tmalloc(max * sizeof(char *));
EXPECT_EQ(1, getdosargv(u"\"\\\\\\\"\"", buf, size, argv, max));
EXPECT_EQ(1, GetDosArgv(u"\"\\\\\\\"\"", buf, size, argv, max));
EXPECT_STREQ("\\\"", argv[0]);
tfree(argv);
tfree(buf);
}
TEST(getdosargv, quoteInMiddleOfArg_wontSplitArg) {
TEST(GetDosArgv, quoteInMiddleOfArg_wontSplitArg) {
size_t max = 4, size = 16;
char *buf = tmalloc(size * sizeof(char));
char **argv = tmalloc(max * sizeof(char *));
EXPECT_EQ(1, getdosargv(u"hi\"\"there", buf, size, argv, max));
EXPECT_EQ(1, GetDosArgv(u"hi\"\"there", buf, size, argv, max));
EXPECT_STREQ("hithere", argv[0]);
max = 4, size = 16;
EXPECT_EQ(1, getdosargv(u"hi\" \"there", buf, size, argv, max));
EXPECT_EQ(1, GetDosArgv(u"hi\" \"there", buf, size, argv, max));
EXPECT_STREQ("hi there", argv[0]);
tfree(argv);
tfree(buf);
}
TEST(getdosargv, waqQuoting1) {
TEST(GetDosArgv, waqQuoting1) {
size_t max = 4;
size_t size = ARG_MAX;
char *buf = tmalloc(size * sizeof(char));
char **argv = tmalloc(max * sizeof(char *));
EXPECT_EQ(2,
getdosargv(u"a\\\\\"\"\"\"\"\"\"\"b c\" d", buf, size, argv, max));
GetDosArgv(u"a\\\\\"\"\"\"\"\"\"\"b c\" d", buf, size, argv, max));
EXPECT_STREQ("a\\\"\"b", argv[0]);
EXPECT_STREQ("c d", argv[1]);
EXPECT_EQ(NULL, argv[2]);
@ -157,12 +157,12 @@ TEST(getdosargv, waqQuoting1) {
tfree(buf);
}
TEST(getdosargv, waqQuoting2) {
TEST(GetDosArgv, waqQuoting2) {
size_t max = 4;
size_t size = ARG_MAX;
char *buf = tmalloc(size * sizeof(char));
char **argv = tmalloc(max * sizeof(char *));
EXPECT_EQ(2, getdosargv(u"\"a\\\"b c\" d", buf, size, argv, max));
EXPECT_EQ(2, GetDosArgv(u"\"a\\\"b c\" d", buf, size, argv, max));
EXPECT_STREQ("a\"b c", argv[0]);
EXPECT_STREQ("d", argv[1]);
EXPECT_EQ(NULL, argv[2]);

View file

@ -21,14 +21,14 @@
#include "libc/str/str.h"
#include "libc/testlib/testlib.h"
TEST(getdosenviron, testOneVariable) {
TEST(GetDosEnviron, testOneVariable) {
#define kEnv u"A=Und wird die Welt auch in Flammen stehen\0"
size_t max = 2;
size_t size = sizeof(kEnv) >> 1;
char *block = tmalloc(size);
char16_t *env = memcpy(tmalloc(sizeof(kEnv)), kEnv, sizeof(kEnv));
char **envp = tmalloc(max * sizeof(char *));
EXPECT_EQ(1, getdosenviron(env, block, size, envp, max));
EXPECT_EQ(1, GetDosEnviron(env, block, size, envp, max));
EXPECT_STREQ("A=Und wird die Welt auch in Flammen stehen", envp[0]);
EXPECT_EQ(NULL, envp[1]);
ASSERT_BINEQ(u"A=Und wird die Welt auch in Flammen stehen  ", block);
@ -38,7 +38,7 @@ TEST(getdosenviron, testOneVariable) {
#undef kEnv
}
TEST(getdosenviron, testTwoVariables) {
TEST(GetDosEnviron, testTwoVariables) {
#define kEnv \
(u"𐌰𐌱𐌲𐌳=Und wird die Welt auch in Flammen stehen\0" \
u"𐌴𐌵𐌶𐌷=Wir werden wieder auferstehen\0")
@ -47,7 +47,7 @@ TEST(getdosenviron, testTwoVariables) {
char *block = tmalloc(size);
char16_t *env = memcpy(tmalloc(sizeof(kEnv)), kEnv, sizeof(kEnv));
char **envp = tmalloc(max * sizeof(char *));
EXPECT_EQ(2, getdosenviron(env, block, size, envp, max));
EXPECT_EQ(2, GetDosEnviron(env, block, size, envp, max));
EXPECT_STREQ("𐌰𐌱𐌲𐌳=Und wird die Welt auch in Flammen stehen", envp[0]);
EXPECT_STREQ("𐌴𐌵𐌶𐌷=Wir werden wieder auferstehen", envp[1]);
EXPECT_EQ(NULL, envp[2]);
@ -57,14 +57,14 @@ TEST(getdosenviron, testTwoVariables) {
#undef kEnv
}
TEST(getdosenviron, testOverrun_truncatesWithGrace) {
TEST(GetDosEnviron, testOverrun_truncatesWithGrace) {
#define kEnv u"A=Und wird die Welt auch in Flammen stehen\0"
size_t max = 2;
size_t size = sizeof(kEnv) >> 2;
char *block = tmalloc(size);
char16_t *env = memcpy(tmalloc(sizeof(kEnv)), kEnv, sizeof(kEnv));
char **envp = tmalloc(max * sizeof(char *));
EXPECT_EQ(1, getdosenviron(env, block, size, envp, max));
EXPECT_EQ(1, GetDosEnviron(env, block, size, envp, max));
EXPECT_STREQ("A=Und wird die Welt ", envp[0]);
EXPECT_EQ(NULL, envp[1]);
ASSERT_BINEQ(u"A=Und wird die Welt   ", block);
@ -74,30 +74,30 @@ TEST(getdosenviron, testOverrun_truncatesWithGrace) {
#undef kEnv
}
TEST(getdosenviron, testEmpty_doesntTouchMemory) {
EXPECT_EQ(0, getdosenviron(u"", NULL, 0, NULL, 0));
TEST(GetDosEnviron, testEmpty_doesntTouchMemory) {
EXPECT_EQ(0, GetDosEnviron(u"", NULL, 0, NULL, 0));
}
TEST(getdosenviron, testEmpty_zeroTerminatesWheneverPossible_1) {
TEST(GetDosEnviron, testEmpty_zeroTerminatesWheneverPossible_1) {
size_t max = 1;
char **envp = tmalloc(max * sizeof(char *));
EXPECT_EQ(0, getdosenviron(u"", NULL, 0, envp, max));
EXPECT_EQ(0, GetDosEnviron(u"", NULL, 0, envp, max));
EXPECT_EQ(NULL, envp[0]);
tfree(envp);
}
TEST(getdosenviron, testEmpty_zeroTerminatesWheneverPossible_2) {
TEST(GetDosEnviron, testEmpty_zeroTerminatesWheneverPossible_2) {
size_t size = 1;
char *block = tmalloc(size);
EXPECT_EQ(0, getdosenviron(u"", block, size, NULL, 0));
EXPECT_EQ(0, GetDosEnviron(u"", block, size, NULL, 0));
EXPECT_BINEQ(u" ", block);
tfree(block);
}
TEST(getdosenviron, testEmpty_zeroTerminatesWheneverPossible_3) {
TEST(GetDosEnviron, testEmpty_zeroTerminatesWheneverPossible_3) {
size_t size = 2;
char *block = tmalloc(size);
EXPECT_EQ(0, getdosenviron(u"", block, size, NULL, 0));
EXPECT_EQ(0, GetDosEnviron(u"", block, size, NULL, 0));
EXPECT_BINEQ(u"  ", block);
tfree(block);
}

View file

@ -31,6 +31,11 @@ TEST(strchr, text) {
char buf[] = "hellothere";
EXPECT_STREQ("there", strchr(buf, 't'));
}
TEST(strchr, testsse) {
char buf[] = "hellohellohellohellohellohellohellohello"
"theretheretheretheretheretheretherethere";
EXPECT_STREQ("theretheretheretheretheretheretherethere", strchr(buf, 't'));
}
TEST(rawmemchr, text) {
char buf[] = "hellothere";
EXPECT_STREQ("there", rawmemchr(buf, 't'));

View file

@ -37,8 +37,16 @@ TEST(tpenc, test) {
EXPECT_EQ(0x8080808080FEul, tpenc(INT_MIN));
}
TEST(tpenc, theimp) {
ASSERT_EQ(0x88989FF0, tpenc(L'😈'));
}
TEST(tpenc, testBeyondTheStandard) {
ASSERT_EQ(0xBFBFBFBFBFFF, tpenc(-1));
}
uint64_t Tpenc(int x) {
return (v = tpenc(x));
return (v = tpenc(VEIL("r", x)));
}
BENCH(tpenc, bench) {
@ -47,6 +55,7 @@ BENCH(tpenc, bench) {
EZBENCH(donothing, Tpenc(' '));
EZBENCH(donothing, Tpenc(0x7f));
EZBENCH(donothing, Tpenc(L''));
EZBENCH(donothing, Tpenc(-1));
EZBENCH(donothing, Tpenc(INT_MIN));
fprintf(stderr, "\n");
}

View file

@ -61,3 +61,7 @@ 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));
}

View file

@ -0,0 +1,27 @@
/*-*- 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/testlib.h"
TEST(tprecode16to8, test) {
char b[128];
EXPECT_EQ(69, tprecode16to8(b, 128, u"(╯°□°)╯︵L┻━┻ 𐌰𐌱𐌲𐌳𐌴𐌵𐌶𐌷𐌸𐌹"));
EXPECT_STREQ("(╯°□°)╯︵L┻━┻ 𐌰𐌱𐌲𐌳𐌴𐌵𐌶𐌷𐌸𐌹", b);
}

View file

@ -28,3 +28,9 @@ TEST(tprecode8to16, test) {
EXPECT_STREQ(u"hello☻♥", buf);
tfree(buf);
}
TEST(tprecode8to16, test2) {
char16_t b[128];
EXPECT_EQ(34, tprecode8to16(b, 128, "(╯°□°)╯︵L┻━┻ 𐌰𐌱𐌲𐌳𐌴𐌵𐌶𐌷𐌸𐌹"));
EXPECT_STREQ(u"(╯°□°)╯︵L┻━┻ 𐌰𐌱𐌲𐌳𐌴𐌵𐌶𐌷𐌸𐌹", b);
}

View file

@ -42,6 +42,7 @@
#include "libc/zip.h"
#include "third_party/zlib/zlib.h"
STATIC_YOINK("zip_uri_support");
STATIC_YOINK("libc/testlib/hyperion.txt");
TEST(undeflate, testEmbeddedPlaintextConstant) {
@ -86,7 +87,7 @@ TEST(undeflate, testEmbeddedCompressedZipFile_theHardWay) {
struct DeflateState ds;
uint8_t *map, *cd, *cf, *lf, *data;
found = false;
ASSERT_NE(-1, (fd = open(findcombinary(), O_RDONLY)));
ASSERT_NE(-1, (fd = open(FindComBinary(), O_RDONLY)));
ASSERT_NE(-1, fstat(fd, &st));
ASSERT_NE(MAP_FAILED,
(map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0)));

View file

@ -18,11 +18,14 @@
02110-1301 USA
*/
#include "libc/calls/calls.h"
#include "libc/limits.h"
#include "libc/runtime/runtime.h"
#include "libc/testlib/testlib.h"
#include "libc/time/time.h"
textstartup static void strftime_test_init(void) { setenv("TZ", "GST", true); }
textstartup static void strftime_test_init(void) {
setenv("TZ", "GST", true);
}
const void *const strftime_test_ctor[] initarray = {strftime_test_init};
testonly char *FormatTime(const char *fmt, struct tm *tm) {
@ -37,6 +40,12 @@ TEST(strftime_100, iso8601_ShakaZuluTime) {
FormatTime("%Y-%m-%dT%H:%M:%SZ", gmtime(&t)));
}
TEST(xiso8601, testUnixYearZero) {
int64_t t = 0;
ASSERT_STREQ("1970-01-01T00:00:00Z",
FormatTime("%Y-%m-%dT%H:%M:%SZ", gmtime(&t)));
}
TEST(strftime_100, rfc2822_ShakaZuluTime) {
int64_t t = 0x5cd04d0e;
ASSERT_STREQ("Mon, 06 May 2019 15:04:46 +0000",
@ -66,3 +75,27 @@ TEST(strftime_201, rfc822_GoogleStandardTime) {
ASSERT_STREQ("Mon, 06 May 19 08:04:46 -0700",
FormatTime("%a, %d %b %y %T %z", localtime(&t)));
}
/* TEST(xiso8601, testModernity_TODO) { */
/* int64_t t = (1600 - 1970) * 31536000; */
/* ASSERT_STREQ("1600-01-01T00:00:00Z", */
/* FormatTime("%Y-%m-%dT%H:%M:%SZ", gmtime(&t))); */
/* } */
TEST(xiso8601, testAtLeastBetterThanTraditionalUnixLimit) {
int64_t t = 10737418235;
ASSERT_STREQ("2310-04-04T16:10:35Z",
FormatTime("%Y-%m-%dT%H:%M:%SZ", gmtime(&t)));
}
TEST(xiso8601, testSomethingHuge) {
int64_t t = 7707318812667;
ASSERT_STREQ("246205-03-18T20:24:27Z",
FormatTime("%Y-%m-%dT%H:%M:%SZ", gmtime(&t)));
}
/* TEST(xiso8601, testMostOfStelliferousEra_TODO) { */
/* int64_t t = INT64_MAX; */
/* ASSERT_STREQ("somethinghuge-01-01T00:00:00Z", */
/* FormatTime("%Y-%m-%dT%H:%M:%SZ", gmtime(&t))); */
/* } */