github.com/artisanhe/tools@v1.0.1-0.20210607022958-19a8fef2eb04/validate/validatetpl/string_test.go (about)

     1  package validatetpl
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestNewValidateChar(t *testing.T) {
    10  	tt := assert.New(t)
    11  	{
    12  		valid, _ := NewValidateChar(0, 2)("中文")
    13  		tt.True(valid)
    14  	}
    15  	{
    16  		valid, msg := NewValidateChar(0, 2)("中文中文")
    17  		tt.False(valid)
    18  		tt.Equal("字符串字数不在[0, 2]范围内,当前长度: 4", msg)
    19  	}
    20  }