1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 module test_base64
is test
22 fun test_encode
is test
do
23 assert "".encode_base64
== ""
24 assert "f".encode_base64
== "Zg=="
25 assert "fo".encode_base64
== "Zm8="
26 assert "foo".encode_base64
== "Zm9v"
27 assert "foob".encode_base64
== "Zm9vYg=="
28 assert "fooba".encode_base64
== "Zm9vYmE="
29 assert "foobar".encode_base64
== "Zm9vYmFy"
32 fun test_decode
is test
do
33 assert "".decode_base64
.to_s
== ""
34 assert "Zg==".decode_base64
.to_s
== "f"
35 assert "Zm8=".decode_base64
.to_s
== "fo"
36 assert "Zm9v".decode_base64
.to_s
== "foo"
37 assert "Zm9vYg==".decode_base64
.to_s
== "foob"
38 assert "Zm9vYmE=".decode_base64
.to_s
== "fooba"
39 assert "Zm9vYmFy".decode_base64
.to_s
== "foobar"
41 assert "Zm9vYg".decode_base64
.to_s
== "foob"
42 assert "Zm9vYmE".decode_base64
.to_s
== "fooba"
43 assert "Zm9v*Yg".decode_base64
.to_s
== "foob"
46 fun test_is_base64
is test
do
47 assert "Znm=".is_base64
48 assert not "Znm===".is_base64
49 assert not "Z.sd=".is_base64
50 assert not "Z==D".is_base64
53 fun test_check_base64
is test
do
54 assert "Znm=".check_base64
== null
55 assert "Znm===".check_base64
.as(not null).to_s
== "Invalid padding length"
56 assert "Z.sd=".check_base64
.as(not null).to_s
== "Invalid Base64 character at position 1: ."
57 assert "Z==D".check_base64
.as(not null).to_s
== "Invalid padding character D at position 3"