# Tests for the base64 module.
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright (c) 1998-2000 by Ajuba Solutions.
# All rights reserved.
#
# RCS: @(#) $Id: base64.test,v 1.4 2000/05/30 23:59:59 ericm Exp $

if {[lsearch [namespace children] ::tcltest] == -1} {
    package require tcltest
    namespace import ::tcltest::*
}

if { [lsearch $auto_path [file dirname [info script]]] == -1 } {
    set auto_path [linsert $auto_path 0 [file dirname [info script]]]
}

package require base64

test base64-1.1 {base64::encode} {
    base64::encode "this is a test\n"
} "dGhpcyBpcyBhIHRlc3QK"
test base64-1.2 {base64::encode wraps lines at 60 characters} {
    set str "The short red fox ran quickly through the green field "
    append str "and jumped over the tall brown bear\n"
    base64::encode $str
} "VGhlIHNob3J0IHJlZCBmb3ggcmFuIHF1aWNrbHkgdGhyb3VnaCB0aGUgZ3Jl
ZW4gZmllbGQgYW5kIGp1bXBlZCBvdmVyIHRoZSB0YWxsIGJyb3duIGJlYXIK"

test base64-2.1 {base64::decode} {
    base64::decode "dGhpcyBpcyBhIHRlc3QK"
} "this is a test\n"
test base64-2.2 {base64::decode ignores newlines} {
    set str "VGhlIHNob3J0IHJlZCBmb3ggcmFuIHF1aWNrbHkgdGhyb3VnaCB0aGUgZ3Jl\n"
    append str "ZW4gZmllbGQgYW5kIGp1bXBlZCBvdmVyIHRoZSB0YWxsIGJyb3duIGJlYXIK"
    base64::decode $str
} "The short red fox ran quickly through the green field and jumped over the tall brown bear\n"
test base64-2.3 {base64::decode handles equal sign padding} {
    # decode the encoding of a string that will be padded in the encoding with
    # one padding char
    base64::decode [base64::encode "01234"]
} "01234"
test base64-2.4 {base64::decode handles equal sign padding} {
    # decode the encoding of a string that will be padded in the encoding with
    # two padding chars
    base64::decode [base64::encode "0123"]
} "0123"

test base64-3.1 {base64 identity test} {
	base64::decode [base64::encode "this is a test"]
} "this is a test"

::tcltest::cleanupTests
return
