-
Notifications
You must be signed in to change notification settings - Fork 1
/
data_types_test.go
42 lines (38 loc) · 1.05 KB
/
data_types_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
36
37
38
39
40
41
42
package sashay_test
import (
"fmt"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/rgalanakis/sashay"
)
func ExampleSimpleDataTyper() {
dt := sashay.SimpleDataTyper("string", "date-time")
fields := sashay.ObjectFields{}
dt(sashay.NewField("abc"), fields)
fmt.Println("Type:", fields["type"], "Format:", fields["format"])
// Output:
// Type: string Format: date-time
}
func ExampleChainDataTyper() {
dt := sashay.ChainDataTyper(
sashay.SimpleDataTyper("string", "format1"),
func(_ sashay.Field, of sashay.ObjectFields) {
of["format"] = "format2"
})
fields := sashay.ObjectFields{}
dt(sashay.NewField("abc"), fields)
fmt.Println("Type:", fields["type"], "Format:", fields["format"])
// Output:
// Type: string Format: format2
}
var _ = Describe("Data typing", func() {
Describe("BuiltinDataTyperFor", func() {
It("uses the noop typer for a non-builtin type", func() {
type T struct{}
dt := sashay.BuiltinDataTyperFor(T{})
of := sashay.ObjectFields{}
dt(sashay.Field{}, of)
Expect(of).To(BeEmpty())
})
})
})