Пример #1
0
// ValidateStoreCode checks if a store code is valid. Returns an ErrStoreCodeInvalid if the
// first letter is not a-zA-Z and followed by a-zA-Z0-9_ or store code length is greater than 32 characters.
func ValidateStoreCode(c string) error {
	if c == "" || len(c) > 32 {
		return ErrStoreCodeInvalid
	}
	c1 := c[0]
	if false == ((c1 >= 'a' && c1 <= 'z') || (c1 >= 'A' && c1 <= 'Z')) {
		return ErrStoreCodeInvalid
	}
	if false == utils.StrIsAlNum(c) {
		return ErrStoreCodeInvalid
	}
	return nil
}
Пример #2
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, utils.StrIsAlNum(test.have) == test.want, "%#v", test)
	}
}
Пример #3
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 = utils.StrIsAlNum("Hello1WorldOfGophers")
	}
}