1 Star 0 Fork 0

CNCF/devstatscode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
unicode_test.go 1.66 KB
一键复制 编辑 原始数据 按行查看 历史
Łukasz Gryglicki 提交于 2021-01-30 18:21 +08:00 . New test case
package devstatscode
import (
"testing"
lib "github.com/cncf/devstatscode"
)
func TestStripUnicode(t *testing.T) {
// Test cases
var testCases = []struct {
str, expected string
}{
{str: "hello", expected: "hello"},
{str: "control:\t\n\r", expected: "control:"},
{str: "gżegżółką", expected: "gzegzoka"},
{str: "net_ease_网易有态", expected: "net_ease_"},
}
// Execute test cases
for index, test := range testCases {
expected := test.expected
got := lib.StripUnicode(test.str)
if got != expected {
t.Errorf(
"test number %d, expected %v, got %v",
index+1, expected, got,
)
}
}
}
// NormalizeName - clean DB string from ', ", -, /, ., " ", trim leading and trailing space, lowercase
// Normalize Unicode characters
func TestNormalizeName(t *testing.T) {
// Test cases
var testCases = []struct {
str, expected string
}{
{str: "hello", expected: "hello"},
{str: "control:\t\n\r", expected: "control"},
{str: "gżegżółką", expected: "gzegzoka"},
{str: "net_ease_网易有态", expected: "netease"},
{str: " see;hello-world/k8s.io, said: HE`MAN ", expected: "seehelloworldk8siosaidheman"},
{str: "Contributions (issues, PRs, git pushes)", expected: "contributionsissuesprsgitpushes"},
{str: "Exclude (ro[bot]nik)", expected: "excluderobotnik"},
{str: "comment\"sallcoted'ivoire", expected: "commentsallcotedivoire"},
{str: "Piraeus-Datastore", expected: "piraeusdatastore"},
}
// Execute test cases
for index, test := range testCases {
expected := test.expected
got := lib.NormalizeName(test.str)
if got != expected {
t.Errorf(
"test number %d, expected %v, got %v",
index+1, expected, got,
)
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cncf/devstatscode.git
git@gitee.com:cncf/devstatscode.git
cncf
devstatscode
devstatscode
master

搜索帮助