Skip to content

Commit

Permalink
improve tbase64.nim (nim-lang#17964)
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour authored May 8, 2021
1 parent 6ab911a commit 9ca3218
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions tests/stdlib/tbase64.nim
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
discard """
output: '''YQ=='''
nimout: '''YQ=='''
targets: "c js"
"""
import base64

import base64
static: echo encode("a")
echo encode("a")
import std/base64

proc main() =
template main() =
doAssert encode("a") == "YQ=="
doAssert encode("Hello World") == "SGVsbG8gV29ybGQ="
doAssert encode("leasure.") == "bGVhc3VyZS4="
doAssert encode("easure.") == "ZWFzdXJlLg=="
Expand Down Expand Up @@ -38,11 +35,7 @@ proc main() =
doAssert decode(encodeMIME(t, lineLen=40)) == t
doAssert decode(encodeMIME(t, lineLen=76)) == t

const invalid = "SGVsbG\x008gV29ybGQ="
try:
doAssert decode(invalid) == "will throw error"
except ValueError:
discard
doAssertRaises(ValueError): discard decode("SGVsbG\x008gV29ybGQ=")

block base64urlSafe:
doAssert encode("c\xf7>", safe = true) == "Y_c-"
Expand All @@ -59,4 +52,5 @@ proc main() =
doAssert encode("", safe = true) == ""
doAssert encode("the quick brown dog jumps over the lazy fox", safe = true) == "dGhlIHF1aWNrIGJyb3duIGRvZyBqdW1wcyBvdmVyIHRoZSBsYXp5IGZveA=="

static: main()
main()

0 comments on commit 9ca3218

Please sign in to comment.