1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00
cowyo/vendor/dmitri.shuralyov.com/text/kebabcase/kebabcase_test.go

48 lines
1.1 KiB
Go
Raw Normal View History

2017-10-03 21:43:55 +03:00
package kebabcase_test
import (
"fmt"
"reflect"
"testing"
2018-03-31 06:42:54 +03:00
"dmitri.shuralyov.com/text/kebabcase"
2017-10-03 21:43:55 +03:00
"github.com/shurcooL/graphql/ident"
)
func Example_kebabCaseToMixedCaps() {
fmt.Println(kebabcase.Parse("client-mutation-id").ToMixedCaps())
// Output: ClientMutationID
}
func TestParse(t *testing.T) {
tests := []struct {
in string
want ident.Name
}{
{in: "book", want: ident.Name{"book"}},
{in: "bookmark", want: ident.Name{"bookmark"}},
{in: "arrow-right", want: ident.Name{"arrow", "right"}},
{in: "arrow-small-right", want: ident.Name{"arrow", "small", "right"}},
{in: "device-camera-video-audio", want: ident.Name{"device", "camera", "video", "audio"}},
{in: "rss", want: ident.Name{"rss"}},
}
for _, tc := range tests {
got := kebabcase.Parse(tc.in)
if !reflect.DeepEqual(got, tc.want) {
t.Errorf("got: %q, want: %q", got, tc.want)
}
}
}
func BenchmarkParse(b *testing.B) {
for i := 0; i < b.N; i++ {
kebabcase.Parse("book")
kebabcase.Parse("bookmark")
kebabcase.Parse("arrow-right")
kebabcase.Parse("arrow-small-right")
kebabcase.Parse("device-camera-video-audio")
kebabcase.Parse("rss")
}
}