mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 13:52:28 +00:00
Propagate nil in Lua APIs more often
This commit is contained in:
parent
c9d7838213
commit
638c56e3a5
5 changed files with 78 additions and 43 deletions
|
@ -47,9 +47,13 @@ assert(hex(0x1940efe9d47ae889) == "0x1940efe9d47ae889")
|
|||
assert(oct(0x1940efe9d47ae889) == "0145007376472436564211")
|
||||
assert(bin(0x1940efe9d47ae889) == "0b0001100101000000111011111110100111010100011110101110100010001001")
|
||||
|
||||
assert(EscapeHtml(nil) == nil)
|
||||
assert(EscapeHtml("?hello&there<>") == "?hello&there<>")
|
||||
|
||||
assert(EscapeParam(nil) == nil)
|
||||
assert(EscapeParam("?hello&there<>") == "%3Fhello%26there%3C%3E")
|
||||
|
||||
assert(DecodeLatin1(nil) == nil)
|
||||
assert(DecodeLatin1("hello\xff\xc0") == "helloÿÀ")
|
||||
assert(EncodeLatin1("helloÿÀ") == "hello\xff\xc0")
|
||||
|
||||
|
@ -65,6 +69,7 @@ assert(url.fragment == "frag")
|
|||
|
||||
assert(Decimate("\xff\xff\x00\x00\xff\xff\x00\x00\xff\xff\x00\x00") == "\xff\x00\xff\x00\xff\x00")
|
||||
|
||||
assert(Underlong(nil) == nil)
|
||||
assert(Underlong("hello") == "hello")
|
||||
assert(Underlong("hello\xc0\x80") == "hello\x00")
|
||||
|
||||
|
@ -91,6 +96,7 @@ assert(not IsLoopbackIp(0x08080808))
|
|||
assert(not IsLoopbackIp(0x0a000000))
|
||||
assert(IsLoopbackIp(0x7f000001))
|
||||
|
||||
assert(IndentLines(nil) == nil)
|
||||
assert(IndentLines("hi\nthere") == " hi\n there")
|
||||
assert(IndentLines("hi\nthere\n") == " hi\n there\n")
|
||||
assert(IndentLines("hi\nthere\n", 2) == " hi\n there\n")
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
|
||||
unix.pledge('stdio')
|
||||
|
||||
assert(Md5(nil) == nil)
|
||||
|
||||
-- https://datatracker.ietf.org/doc/html/rfc1321#appendix-A.5
|
||||
assert(Md5("hello") == "\x5d\x41\x40\x2a\xbc\x4b\x2a\x76\xb9\x71\x9d\x91\x10\x17\xc5\x92")
|
||||
assert(Md5("") == "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\x09\x98\xec\xf8\x42\x7e")
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
unix.pledge('stdio')
|
||||
|
||||
-- SHA-1
|
||||
assert(Sha1(nil) == nil)
|
||||
assert(Sha1("abc") == "\xa9\x99\x3e\x36\x47\x06\x81\x6a\xba\x3e\x25\x71\x78\x50\xc2\x6c\x9c\xd0\xd8\x9d")
|
||||
assert(
|
||||
Sha1("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") ==
|
||||
|
@ -57,6 +58,7 @@ assert(
|
|||
)
|
||||
|
||||
-- SHA-224
|
||||
assert(Sha224(nil) == nil)
|
||||
assert(
|
||||
Sha224("abc") ==
|
||||
"\x23\x09\x7d\x22\x34\x05\xd8\x22\x86\x42\xa4\x77\xbd\xa2" ..
|
||||
|
@ -106,6 +108,7 @@ assert(
|
|||
)
|
||||
|
||||
-- SHA-256
|
||||
assert(Sha256(nil) == nil)
|
||||
assert(
|
||||
Sha256("abc") ==
|
||||
"\xba\x78\x16\xbf\x8f\x01\xcf\xea\x41\x41\x40\xde\x5d\xae\x22\x23" ..
|
||||
|
@ -150,6 +153,7 @@ assert(
|
|||
)
|
||||
|
||||
-- SHA-384
|
||||
assert(Sha384(nil) == nil)
|
||||
assert(
|
||||
Sha384("abc") ==
|
||||
"\xcb\x00\x75\x3f\x45\xa3\x5e\x8b\xb5\xa0\x3d\x69\x9a\xc6\x50\x07\x27\x2c\x32\xab\x0e\xde\xd1\x63" ..
|
||||
|
@ -203,6 +207,7 @@ assert(
|
|||
)
|
||||
|
||||
-- SHA-512
|
||||
assert(Sha512(nil) == nil)
|
||||
assert(
|
||||
Sha512("abc") ==
|
||||
"\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41\x31\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2" ..
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue