Skip to content

Commit

Permalink
Add UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
dojutsu-user committed Sep 7, 2024
1 parent a1a7b28 commit 22b9490
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions binder/mapping_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package binder

import (
"errors"
"reflect"
"testing"

Expand Down Expand Up @@ -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 {

Check failure on line 35 in binder/mapping_test.go

View workflow job for this annotation

GitHub Actions / lint

fieldalignment: struct with 48 pointer bytes could be 40 (govet)
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)
}
})
}
}

0 comments on commit 22b9490

Please sign in to comment.