1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-09 23:22:28 +08:00

feat: add IsGBK validator

This commit is contained in:
dudaodong
2022-12-09 17:36:59 +08:00
parent d59259bbe0
commit af5cfe6da1
4 changed files with 53 additions and 0 deletions

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))
}