40 lines
658 B
Go
40 lines
658 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, Base58BTC, Base58Flickr, Base64, Base64url }
|
|
|
|
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")
|
|
}
|
|
}
|