Text: Do not capitalize "van" in names and titles #2672

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer 2022-09-14 20:37:24 +02:00
parent d2c6eac3bf
commit eec31c4938
7 changed files with 62 additions and 43 deletions

34
pkg/txt/separator_test.go Normal file
View file

@ -0,0 +1,34 @@
package txt
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestIsSeparator(t *testing.T) {
t.Run("rune A", func(t *testing.T) {
assert.Equal(t, false, isSeparator('A'))
})
t.Run("rune 99", func(t *testing.T) {
assert.Equal(t, false, isSeparator('9'))
})
t.Run("rune /", func(t *testing.T) {
assert.Equal(t, true, isSeparator('/'))
})
t.Run("rune \\", func(t *testing.T) {
assert.Equal(t, true, isSeparator('\\'))
})
t.Run("rune ♥ ", func(t *testing.T) {
assert.Equal(t, false, isSeparator('♥'))
})
t.Run("rune space", func(t *testing.T) {
assert.Equal(t, true, isSeparator(' '))
})
t.Run("rune '", func(t *testing.T) {
assert.Equal(t, false, isSeparator('\''))
})
t.Run("rune ý", func(t *testing.T) {
assert.Equal(t, false, isSeparator('ý'))
})
}

View file

@ -1397,6 +1397,7 @@ var ShortWords = map[string]bool{
"low": true,
"lox": true,
"lp": true,
"lpg": true,
"lpm": true,
"lr": true,
"ls": true,

View file

@ -35,6 +35,7 @@ var SmallWords = map[string]bool{
"und": true,
"uns": true,
"des": true,
"van": true,
"von": true,
"für": true,
"ein": true,

View file

@ -29,7 +29,7 @@ func Title(s string) string {
if match, ok := SpecialWords[search]; ok {
words[i] = strings.Replace(strings.ToLower(w), search, match, 1)
} else if i > 0 && SmallWords[search] {
} else if i > 0 && SmallWords[search] == true {
words[i] = strings.ToLower(w)
} else {
prev := ' '

View file

@ -6,48 +6,6 @@ import (
"github.com/stretchr/testify/assert"
)
func TestIsSeparator(t *testing.T) {
t.Run("rune A", func(t *testing.T) {
assert.Equal(t, false, isSeparator('A'))
})
t.Run("rune 99", func(t *testing.T) {
assert.Equal(t, false, isSeparator('9'))
})
t.Run("rune /", func(t *testing.T) {
assert.Equal(t, true, isSeparator('/'))
})
t.Run("rune \\", func(t *testing.T) {
assert.Equal(t, true, isSeparator('\\'))
})
t.Run("rune ♥ ", func(t *testing.T) {
assert.Equal(t, false, isSeparator('♥'))
})
t.Run("rune space", func(t *testing.T) {
assert.Equal(t, true, isSeparator(' '))
})
t.Run("rune '", func(t *testing.T) {
assert.Equal(t, false, isSeparator('\''))
})
t.Run("rune ý", func(t *testing.T) {
assert.Equal(t, false, isSeparator('ý'))
})
}
func TestUcFirst(t *testing.T) {
t.Run("photo-lover", func(t *testing.T) {
assert.Equal(t, "Photo-lover", UpperFirst("photo-lover"))
})
t.Run("cat", func(t *testing.T) {
assert.Equal(t, "Cat", UpperFirst("Cat"))
})
t.Run("KwaZulu natal", func(t *testing.T) {
assert.Equal(t, "KwaZulu Natal", Title("KwaZulu natal"))
})
t.Run("empty string", func(t *testing.T) {
assert.Equal(t, "", UpperFirst(""))
})
}
func TestTitle(t *testing.T) {
t.Run("Cour d'Honneur", func(t *testing.T) {
assert.Equal(t, "Cour d'Honneur", Title("Cour d'Honneur"))
@ -107,4 +65,7 @@ func TestTitle(t *testing.T) {
t.Run("NYC", func(t *testing.T) {
assert.Equal(t, "NYC, NY - LonDon, UK - NYC, NY and London, UK.", Title("NYC, NY - LonDon, UK - Nyc, Ny and London, Uk."))
})
t.Run("KoosVanDriemond", func(t *testing.T) {
assert.Equal(t, "Koos van Driemond", Title("Koos van Driemond"))
})
}

View file

@ -0,0 +1,22 @@
package txt
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestUcFirst(t *testing.T) {
t.Run("photo-lover", func(t *testing.T) {
assert.Equal(t, "Photo-lover", UpperFirst("photo-lover"))
})
t.Run("cat", func(t *testing.T) {
assert.Equal(t, "Cat", UpperFirst("Cat"))
})
t.Run("KwaZulu natal", func(t *testing.T) {
assert.Equal(t, "KwaZulu natal", UpperFirst("KwaZulu natal"))
})
t.Run("empty string", func(t *testing.T) {
assert.Equal(t, "", UpperFirst(""))
})
}