Test case and documentation update for suffx and prefix functionality

This commit is contained in:
Roshan Ranabhat 2021-05-14 23:18:35 +05:45
parent 089d9d1aa9
commit b624324b66
2 changed files with 33 additions and 27 deletions

View File

@ -50,6 +50,11 @@ Convert string to camel case, snake case, kebab case / slugify, custom delimiter
<tr>
<td><a href="#firstlength-int-string">First</a></td>
<td><a href="#lastlength-int-string">Last</a></td>
<td><a href="#prefix-string-string">Prefix</a></td>
</tr>
<tr>
<td><a href="#suffix-string-string">Suffix</a></td>
<td></td>
<td></td>
</tr>
</table>

View File

@ -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)
}
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/
// _
str = New("foobar")
against = "foofoofoobar"
if val := str.Prefix("foofoo"); val != against {
t.Errorf("Expected: to be %s but got: %s", against, val)
}
}
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)
}
}