-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunmarshal_test.go
More file actions
37 lines (34 loc) · 798 Bytes
/
unmarshal_test.go
File metadata and controls
37 lines (34 loc) · 798 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
package zon
import (
"reflect"
"testing"
)
func TestUnmarshal(t *testing.T) {
for _, tt := range []struct {
name string
data string
v any
}{
{"bool true", "true", new(bool)},
{"int", "42", new(int)},
{"float", "3.14", new(float64)},
{"string", `"hello"`, new(string)},
{"slice", ".{1,2,3}", &[]int{}},
{"map", ".{.a = 1}", &map[string]int{}},
{"struct", ".{.x = 5, .y = .{.z = .{1,2}}}", &struct {
X int `zon:"x"`
Y struct {
Z []int `zon:"z"`
} `zon:"y"`
}{}},
} {
t.Run(tt.name, func(t *testing.T) {
if err := Unmarshal([]byte(tt.data), tt.v); err != nil {
t.Errorf("Unmarshal(%q) returned error: %v", tt.data, err)
}
if reflect.ValueOf(tt.v).Elem().IsZero() {
t.Errorf("Unmarshal did not set value for %q", tt.data)
}
})
}
}