-
Notifications
You must be signed in to change notification settings - Fork 1
/
yaml_test.go
35 lines (30 loc) · 909 Bytes
/
yaml_test.go
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
package orderedmap
import (
"testing"
"time"
"github.com/alecthomas/assert/v2"
"gopkg.in/yaml.v3"
)
func TestOrderedMap_MarshalYAML(t *testing.T) {
now := time.Now().UTC().Truncate(time.Second)
got, err := yaml.Marshal(OrderedMap[string, any]{
{"name", "John"},
{"age", 30},
{"active", true},
{"last_access_time", now},
})
assert.NoError(t, err)
assert.Equal(t, "name: John\nage: 30\nactive: true\nlast_access_time: "+now.Format(time.RFC3339Nano)+"\n", string(got))
}
func TestOrderedMap_UnmarshalYAML(t *testing.T) {
now := time.Now().UTC().Truncate(time.Second)
var got OrderedMap[string, any]
err := yaml.Unmarshal([]byte("name: John\nage: 30\nactive: true\nlast_access_time: "+now.Format(time.RFC3339Nano)+"\n"), &got)
assert.NoError(t, err)
assert.Equal(t, OrderedMap[string, any]{
{"name", "John"},
{"age", 30},
{"active", true},
{"last_access_time", now},
}, got)
}