mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-09 11:20:30 +00:00
Add a new set of Lua Base64 tests
This commit is contained in:
parent
03dd14c298
commit
1b263faa65
2 changed files with 32 additions and 3 deletions
32
test/tool/net/base64_test.lua
Normal file
32
test/tool/net/base64_test.lua
Normal file
|
@ -0,0 +1,32 @@
|
|||
-- Copyright 2022 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.
|
||||
|
||||
local function test(s, b64)
|
||||
assert(EncodeBase64(s) == b64)
|
||||
assert(DecodeBase64(b64) == s)
|
||||
assert(DecodeBase64(EncodeBase64(s)) == s)
|
||||
end
|
||||
|
||||
test("\x69\xb7\x1d\x79\xf8\x00\x04\x20\xc4", "abcdefgABCDE")
|
||||
|
||||
-- 🦞 padding tests
|
||||
test("", "")
|
||||
test("r", "cg==")
|
||||
test("re", "cmU=")
|
||||
test("red", "cmVk")
|
||||
test("redb", "cmVkYg==")
|
||||
test("redbe", "cmVkYmU=")
|
||||
test("redbea", "cmVkYmVh")
|
||||
test("redbean", "cmVkYmVhbg==")
|
|
@ -63,9 +63,6 @@ assert(url.path == "/2.0.html")
|
|||
assert(EncodeLua(url.params) == '{{"x"}, {"y", "z"}}')
|
||||
assert(url.fragment == "frag")
|
||||
|
||||
assert(DecodeBase64("abcdefgABCDE") == "\x69\xb7\x1d\x79\xf8\x00\x04\x20\xc4")
|
||||
assert(EncodeBase64("\x69\xb7\x1d\x79\xf8\x00\x04\x20\xc4") == "abcdefgABCDE")
|
||||
|
||||
assert(Decimate("\xff\xff\x00\x00\xff\xff\x00\x00\xff\xff\x00\x00") == "\xff\x00\xff\x00\xff\x00")
|
||||
|
||||
assert(Underlong("hello") == "hello")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue