2024-01-17 14:26:33 +00:00
|
|
|
package textutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNormalizeString(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
input string
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
input: "test",
|
|
|
|
expected: "test",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "test test",
|
|
|
|
expected: "test_test",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "test-test",
|
|
|
|
expected: "test_test",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "test_test",
|
|
|
|
expected: "test_test",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "test.test",
|
|
|
|
expected: "test_test",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "test/test",
|
|
|
|
expected: "test_test",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "test/test.test",
|
|
|
|
expected: "test_test_test",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "TestTest",
|
|
|
|
expected: "testtest",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "TestTestTest",
|
|
|
|
expected: "testtesttest",
|
2024-07-17 12:33:49 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
input: ".test//test..test",
|
|
|
|
expected: "test_test_test",
|
2024-01-17 14:26:33 +00:00
|
|
|
}}
|
|
|
|
|
|
|
|
for _, c := range cases {
|
|
|
|
assert.Equal(t, c.expected, NormalizeString(c.input))
|
|
|
|
}
|
|
|
|
}
|