feat: add IsGBK validator

This commit is contained in:
dudaodong committed 2022-12-09 17:36:59 +08:00
1 parent d59259bbe0
commit af5cfe6da1
4 files changed
+53

No files matched your search

+12
View File
@@ -4,8 +4,10 @@ import (
"fmt"
"testing"
"time"
"unicode/utf8"
"github.com/duke-git/lancet/v2/internal"
"golang.org/x/text/encoding/simplifiedchinese"
)
func TestIsAllUpper(t *testing.T) {
@@ -388,3 +390,13 @@ func TestIsZeroValue(t *testing.T) {
assert.Equal(false, IsZeroValue(value))
}
}
func TestIsGBK(t *testing.T) {
assert := internal.NewAssert(t, "TestIsGBK")
str := "你好"
gbkData, _ := simplifiedchinese.GBK.NewEncoder().Bytes([]byte(str))
assert.Equal(true, IsGBK(gbkData))
assert.Equal(false, utf8.Valid(gbkData))
}