2018-10-15 11:02:48 -07:00
|
|
|
package subspace
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
type testparams struct {
|
|
|
|
i int64
|
|
|
|
b bool
|
|
|
|
}
|
|
|
|
|
2019-02-04 18:13:04 -08:00
|
|
|
func (tp *testparams) ParamSetPairs() ParamSetPairs {
|
|
|
|
return ParamSetPairs{
|
2018-10-15 11:02:48 -07:00
|
|
|
{[]byte("i"), &tp.i},
|
|
|
|
{[]byte("b"), &tp.b},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-04 18:13:04 -08:00
|
|
|
func TestKeyTable(t *testing.T) {
|
|
|
|
table := NewKeyTable()
|
2018-10-15 11:02:48 -07:00
|
|
|
|
|
|
|
require.Panics(t, func() { table.RegisterType([]byte(""), nil) })
|
|
|
|
require.Panics(t, func() { table.RegisterType([]byte("!@#$%"), nil) })
|
|
|
|
require.Panics(t, func() { table.RegisterType([]byte("hello,"), nil) })
|
|
|
|
require.Panics(t, func() { table.RegisterType([]byte("hello"), nil) })
|
|
|
|
|
|
|
|
require.NotPanics(t, func() { table.RegisterType([]byte("hello"), bool(false)) })
|
|
|
|
require.NotPanics(t, func() { table.RegisterType([]byte("world"), int64(0)) })
|
|
|
|
require.Panics(t, func() { table.RegisterType([]byte("hello"), bool(false)) })
|
|
|
|
|
|
|
|
require.NotPanics(t, func() { table.RegisterParamSet(&testparams{}) })
|
|
|
|
require.Panics(t, func() { table.RegisterParamSet(&testparams{}) })
|
|
|
|
}
|