Add: StringUtils.Substring
This commit is contained in:
51
StringUtils_test.go
Normal file
51
StringUtils_test.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package golanghelper_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gitlab-ce.niaulang.com/niau-lang/golanghelper"
|
||||
)
|
||||
|
||||
func TestSubstring(t *testing.T) {
|
||||
stringUtils := golanghelper.StringUtils{}
|
||||
|
||||
s := stringUtils.Substring("", 0, 0)
|
||||
if s != "" {
|
||||
t.Errorf("預期的值為空字串, 卻回傳 %v", s)
|
||||
}
|
||||
|
||||
s = stringUtils.Substring("abc", 0, 2)
|
||||
if s != "ab" {
|
||||
t.Errorf("預期的值為 ab, 卻回傳 %v", s)
|
||||
}
|
||||
|
||||
s = stringUtils.Substring("abc", 2, 0)
|
||||
if s != "" {
|
||||
t.Errorf("預期的值為空字串, 卻回傳 %v", s)
|
||||
}
|
||||
|
||||
s = stringUtils.Substring("abc", 2, 4)
|
||||
if s != "c" {
|
||||
t.Errorf("預期的值為 c, 卻回傳 %v", s)
|
||||
}
|
||||
|
||||
s = stringUtils.Substring("abc", 4, 6)
|
||||
if s != "" {
|
||||
t.Errorf("預期的值為空字串, 卻回傳 %v", s)
|
||||
}
|
||||
|
||||
s = stringUtils.Substring("abc", 2, 2)
|
||||
if s != "" {
|
||||
t.Errorf("預期的值為 ab, 卻回傳 %v", s)
|
||||
}
|
||||
|
||||
s = stringUtils.Substring("abc", -2, -1)
|
||||
if s != "b" {
|
||||
t.Errorf("預期的值為 b, 卻回傳 %v", s)
|
||||
}
|
||||
|
||||
s = stringUtils.Substring("abc", -4, 2)
|
||||
if s != "ab" {
|
||||
t.Errorf("預期的值為 ab, 卻回傳 %v", s)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user