forked from project-dalec/dalec
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspec_test.go
More file actions
36 lines (28 loc) · 763 Bytes
/
spec_test.go
File metadata and controls
36 lines (28 loc) · 763 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
package dalec
import (
"encoding/json"
"testing"
"time"
"github.com/goccy/go-yaml"
"gotest.tools/v3/assert"
"gotest.tools/v3/assert/cmp"
)
func TestDate(t *testing.T) {
expect := "2023-10-01"
expectTime, err := time.Parse(time.DateOnly, expect)
assert.NilError(t, err)
d := Date{Time: expectTime}
assert.Check(t, cmp.Equal(d.Format(time.DateOnly), expect))
dtJSON, err := json.Marshal(d)
assert.NilError(t, err)
dtYAML, err := yaml.Marshal(d)
assert.NilError(t, err)
var d2 Date
err = json.Unmarshal(dtJSON, &d2)
assert.NilError(t, err)
assert.Check(t, cmp.Equal(d2.Format(time.DateOnly), expect))
d3 := Date{}
err = yaml.Unmarshal(dtYAML, &d3)
assert.NilError(t, err)
assert.Check(t, cmp.Equal(d3.Format(time.DateOnly), expect))
}