-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.mojo
37 lines (33 loc) · 1.06 KB
/
test.mojo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from fast_base64 import encode, decode
from fast_base64.chromium import encode as c_encode
from base64 import b64encode
from testing import assert_equal
from samples import mobi_dick_plain, mobi_dick_base64
fn b64(s: String) raises:
var b = encode(s)
assert_equal(b, b64encode(s))
assert_equal(b, c_encode(s))
var p: DTypePointer[DType.uint8]
var length: Int
p, length = decode[zero_terminated=True](b)
if len(s) == 0 and length == 0:
return
var decoded_s = String(p.bitcast[DType.int8](), length)
assert_equal(s, decoded_s)
fn main() raises:
b64("hello world")
b64("")
b64("h")
b64("ha")
b64("hal")
b64("halo")
b64("AtariAtat")
b64("AtariAtatürkAtatürk's")
var b_chromium = encode(mobi_dick_plain)
var b_std = b64encode(mobi_dick_plain)
assert_equal(b_chromium, mobi_dick_base64)
assert_equal(b_std, mobi_dick_base64)
var p: DTypePointer[DType.uint8]
var l: Int
p, l = decode[True](mobi_dick_base64)
assert_equal(mobi_dick_plain, String(p.bitcast[DType.int8](), l))