forked from swaggest/jsonschema-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdate_test.go
More file actions
30 lines (22 loc) · 686 Bytes
/
date_test.go
File metadata and controls
30 lines (22 loc) · 686 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
package jsonschema_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/swaggest/jsonschema-go"
)
func TestDate_MarshalText(t *testing.T) {
var d jsonschema.Date
assert.NoError(t, d.UnmarshalText([]byte("2021-05-08")))
b, err := d.MarshalText()
assert.NoError(t, err)
assert.Equal(t, "2021-05-08", string(b))
assert.Error(t, d.UnmarshalText([]byte("2021-05-088")))
}
func TestDate_MarshalJSON(t *testing.T) {
var d jsonschema.Date
assert.NoError(t, d.UnmarshalJSON([]byte(`"2021-05-08"`)))
b, err := d.MarshalJSON()
assert.NoError(t, err)
assert.Equal(t, `"2021-05-08"`, string(b))
assert.Error(t, d.UnmarshalJSON([]byte(`""2021-05-088"`)))
}