Check errors

This commit is contained in:
Fedor Korotkiy 2020-04-16 15:14:19 +03:00
parent a270d1ed87
commit 63272619d9

View file

@ -2,6 +2,7 @@ package jsonlist
import (
"bytes"
"encoding/json"
"reflect"
"testing"
@ -47,8 +48,15 @@ func TestJsonList(t *testing.T) {
emptySlice = reflect.New(reflect.TypeOf(test.value))
require.NoError(t, Unmarshal(bytes.NewBufferString(test.js), emptySlice.Interface()))
require.NoError(t, Unmarshal(&buf, emptySlice.Interface()))
require.Equal(t, test.value, emptySlice.Elem().Interface())
})
}
}
func TestErrors(t *testing.T) {
var buf bytes.Buffer
require.Equal(t, &json.UnsupportedTypeError{Type: reflect.TypeOf([]int{})}, Unmarshal(&buf, []int{}))
require.Equal(t, &json.UnsupportedTypeError{Type: reflect.TypeOf(1)}, Marshal(&buf, 1))
}