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> <tr>
<td><a href="#firstlength-int-string">First</a></td> <td><a href="#firstlength-int-string">First</a></td>
<td><a href="#lastlength-int-string">Last</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> <td></td>
</tr> </tr>
</table> </table>

View File

@ -1,7 +1,6 @@
package stringy package stringy
import ( import (
"fmt"
"testing" "testing"
) )
@ -312,28 +311,30 @@ func TestInput_Last(t *testing.T) {
} }
} }
func ExampleStringManipulation_Prefix() { func TestInput_Prefix(t *testing.T) {
fmt.Println(New("foobar").Prefix("foo")) str := New("foobar")
fmt.Println(New("foobar").Prefix("foofoo")) against := "foobar"
fmt.Println(New("foobar").Prefix("/")) if val := str.Prefix("foo"); val != against {
fmt.Println(New("").Prefix("_")) t.Errorf("Expected: to be %s but got: %s", against, val)
// Output:
// foobar
// foofoofoobar
// /foobar
// _
} }
func ExampleStringManipulation_Suffix() { str = New("foobar")
fmt.Println(New("foobar").Suffix("bar")) against = "foofoofoobar"
fmt.Println(New("foobar").Suffix("barbar")) if val := str.Prefix("foofoo"); val != against {
fmt.Println(New("foobar").Suffix("/")) t.Errorf("Expected: to be %s but got: %s", against, val)
fmt.Println(New("foobar/").Suffix("/")) }
fmt.Println(New("").Suffix("_")) }
// Output:
// foobar func TestInput_Suffix(t *testing.T) {
// foobarbarbar str := New("foobar")
// foobar/ against := "foobar"
// 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)
}
} }