From 9ec076e4f62bf41b6c4a5491e6428a27d70a3c23 Mon Sep 17 00:00:00 2001 From: Samuel Berthe Date: Mon, 20 Mar 2023 17:59:52 +0100 Subject: [PATCH] test: adding some tests to Substring (see #288) --- string_example_test.go | 6 ++++++ string_test.go | 2 ++ 2 files changed, 8 insertions(+) diff --git a/string_example_test.go b/string_example_test.go index ad93fda0..b659ea14 100644 --- a/string_example_test.go +++ b/string_example_test.go @@ -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() { diff --git a/string_test.go b/string_test.go index e32e5c52..42832586 100644 --- a/string_test.go +++ b/string_test.go @@ -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) {