2017-06-24 19:12:15 +08:00
|
|
|
package variables
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
type interfaceToBool struct {
|
|
|
|
Value interface{}
|
|
|
|
Result bool
|
|
|
|
}
|
|
|
|
|
|
|
|
var testIsMap = []*interfaceToBool{
|
2017-06-25 17:02:16 +08:00
|
|
|
{"teste", false},
|
|
|
|
{453478, false},
|
|
|
|
{-984512, false},
|
|
|
|
{true, false},
|
|
|
|
{map[string]bool{}, true},
|
|
|
|
{map[int]bool{}, true},
|
|
|
|
{map[interface{}]bool{}, true},
|
|
|
|
{[]string{}, false},
|
2017-06-24 19:12:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestIsMap(t *testing.T) {
|
|
|
|
for _, test := range testIsMap {
|
|
|
|
if IsMap(test.Value) != test.Result {
|
|
|
|
t.Errorf("Incorrect value on IsMap for %v; want: %v; got: %v", test.Value, test.Result, !test.Result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var testIsSlice = []*interfaceToBool{
|
2017-06-25 17:02:16 +08:00
|
|
|
{"teste", false},
|
|
|
|
{453478, false},
|
|
|
|
{-984512, false},
|
|
|
|
{true, false},
|
|
|
|
{map[string]bool{}, false},
|
|
|
|
{map[int]bool{}, false},
|
|
|
|
{map[interface{}]bool{}, false},
|
|
|
|
{[]string{}, true},
|
|
|
|
{[]int{}, true},
|
|
|
|
{[]bool{}, true},
|
|
|
|
{[]interface{}{}, true},
|
2017-06-24 19:12:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestIsSlice(t *testing.T) {
|
|
|
|
for _, test := range testIsSlice {
|
|
|
|
if IsSlice(test.Value) != test.Result {
|
|
|
|
t.Errorf("Incorrect value on IsSlice for %v; want: %v; got: %v", test.Value, test.Result, !test.Result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|