mirror of
https://github.com/argoproj/argo-cd
synced 2026-05-24 09:50:08 +00:00
* chore: enable unused-parameter from revive Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> * apply recommandations Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> --------- Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
60 lines
1.1 KiB
Go
60 lines
1.1 KiB
Go
package strings
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestNewExprs(t *testing.T) {
|
|
funcs := []string{
|
|
"ReplaceAll",
|
|
"ToUpper",
|
|
"ToLower",
|
|
}
|
|
for _, fn := range funcs {
|
|
stringsExprs := NewExprs()
|
|
_, hasFunc := stringsExprs[fn]
|
|
assert.True(t, hasFunc)
|
|
}
|
|
}
|
|
|
|
func TestReplaceAll(t *testing.T) {
|
|
exprs := NewExprs()
|
|
input := "test_replace"
|
|
expected := "test=replace"
|
|
replaceAllFn, ok := exprs["ReplaceAll"].(func(s, old, new string) string)
|
|
assert.True(t, ok)
|
|
actual := replaceAllFn(input, "_", "=")
|
|
assert.Equal(t, expected, actual)
|
|
}
|
|
|
|
func TestUpperAndLower(t *testing.T) {
|
|
testCases := []struct {
|
|
fn string
|
|
input string
|
|
expected string
|
|
}{
|
|
{
|
|
fn: "ToUpper",
|
|
input: "test",
|
|
expected: "TEST",
|
|
},
|
|
{
|
|
fn: "ToLower",
|
|
input: "TEST",
|
|
expected: "test",
|
|
},
|
|
}
|
|
exprs := NewExprs()
|
|
|
|
for _, testCase := range testCases {
|
|
t.Run("With success case: Func: "+testCase.fn, func(t *testing.T) {
|
|
toUpperFn, ok := exprs[testCase.fn].(func(s string) string)
|
|
assert.True(t, ok)
|
|
|
|
actual := toUpperFn(testCase.input)
|
|
assert.Equal(t, testCase.expected, actual)
|
|
})
|
|
}
|
|
}
|