Files
multibase/multibase_test.go

40 lines
692 B
Go
Raw Normal View History

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