Пример #1
0
// Benchmark_TranslitURL	  300000	      3905 ns/op	     688 B/op	       3 allocs/op
func Benchmark_TranslitURL(b *testing.B) {
	b.ReportAllocs()
	want := "weiss-goldmann-gobel-weiss-gothe-goethe-und-gotz"
	have := []rune("Weiß$ Goldmann: Göbel; Weiss, Göthe, Goethe und Götz")
	for i := 0; i < b.N; i++ {
		benchmarkTranslitURL = string(utils.TranslitURL(have))
		if benchmarkTranslitURL != want {
			b.Errorf("\nWant: %s\nHave: %s\n", want, benchmarkTranslitURL)
		}
	}
}
Пример #2
0
func TestTranslitURL(t *testing.T) {
	tests := []struct {
		have string
		want string
	}{
		{"Hello World", "hello-world"},
		{"Weiß, Goldmann, Göbel, Weiss, Göthe, Goethe und Götz", "weiss-goldmann-gobel-weiss-gothe-goethe-und-gotz"},
		{"I have 5€ @ home", "i-have-5euro-at-home"},
		{"Weiß, Goldmann, Göbel, Weiss, Göthe, Goethe und Götz", "weiss-goldmann-gobel-weiss-gothe-goethe-und-gotz"},
		{"I have 5 € @ home", "i-have-5-euro-at-home"},
		{"I have 5 € @ home  ∏", "i-have-5-euro-at-home"},
		{"  I have 5 € @ home  ∏ ", "i-have-5-euro-at-home"},
		{"", ""},
	}

	for _, test := range tests {
		assert.Equal(t, test.want, string(utils.TranslitURL([]rune(test.have))), "%#v", test)
	}
}