Make the title case style guide configurable

This works for the `title` func and the other places where Hugo makes title case.

* AP style (new default)
* Chicago style
* Go style (what we have today)

Fixes #989
This commit is contained in:
Bjørn Erik Pedersen
2017-07-30 17:46:04 +02:00
parent 9b4170ce76
commit 8fb594bfb0
10 changed files with 77 additions and 7 deletions

View File

@@ -19,6 +19,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGuessType(t *testing.T) {
@@ -173,6 +174,20 @@ func TestReaderContains(t *testing.T) {
assert.False(t, ReaderContains(nil, nil))
}
func TestGetTitleFunc(t *testing.T) {
title := "somewhere over the rainbow"
assert := require.New(t)
assert.Equal("Somewhere Over The Rainbow", GetTitleFunc("go")(title))
assert.Equal("Somewhere over the Rainbow", GetTitleFunc("chicago")(title), "Chicago style")
assert.Equal("Somewhere over the Rainbow", GetTitleFunc("Chicago")(title), "Chicago style")
assert.Equal("Somewhere Over the Rainbow", GetTitleFunc("ap")(title), "AP style")
assert.Equal("Somewhere Over the Rainbow", GetTitleFunc("ap")(title), "AP style")
assert.Equal("Somewhere Over the Rainbow", GetTitleFunc("")(title), "AP style")
assert.Equal("Somewhere Over the Rainbow", GetTitleFunc("unknown")(title), "AP style")
}
func BenchmarkReaderContains(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {