mirror of https://github.com/gobeam/stringy.git
Test case and documentation update for suffx and prefix functionality
This commit is contained in:
parent
089d9d1aa9
commit
b624324b66
|
@ -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>
|
||||||
|
|
|
@ -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
|
str = New("foobar")
|
||||||
// /foobar
|
against = "foofoofoobar"
|
||||||
// _
|
if val := str.Prefix("foofoo"); val != against {
|
||||||
|
t.Errorf("Expected: to be %s but got: %s", against, val)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleStringManipulation_Suffix() {
|
func TestInput_Suffix(t *testing.T) {
|
||||||
fmt.Println(New("foobar").Suffix("bar"))
|
str := New("foobar")
|
||||||
fmt.Println(New("foobar").Suffix("barbar"))
|
against := "foobar"
|
||||||
fmt.Println(New("foobar").Suffix("/"))
|
if val := str.Suffix("bar"); val != against {
|
||||||
fmt.Println(New("foobar/").Suffix("/"))
|
t.Errorf("Expected: to be %s but got: %s", against, val)
|
||||||
fmt.Println(New("").Suffix("_"))
|
}
|
||||||
// Output:
|
|
||||||
// foobar
|
str = New("foobar")
|
||||||
// foobarbarbar
|
against = "foobarbarbar"
|
||||||
// foobar/
|
if val := str.Suffix("barbar"); val != against {
|
||||||
// foobar/
|
t.Errorf("Expected: to be %s but got: %s", against, val)
|
||||||
// _
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue