-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathunmarshal_test.go
More file actions
39 lines (36 loc) · 1001 Bytes
/
unmarshal_test.go
File metadata and controls
39 lines (36 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package ipldgit
import (
"fmt"
"strings"
"testing"
basicnode "github.com/ipld/go-ipld-prime/node/basic"
)
func TestUnmarshalError(t *testing.T) {
tests := []struct {
name string
input string
want string
}{
{"Empty", "", "unexpected EOF"},
{"Whitespace", " ", "unrecognized object type"},
{"NoSpace", "foo", "unexpected EOF"},
{"BadType", "foo ", "unrecognized object type"},
}
for _, test := range tests {
t.Run("Decode/"+test.name, func(t *testing.T) {
nb := basicnode.Prototype.Any.NewBuilder()
err := Decode(nb, strings.NewReader(test.input))
got := fmt.Sprint(err)
if !strings.Contains(got, test.want) {
t.Fatalf("Decode(%q) got %q, want %q", test.input, got, test.want)
}
})
t.Run("ParseObject/"+test.name, func(t *testing.T) {
_, err := ParseObject(strings.NewReader(test.input))
got := fmt.Sprint(err)
if !strings.Contains(got, test.want) {
t.Fatalf("ParseObject(%q) got %q, want %q", test.input, got, test.want)
}
})
}
}