示例#1
0
// StrIsAlNum returns true if a string consists of characters a-zA-Z0-9_
func TestStrIsAlNum(t *testing.T) {
	tests := []struct {
		have string
		want bool
	}{
		{"Hello World", false},
		{"HelloWorld", true},
		{"Hello1World", true},
		{"Hello0123456789", true},
		{"Hello0123456789€", false},
		{" Hello0123456789", false},
	}

	for _, test := range tests {
		assert.True(t, util.StrIsAlNum(test.have) == test.want, "%#v", test)
	}
}
示例#2
0
// BenchmarkStrIsAlNum	10000000	       132 ns/op	       0 B/op	       0 allocs/op
func BenchmarkStrIsAlNum(b *testing.B) {
	b.ReportAllocs()
	for i := 0; i < b.N; i++ {
		benchStrIsAlNum = util.StrIsAlNum("Hello1WorldOfGophers")
	}
}