gitee.com/h79/goutils@v1.22.10/common/stringutil/stringutil_test.go (about)

     1  package stringutil
     2  
     3  import (
     4  	"regexp"
     5  	"testing"
     6  )
     7  
     8  func TestStringValidate(t *testing.T) {
     9  	if !IsNameValidate("hullo001") {
    10  		t.Error("name is invalidate")
    11  	}
    12  
    13  	if !IsPhoneValidate("23622283547") {
    14  		t.Error("23622283547 number is invalidate")
    15  	}
    16  
    17  	if !IsPhoneValidate("13844486306-44") {
    18  		t.Error("13844486306 number is invalidate")
    19  	}
    20  
    21  	if !IsPhoneExtValidate("13844486306-44466") {
    22  		t.Error("13844486306 number is invalidate")
    23  	}
    24  
    25  	if !HasChinaPhoneLegal("sdsxvxvx13844486306-444456") {
    26  		t.Error("13844486306 number is invalidate")
    27  	}
    28  
    29  	if !IsEmailValidate("sybgo@sina.com") {
    30  		t.Error("email is invalidate")
    31  	}
    32  	//
    33  	var text = "SFSF<a href=\"https://wx889ba45762981adb.wxcp.qidian.com/ubz/QKcs9\">惊喜+1,充9.9送9.9</a>\n\n<a href=\"https://wx889ba45762981adb.wxcp.qidian.com/pov/QKcs5\">惊喜+2,充45送45</a>\n\n<a href=\"https://wx889ba45762981adb.wxcp.qidian.com/ykv/QKcsl\">惊喜+3,充95送95</a>"
    34  
    35  	reg, er := regexp.Compile(`<a href=(.*)>(.*)</a>`)
    36  	if er != nil {
    37  		t.Error("xxx", er)
    38  		return
    39  	}
    40  	aa := reg.FindAllStringSubmatch(text, 10)
    41  	t.Log("regexp:", aa)
    42  }
    43  
    44  func TestBytesTo(t *testing.T) {
    45  	buff := []byte{0, 0, 0, 19, 57, 48}
    46  	buff1 := []byte{0, 12, 0, 19, 57, 48}
    47  
    48  	l := BytesTo[int32](buff[0:4], 0)
    49  	t.Log(l)
    50  	ll := BytesToUInt32(buff1[0:4])
    51  	t.Log(ll)
    52  }
    53  
    54  func TestNumberValue(t *testing.T) {
    55  	num := NumberWithString("%0.2", 3)
    56  	t.Logf("%v", num.ToString(3))
    57  
    58  	t.Log(Decimal(num.Decimal))
    59  
    60  	var xx = []interface{}{1, 2, 3, 5}
    61  	t.Log(ATo(xx))
    62  }