golib/helper/str_helper_test.go

121 lines
2.3 KiB
Go
Raw Normal View History

2023-06-15 21:22:51 +08:00
//
// str_helper_test.go
// Copyright (C) 2022 tiglog <me@tiglog.com>
//
// Distributed under terms of the MIT license.
//
package helper_test
import (
"fmt"
"testing"
2023-06-15 21:38:12 +08:00
"git.hexq.cn/tiglog/golib/gtest"
"git.hexq.cn/tiglog/golib/helper"
2023-06-15 21:22:51 +08:00
)
func TestIsString(t *testing.T) {
v1 := 111
r1 := helper.IsString(v1)
gtest.False(t, r1)
v2 := "hello"
r2 := helper.IsString(v2)
gtest.True(t, r2)
}
func TestRandString(t *testing.T) {
r1 := helper.RandString(10)
fmt.Println(r1)
gtest.NotEqual(t, "", r1)
gtest.Equal(t, 10, len(r1))
}
func TestUcFirst(t *testing.T) {
v1 := "hello"
r1 := helper.UcFirst(v1)
gtest.Equal(t, "Hello", r1)
v2 := "hello world"
r2 := helper.UcFirst(v2)
gtest.Equal(t, "Hello world", r2)
v3 := "helloWorld"
r3 := helper.UcFirst(v3)
gtest.Equal(t, "HelloWorld", r3)
}
func TestGenId(t *testing.T) {
s1 := helper.GenId()
s2 := helper.GenId()
s3 := helper.GenId()
s4 := helper.GenId()
fmt.Println("gen id: ", s4)
gtest.NotNil(t, s1)
gtest.NotNil(t, s2)
gtest.NotNil(t, s3)
gtest.NotNil(t, s4)
gtest.NotEqual(t, s1, s2)
gtest.NotEqual(t, s1, s3)
gtest.NotEqual(t, s1, s4)
// fmt.Println(s1)
// fmt.Println(s2)
// fmt.Println(s3)
// fmt.Println(s4)
}
func TestUniq(t *testing.T) {
s1 := helper.Uniq(1)
fmt.Println("s1=", s1)
gtest.True(t, 1 == len(s1))
s12 := helper.Uniq(6)
s13 := helper.Uniq(6)
s14 := helper.Uniq(6)
s15 := helper.Uniq(6)
fmt.Println("s12..15", s12, s13, s14, s15)
gtest.NotNil(t, s12)
gtest.NotNil(t, s13)
gtest.NotNil(t, s14)
gtest.NotNil(t, s15)
gtest.NotEqual(t, s12, s13)
gtest.NotEqual(t, s12, s14)
gtest.NotEqual(t, s12, s15)
s2 := helper.Uniq(16)
s3 := helper.Uniq(16)
s4 := helper.Uniq(16)
s5 := helper.Uniq(16)
gtest.NotNil(t, s2)
gtest.NotNil(t, s3)
gtest.NotNil(t, s4)
gtest.NotNil(t, s5)
gtest.NotEqual(t, s2, s3)
gtest.NotEqual(t, s2, s4)
gtest.NotEqual(t, s2, s5)
s6 := helper.Uniq(32)
fmt.Println("s6=", s6)
s7 := helper.Uniq(32)
s8 := helper.Uniq(32)
s9 := helper.Uniq(32)
gtest.NotNil(t, s6)
gtest.NotNil(t, s7)
gtest.NotNil(t, s8)
gtest.NotNil(t, s9)
// fmt.Println("s6789=", s6, s7, s8, s9)
s60 := helper.Uniq(64)
fmt.Println("s60=", s60)
s70 := helper.Uniq(64)
s80 := helper.Uniq(64)
s90 := helper.Uniq(64)
gtest.NotNil(t, s60)
gtest.NotNil(t, s70)
gtest.NotNil(t, s80)
gtest.NotNil(t, s90)
// fmt.Println(s60, s70, s80, s90)
}