github.com/andeya/ameda@v1.5.3/export_test.go (about) 1 // Copyright 2017 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package ameda 6 7 import ( 8 "math" 9 "strconv" 10 "testing" 11 12 "github.com/stretchr/testify/assert" 13 ) 14 15 var ( 16 BitSizeError = bitSizeError 17 BaseError = baseError 18 ) 19 20 func TestStrconv62(t *testing.T) { 21 a := FormatInt(math.MaxInt64, 62) 22 // FormatInt: base10=9223372036854775807 -> base62=aZl8N0y58M7 23 t.Logf("FormatInt: base10=%d -> base62=%s", math.MaxInt64, a) 24 i, err := ParseInt(a, 62, 64) 25 assert.NoError(t, err) 26 assert.Equal(t, int64(math.MaxInt64), i) 27 t.Logf("ParseInt base62: bitSize=64, num=%d", i) 28 i, err = ParseInt(a, 62, 32) 29 assert.EqualError(t, err.(*strconv.NumError).Err, strconv.ErrRange.Error()) 30 assert.Equal(t, int64(math.MaxInt32), i) 31 32 a = FormatInt(math.MinInt64, 62) 33 // FormatInt: base10=-9223372036854775808 -> base62=-aZl8N0y58M8 34 t.Logf("FormatInt: base10=%d -> base62=%s", math.MinInt64, a) 35 i, err = ParseInt(a, 62, 64) 36 assert.NoError(t, err) 37 assert.Equal(t, int64(math.MinInt64), i) 38 t.Logf("ParseInt base62: bitSize=64, num=%d", i) 39 i, err = ParseInt(a, 62, 32) 40 assert.EqualError(t, err.(*strconv.NumError).Err, strconv.ErrRange.Error()) 41 assert.Equal(t, int64(math.MinInt32), i) 42 }