-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrim_test.go
56 lines (53 loc) · 1.6 KB
/
trim_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
package doris
import (
"testing"
"github.com/stretchr/testify/require"
pb "libs.altipla.consulting/hosting/testdata"
)
func TestTrimStrings(t *testing.T) {
in := &pb.TrimTest{
Direct: " direct\n\t",
Sub: &pb.Message{
Child: " child",
RepeatedChild: []string{" repeated child1", "repeated child2 "},
},
Map: map[string]string{
" key": " value",
},
List: []string{" item"},
Mapsub: map[string]*pb.Message{
" key": {
Child: " mapsub child",
},
},
Oneof1: &pb.TrimTest_OneofDirect1{
OneofDirect1: " oneof_direct1",
},
Oneof2: &pb.TrimTest_OneofSub2{
OneofSub2: &pb.Message{
Child: " oneof_child",
},
},
RepeatedMessage: []*pb.Message{
{Child: " repeated1"},
{Child: "repeated2 "},
},
Enum: pb.TrimTest_TEST_FOO,
}
out := trimMessage(in.ProtoReflect()).Interface().(*pb.TrimTest)
require.Equal(t, out.Direct, "direct")
require.Equal(t, out.Sub.Child, "child")
require.Equal(t, out.Sub.RepeatedChild, []string{"repeated child1", "repeated child2"})
require.Equal(t, out.Map, map[string]string{"key": "value"})
require.Nil(t, out.Empty)
require.Equal(t, out.List, []string{"item"})
require.Contains(t, out.Mapsub, "key")
require.Equal(t, out.Mapsub["key"].Child, "mapsub child")
require.Len(t, out.Mapsub, 1)
require.Equal(t, out.GetOneofDirect1(), "oneof_direct1")
require.Equal(t, out.GetOneofSub2().Child, "oneof_child")
require.Len(t, out.RepeatedMessage, 2)
require.Equal(t, out.RepeatedMessage[0].Child, "repeated1")
require.Equal(t, out.RepeatedMessage[1].Child, "repeated2")
require.Equal(t, out.Enum, pb.TrimTest_TEST_FOO)
}