From b624324b66cc5ec110180124c1ab8790a2b054bd Mon Sep 17 00:00:00 2001 From: Roshan Ranabhat Date: Fri, 14 May 2021 23:18:35 +0545 Subject: [PATCH] Test case and documentation update for suffx and prefix functionality --- README.md | 13 +++++++++---- stringy_test.go | 47 ++++++++++++++++++++++++----------------------- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index b5f5ded..66a5a91 100644 --- a/README.md +++ b/README.md @@ -48,10 +48,15 @@ Convert string to camel case, snake case, kebab case / slugify, custom delimiter UcFirst - First - Last - - + First + Last + Prefix + + + Suffix + + + diff --git a/stringy_test.go b/stringy_test.go index bac1018..800aff3 100644 --- a/stringy_test.go +++ b/stringy_test.go @@ -1,7 +1,6 @@ package stringy import ( - "fmt" "testing" ) @@ -312,28 +311,30 @@ func TestInput_Last(t *testing.T) { } } -func ExampleStringManipulation_Prefix() { - fmt.Println(New("foobar").Prefix("foo")) - fmt.Println(New("foobar").Prefix("foofoo")) - fmt.Println(New("foobar").Prefix("/")) - fmt.Println(New("").Prefix("_")) - // Output: - // foobar - // foofoofoobar - // /foobar - // _ +func TestInput_Prefix(t *testing.T) { + str := New("foobar") + against := "foobar" + if val := str.Prefix("foo"); val != against { + t.Errorf("Expected: to be %s but got: %s", against, val) + } + + str = New("foobar") + against = "foofoofoobar" + if val := str.Prefix("foofoo"); val != against { + t.Errorf("Expected: to be %s but got: %s", against, val) + } } -func ExampleStringManipulation_Suffix() { - fmt.Println(New("foobar").Suffix("bar")) - fmt.Println(New("foobar").Suffix("barbar")) - fmt.Println(New("foobar").Suffix("/")) - fmt.Println(New("foobar/").Suffix("/")) - fmt.Println(New("").Suffix("_")) - // Output: - // foobar - // foobarbarbar - // foobar/ - // foobar/ - // _ +func TestInput_Suffix(t *testing.T) { + str := New("foobar") + against := "foobar" + if val := str.Suffix("bar"); val != against { + t.Errorf("Expected: to be %s but got: %s", against, val) + } + + str = New("foobar") + against = "foobarbarbar" + if val := str.Suffix("barbar"); val != against { + t.Errorf("Expected: to be %s but got: %s", against, val) + } }