-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgolf_value_types_test.go
63 lines (51 loc) · 1.24 KB
/
golf_value_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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package golf
import (
"fmt"
"testing"
)
func TestInt(t *testing.T) {
f := Fore("hero", 3)
assertMapLen(t, f, 1)
assertKeyEquals(t, f, "hero", 3)
}
func TestString(t *testing.T) {
f := Fore("hero", "three")
assertMapLen(t, f, 1)
assertKeyEquals(t, f, "hero", "three")
}
func TestStringThatGolfs(t *testing.T) {
s := StringThatGolfs("three")
f := Fore("hero", &s)
t.Log(f)
assertMapLen(t, f, 1)
assertKeyEquals(t, f, "hero.golfer", "three three")
}
func TestNil(t *testing.T) {
f := Fore("hero", nil)
if f != nil {
t.Fatal("not nil")
}
}
func TestStructPointer(t *testing.T) {
f := Fore("test", &StructWithPointer{Foo: &FooStruct{Bar: "value"}})
assertMapLen(t, f, 1)
assertKeyEquals(t, f, "test.foo.Bar", "value")
}
func TestStructNonPointer(t *testing.T) {
f := Fore("test", &StructWithoutPointer{Foo: FooStruct{Bar: "value"}})
assertMapLen(t, f, 1)
assertKeyEquals(t, f, "test.foo.Bar", "value")
}
type StringThatGolfs string
func (s *StringThatGolfs) GolfExportedFields() map[string]interface{} {
return map[string]interface{}{"golfer": fmt.Sprintf("%s %s", *s, *s)}
}
type FooStruct struct {
Bar string
}
type StructWithPointer struct {
Foo *FooStruct `golf:"foo"`
}
type StructWithoutPointer struct {
Foo FooStruct `golf:"foo"`
}