test: adding some tests to Substring (see #288)

This commit is contained in:
Samuel Berthe
2023-03-20 17:59:52 +01:00
parent cccebf930b
commit 9ec076e4f6
2 changed files with 8 additions and 0 deletions

View File

@@ -9,14 +9,20 @@ func ExampleSubstring() {
result1 := Substring("hello", 2, 3)
result2 := Substring("hello", -4, 3)
result3 := Substring("hello", -2, math.MaxUint)
result4 := Substring("🏠🐶🐱", 0, 2)
result5 := Substring("你好,世界", 0, 3)
fmt.Printf("%v\n", result1)
fmt.Printf("%v\n", result2)
fmt.Printf("%v\n", result3)
fmt.Printf("%v\n", result4)
fmt.Printf("%v\n", result5)
// Output:
// llo
// ell
// lo
// 🏠🐶
// 你好,
}
func ExampleChunkString() {

View File

@@ -75,6 +75,7 @@ func TestSubstring(t *testing.T) {
str11 := Substring("hello", -4, 1)
str12 := Substring("hello", -4, math.MaxUint)
str13 := Substring("🏠🐶🐱", 0, 2)
str14 := Substring("你好,世界", 0, 3)
is.Equal("", str1)
is.Equal("", str2)
@@ -89,6 +90,7 @@ func TestSubstring(t *testing.T) {
is.Equal("e", str11)
is.Equal("ello", str12)
is.Equal("🏠🐶", str13)
is.Equal("你好,", str14)
}
func TestRuneLength(t *testing.T) {