You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
1.8 KiB
Go
102 lines
1.8 KiB
Go
2 years ago
|
package test
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"strings"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestExecutor_Run(t *testing.T) {
|
||
|
executor := NewExecutor[string, string]()
|
||
|
executor.Add([]Data[string, string]{
|
||
|
{
|
||
|
Name: "empty",
|
||
|
},
|
||
|
{
|
||
|
Name: "snake_case",
|
||
|
input: "A_B_C",
|
||
|
want: "a_b_c",
|
||
|
},
|
||
|
{
|
||
|
Name: "camel_case",
|
||
|
input: "AaBbCc",
|
||
|
want: "aabbcc",
|
||
|
},
|
||
|
}...)
|
||
|
executor.Run(t, func(s string) string {
|
||
|
return strings.ToLower(s)
|
||
|
})
|
||
|
}
|
||
|
|
||
|
func TestExecutor_RunE(t *testing.T) {
|
||
|
var dummyError = errors.New("dummy error")
|
||
|
executor := NewExecutor[string, string]()
|
||
|
executor.Add([]Data[string, string]{
|
||
|
{
|
||
|
Name: "empty",
|
||
|
},
|
||
|
{
|
||
|
Name: "snake_case",
|
||
|
input: "A_B_C",
|
||
|
want: "a_b_c",
|
||
|
},
|
||
|
{
|
||
|
Name: "camel_case",
|
||
|
input: "AaBbCc",
|
||
|
want: "aabbcc",
|
||
|
},
|
||
|
{
|
||
|
Name: "invalid_input",
|
||
|
input: "😄",
|
||
|
E: dummyError,
|
||
|
},
|
||
|
}...)
|
||
|
executor.RunE(t, func(s string) (string, error) {
|
||
|
for _, r := range s {
|
||
|
if r == '_' || r >= 'a' && r <= 'z' || r >= 'A' && r <= 'Z' {
|
||
|
continue
|
||
|
}
|
||
|
return "", dummyError
|
||
|
}
|
||
|
return strings.ToLower(s), nil
|
||
|
})
|
||
|
}
|
||
|
|
||
|
func TestWithComparison(t *testing.T) {
|
||
|
var dummyError = errors.New("dummy error")
|
||
|
executor := NewExecutor[string, string](WithComparison[string, string](func(t *testing.T, expected, actual string) bool {
|
||
|
return assert.Equal(t, expected, actual)
|
||
|
}))
|
||
|
executor.Add([]Data[string, string]{
|
||
|
{
|
||
|
Name: "empty",
|
||
|
},
|
||
|
{
|
||
|
Name: "snake_case",
|
||
|
input: "A_B_C",
|
||
|
want: "a_b_c",
|
||
|
},
|
||
|
{
|
||
|
Name: "camel_case",
|
||
|
input: "AaBbCc",
|
||
|
want: "aabbcc",
|
||
|
},
|
||
|
{
|
||
|
Name: "invalid_input",
|
||
|
input: "😄",
|
||
|
E: dummyError,
|
||
|
},
|
||
|
}...)
|
||
|
executor.RunE(t, func(s string) (string, error) {
|
||
|
for _, r := range s {
|
||
|
if r == '_' || r >= 'a' && r <= 'z' || r >= 'A' && r <= 'Z' {
|
||
|
continue
|
||
|
}
|
||
|
return "", dummyError
|
||
|
}
|
||
|
return strings.ToLower(s), nil
|
||
|
})
|
||
|
}
|