github.com/mutagen-io/mutagen@v0.18.0-rc1/pkg/encoding/base62_test.go (about) 1 package encoding 2 3 import ( 4 "bytes" 5 "testing" 6 ) 7 8 // TestBase62RoundTrip verifies that Base62 encoding correctly round-trips data. 9 func TestBase62RoundTrip(t *testing.T) { 10 // Set up test cases. 11 testCases := [][]byte{ 12 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 13 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}, 14 {0x01, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 15 {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}, 16 {0xf2, 0xa7, 0x30, 0x90, 0x01, 0x7b, 0x00, 0x01, 0xff, 0xfe, 0x0f, 0x1f, 0xa1, 0x0a, 0x0f, 0xf0}, 17 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 18 } 19 20 // Process test cases. 21 for _, value := range testCases { 22 if decoded, err := DecodeBase62(EncodeBase62(value)); err != nil { 23 t.Error("unable to decode value:", err) 24 } else if !bytes.Equal(decoded, value) { 25 t.Error("decoded bytes do not match original") 26 } 27 } 28 }