From 1b263faa65765649c882753c59e0c84db0b76627 Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Sat, 23 Jul 2022 03:17:50 -0400 Subject: [PATCH] Add a new set of Lua Base64 tests --- test/tool/net/base64_test.lua | 32 ++++++++++++++++++++++++++++++++ test/tool/net/lfuncs_test.lua | 3 --- 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 test/tool/net/base64_test.lua diff --git a/test/tool/net/base64_test.lua b/test/tool/net/base64_test.lua new file mode 100644 index 000000000..8cd43f7e4 --- /dev/null +++ b/test/tool/net/base64_test.lua @@ -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==") diff --git a/test/tool/net/lfuncs_test.lua b/test/tool/net/lfuncs_test.lua index ada5a8ead..eb192532d 100644 --- a/test/tool/net/lfuncs_test.lua +++ b/test/tool/net/lfuncs_test.lua @@ -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")