feature/goctl-api-swagger (#4780)

This commit is contained in:
kesonan
2025-04-17 22:38:55 +08:00
committed by GitHub
parent 801c283478
commit 9c478626d2
38 changed files with 2445 additions and 23 deletions

View File

@@ -3,6 +3,7 @@ package util
import (
"strings"
"testing"
"unicode"
"github.com/stretchr/testify/assert"
)
@@ -72,3 +73,67 @@ func TestEscapeGoKeyword(t *testing.T) {
assert.False(t, isGolangKeyword(strings.Title(k)))
}
}
func TestFieldsAndTrimSpace(t *testing.T) {
testCases := []struct {
name string
input string
delimiter func(r rune) bool
expected []string
}{
{
name: "Comma-separated values",
input: "a, b, c",
delimiter: func(r rune) bool { return r == ',' },
expected: []string{"a", " b", " c"},
},
{
name: "Space-separated values",
input: "a b c",
delimiter: unicode.IsSpace,
expected: []string{"a", "b", "c"},
},
{
name: "Mixed whitespace",
input: "a\tb\nc",
delimiter: unicode.IsSpace,
expected: []string{"a", "b", "c"},
},
{
name: "Empty input",
input: "",
delimiter: unicode.IsSpace,
expected: []string(nil),
},
{
name: "Trailing and leading spaces",
input: " a , b , c ",
delimiter: func(r rune) bool { return r == ',' },
expected: []string{" a ", " b ", " c "},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := FieldsAndTrimSpace(tc.input, tc.delimiter)
assert.Equal(t, tc.expected, result)
})
}
}
func TestUnquote(t *testing.T) {
testCases := []struct {
input string
expected string
}{
{input: `"hello"`, expected: `hello`},
{input: "`world`", expected: `world`},
{input: `"foo'bar"`, expected: `foo'bar`},
{input: "", expected: ""},
}
for _, tc := range testCases {
result := Unquote(tc.input)
assert.Equal(t, tc.expected, result)
}
}