From 22b9490f67d44784820f261541656ec3cfe0393e Mon Sep 17 00:00:00 2001 From: dojutsu-user Date: Sat, 7 Sep 2024 16:55:22 +0530 Subject: [PATCH] Add UTs --- binder/mapping_test.go | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/binder/mapping_test.go b/binder/mapping_test.go index aec91ff2be..af29b16c00 100644 --- a/binder/mapping_test.go +++ b/binder/mapping_test.go @@ -1,6 +1,7 @@ package binder import ( + "errors" "reflect" "testing" @@ -29,3 +30,50 @@ func Test_EqualFieldType(t *testing.T) { require.True(t, equalFieldType(&user, reflect.Int, "AGE")) require.True(t, equalFieldType(&user, reflect.Int, "age")) } + +func Test_ParseParamSquareBrackets(t *testing.T) { + tests := []struct { + input string + expected string + err error + }{ + { + input: "foo[bar]", + expected: "foo.bar", + err: nil, + }, + { + input: "foo[bar][baz]", + expected: "foo.bar.baz", + err: nil, + }, + { + input: "foo[bar", + expected: "", + err: errors.New("unmatched brackets"), + }, + { + input: "foo[bar][baz", + expected: "", + err: errors.New("unmatched brackets"), + }, + { + input: "foo]bar[", + expected: "", + err: errors.New("unmatched brackets"), + }, + } + + for _, tt := range tests { + t.Run(tt.input, func(t *testing.T) { + result, err := parseParamSquareBrackets(tt.input) + if tt.err != nil { + require.Error(t, err) + require.EqualError(t, err, tt.err.Error()) + } else { + require.NoError(t, err) + require.Equal(t, tt.expected, result) + } + }) + } +}