-
Notifications
You must be signed in to change notification settings - Fork 3
/
convert_recipes_test.go
60 lines (51 loc) · 1.88 KB
/
convert_recipes_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
package convert_test
import (
"testing"
"github.com/Eun/go-convert"
"github.com/Eun/go-convert/internal/testhelpers"
)
type StructWithConvertRecipesFunc struct {
str string
}
func (StructWithConvertRecipesFunc) ConvertRecipes() []convert.Recipe {
return []convert.Recipe{
convert.MustMakeRecipe(func(_ convert.Converter, in StructWithConvertRecipesFunc, out *string) error {
*out = in.str
return nil
}),
convert.MustMakeRecipe(func(_ convert.Converter, in string, out *StructWithConvertRecipesFunc) error {
out.str = in
return nil
}),
}
}
type StructWithConvertRecipesFuncPtr struct {
str string
}
func (*StructWithConvertRecipesFuncPtr) ConvertRecipes() []convert.Recipe {
return []convert.Recipe{
convert.MustMakeRecipe(func(_ convert.Converter, in StructWithConvertRecipesFuncPtr, out *string) error {
*out = in.str
return nil
}),
convert.MustMakeRecipe(func(_ convert.Converter, in string, out *StructWithConvertRecipesFuncPtr) error {
out.str = in
return nil
}),
}
}
func TestConvertRecipes(t *testing.T) {
tests := []testhelpers.TestCase{
{StructWithConvertRecipesFunc{"Hello World"}, "", "Hello World", "", nil},
{&StructWithConvertRecipesFunc{"Hello World"}, "", "Hello World", "", nil},
{StructWithConvertRecipesFuncPtr{"Hello World"}, "", "Hello World", "", nil},
{&StructWithConvertRecipesFuncPtr{"Hello World"}, "", "Hello World", "", nil},
{"Hello World", StructWithConvertRecipesFunc{}, StructWithConvertRecipesFunc{"Hello World"}, "", nil},
{"Hello World", &StructWithConvertRecipesFunc{}, &StructWithConvertRecipesFunc{"Hello World"}, "", nil},
{"Hello World", StructWithConvertRecipesFuncPtr{}, StructWithConvertRecipesFuncPtr{"Hello World"}, "", nil},
{"Hello World", &StructWithConvertRecipesFuncPtr{}, &StructWithConvertRecipesFuncPtr{"Hello World"}, "", nil},
}
for i, test := range tests {
testhelpers.RunTest(t, test, i)
}
}