github.com/wangyougui/gf/v2@v2.6.5/text/gstr/gstr_z_unit_convert_test.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/wangyougui/gf.
     6  
     7  package gstr_test
     8  
     9  import (
    10  	"testing"
    11  
    12  	"github.com/wangyougui/gf/v2/test/gtest"
    13  	"github.com/wangyougui/gf/v2/text/gstr"
    14  )
    15  
    16  func Test_OctStr(t *testing.T) {
    17  	gtest.C(t, func(t *gtest.T) {
    18  		t.Assert(gstr.OctStr(`\346\200\241`), "怡")
    19  	})
    20  }
    21  
    22  func Test_WordWrap(t *testing.T) {
    23  	gtest.C(t, func(t *gtest.T) {
    24  		t.Assert(gstr.WordWrap("12 34", 2, "<br>"), "12<br>34")
    25  		t.Assert(gstr.WordWrap("12 34", 2, "\n"), "12\n34")
    26  		t.Assert(gstr.WordWrap("我爱 GF", 2, "\n"), "我爱\nGF")
    27  		t.Assert(gstr.WordWrap("A very long woooooooooooooooooord. and something", 7, "<br>"),
    28  			"A very<br>long<br>woooooooooooooooooord.<br>and<br>something")
    29  	})
    30  	// Chinese Punctuations.
    31  	gtest.C(t, func(t *gtest.T) {
    32  		var (
    33  			br      = "                       "
    34  			content = "    DelRouteKeyIPv6    删除VPC内的服务的Route信息;和DelRouteIPv6接口相比,这个接口可以删除满足条件的多条RS\n"
    35  			length  = 120
    36  		)
    37  		wrappedContent := gstr.WordWrap(content, length, "\n"+br)
    38  		t.Assert(wrappedContent, `    DelRouteKeyIPv6    删除VPC内的服务的Route信息;和DelRouteIPv6接口相比,
    39                         这个接口可以删除满足条件的多条RS
    40  `)
    41  	})
    42  }