gf/text/gstr/gstr_z_unit_convert_test.go

43 lines
1.4 KiB
Go
Raw Permalink Normal View History

2021-01-17 21:46:25 +08:00
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
2020-02-12 10:48:15 +08:00
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package gstr_test
import (
"testing"
2021-10-11 21:41:56 +08:00
"github.com/gogf/gf/v2/test/gtest"
"github.com/gogf/gf/v2/text/gstr"
2020-02-12 10:48:15 +08:00
)
func Test_OctStr(t *testing.T) {
2020-03-19 22:56:12 +08:00
gtest.C(t, func(t *gtest.T) {
t.Assert(gstr.OctStr(`\346\200\241`), "怡")
2020-02-12 10:48:15 +08:00
})
}
2022-05-13 14:18:51 +08:00
func Test_WordWrap(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
t.Assert(gstr.WordWrap("12 34", 2, "<br>"), "12<br>34")
t.Assert(gstr.WordWrap("12 34", 2, "\n"), "12\n34")
t.Assert(gstr.WordWrap("我爱 GF", 2, "\n"), "我爱\nGF")
t.Assert(gstr.WordWrap("A very long woooooooooooooooooord. and something", 7, "<br>"),
"A very<br>long<br>woooooooooooooooooord.<br>and<br>something")
})
// Chinese Punctuations.
gtest.C(t, func(t *gtest.T) {
var (
br = " "
content = " DelRouteKeyIPv6 删除VPC内的服务的Route信息;和DelRouteIPv6接口相比这个接口可以删除满足条件的多条RS\n"
length = 120
)
wrappedContent := gstr.WordWrap(content, length, "\n"+br)
t.Assert(wrappedContent, ` DelRouteKeyIPv6 删除VPC内的服务的Route信息;和DelRouteIPv6接口相比
这个接口可以删除满足条件的多条RS
`)
})
}