Files
multibase/multibase_test.go
mateon1 8e28da0e2a Updated codes to values from csv, added padded b32
License: MIT
Signed-off-by: Mateusz Naściszewski <matin1111@wp.pl>
2016-12-12 09:01:18 +01:00

40 lines
689 B
Go

package multibase
import (
"bytes"
"math/rand"
"testing"
)
func TestRoundTrip(t *testing.T) {
buf := make([]byte, 16)
rand.Read(buf)
baseList := []int{ Base16, Base32, Base32hex, Base32pad, Base32hexPad, Base58BTC, Base58Flickr, Base64pad, Base64urlPad }
for _, base := range baseList {
enc, err := Encode(base, buf)
if err != nil {
t.Fatal(err)
}
e, out, err := Decode(enc)
if err != nil {
t.Fatal(err)
}
if e != base {
t.Fatal("got wrong encoding out")
}
if !bytes.Equal(buf, out) {
t.Fatal("input wasnt the same as output", buf, out)
}
}
_, _, err := Decode("")
if err == nil {
t.Fatal("shouldnt be able to decode empty string")
}
}