-
Notifications
You must be signed in to change notification settings - Fork 1
/
field_test.go
44 lines (39 loc) · 1.3 KB
/
field_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
43
44
package sashay_test
import (
"fmt"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/rgalanakis/sashay"
"reflect"
)
func ExampleZeroSliceValueField() {
type User struct{}
slice := make([]User, 0)
sliceField := sashay.NewField(slice)
userField := sashay.NewField(User{})
zeroSliceField := sashay.ZeroSliceValueField(reflect.TypeOf(slice))
fmt.Println("sliceField type name:", sliceField.Type)
fmt.Println("userField type name:", userField.Type)
fmt.Println("zeroSliceField type name:", zeroSliceField.Type)
// Output:
// sliceField type name: []sashay_test.User
// userField type name: sashay_test.User
// zeroSliceField type name: sashay_test.User
}
var _ = Describe("Field", func() {
It("can render itself as a string", func() {
f := sashay.NewField(5)
Expect(f.String()).To(Equal("Field{kind: int, type:int}"))
})
})
var _ = Describe("Fields", func() {
Describe("FlattenSliceTypes", func() {
It("replaces Fields with slice types with their underlying value", func() {
intField := sashay.NewField(5)
strSliceField := sashay.NewField([]string{})
flattened := sashay.Fields{intField, strSliceField}.FlattenSliceTypes()
Expect(flattened[0].Kind.String()).To(Equal(reflect.Int.String()))
Expect(flattened[1].Kind.String()).To(Equal(reflect.String.String()))
})
})
})