improve tbase64.nim (#17964)
This commit is contained in:
parent
6ab911accb
commit
9ca3218a6d
1 changed files with 6 additions and 12 deletions
|
|
@ -1,14 +1,11 @@
|
||||||
discard """
|
discard """
|
||||||
output: '''YQ=='''
|
targets: "c js"
|
||||||
nimout: '''YQ=='''
|
|
||||||
"""
|
"""
|
||||||
import base64
|
|
||||||
|
|
||||||
import base64
|
import std/base64
|
||||||
static: echo encode("a")
|
|
||||||
echo encode("a")
|
|
||||||
|
|
||||||
proc main() =
|
template main() =
|
||||||
|
doAssert encode("a") == "YQ=="
|
||||||
doAssert encode("Hello World") == "SGVsbG8gV29ybGQ="
|
doAssert encode("Hello World") == "SGVsbG8gV29ybGQ="
|
||||||
doAssert encode("leasure.") == "bGVhc3VyZS4="
|
doAssert encode("leasure.") == "bGVhc3VyZS4="
|
||||||
doAssert encode("easure.") == "ZWFzdXJlLg=="
|
doAssert encode("easure.") == "ZWFzdXJlLg=="
|
||||||
|
|
@ -38,11 +35,7 @@ proc main() =
|
||||||
doAssert decode(encodeMIME(t, lineLen=40)) == t
|
doAssert decode(encodeMIME(t, lineLen=40)) == t
|
||||||
doAssert decode(encodeMIME(t, lineLen=76)) == t
|
doAssert decode(encodeMIME(t, lineLen=76)) == t
|
||||||
|
|
||||||
const invalid = "SGVsbG\x008gV29ybGQ="
|
doAssertRaises(ValueError): discard decode("SGVsbG\x008gV29ybGQ=")
|
||||||
try:
|
|
||||||
doAssert decode(invalid) == "will throw error"
|
|
||||||
except ValueError:
|
|
||||||
discard
|
|
||||||
|
|
||||||
block base64urlSafe:
|
block base64urlSafe:
|
||||||
doAssert encode("c\xf7>", safe = true) == "Y_c-"
|
doAssert encode("c\xf7>", safe = true) == "Y_c-"
|
||||||
|
|
@ -59,4 +52,5 @@ proc main() =
|
||||||
doAssert encode("", safe = true) == ""
|
doAssert encode("", safe = true) == ""
|
||||||
doAssert encode("the quick brown dog jumps over the lazy fox", safe = true) == "dGhlIHF1aWNrIGJyb3duIGRvZyBqdW1wcyBvdmVyIHRoZSBsYXp5IGZveA=="
|
doAssert encode("the quick brown dog jumps over the lazy fox", safe = true) == "dGhlIHF1aWNrIGJyb3duIGRvZyBqdW1wcyBvdmVyIHRoZSBsYXp5IGZveA=="
|
||||||
|
|
||||||
|
static: main()
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue