diff options
author | Peter Saxton <peterhsaxton@gmail.com> | 2020-06-23 11:09:01 +0100 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2020-06-24 22:09:19 +0100 |
commit | 5077a4915893310e2f94a6541563529305e3cd28 (patch) | |
tree | 1f2ce90ba1219f858e0d55e20dec0d979b372df3 /test | |
parent | 5017b8bff3097206d36bc6d5f28ce082649d4dbc (diff) | |
download | gleam_stdlib-5077a4915893310e2f94a6541563529305e3cd28.tar.gz gleam_stdlib-5077a4915893310e2f94a6541563529305e3cd28.zip |
encode and decode functions for bas64
Diffstat (limited to 'test')
-rw-r--r-- | test/gleam/base_test.gleam | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/test/gleam/base_test.gleam b/test/gleam/base_test.gleam new file mode 100644 index 0000000..90fdb2a --- /dev/null +++ b/test/gleam/base_test.gleam @@ -0,0 +1,52 @@ +import gleam/base +import gleam/bit_string.{BitString} +import gleam/io +import gleam/list +import gleam/should + +external fn list_to_binary(List(Int)) -> BitString = + "erlang" "list_to_binary" + +pub fn encode64_test() { + [255, 127, 254, 252] + |> list_to_binary() + |> base.encode64(True) + |> should.equal("/3/+/A==") + + [255, 127, 254, 252] + |> list_to_binary() + |> base.encode64(False) + |> should.equal("/3/+/A") + + [0, 0, 0] + |> list_to_binary() + |> base.encode64(True) + |> should.equal("AAAA") + + [] + |> list_to_binary() + |> base.encode64(True) + |> should.equal("") +} + +pub fn decode64_test() { + "/3/+/A==" + |> base.decode64() + |> should.equal(Ok(list_to_binary([255, 127, 254, 252]))) + + "/3/+/A" + |> base.decode64() + |> should.equal(Ok(list_to_binary([255, 127, 254, 252]))) + + "AAAA" + |> base.decode64() + |> should.equal(Ok(list_to_binary([0, 0, 0]))) + + "" + |> base.decode64() + |> should.equal(Ok(list_to_binary([]))) + + ")!" + |> base.decode64() + |> should.equal(Error(Nil)) +} |