mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-29 07:00:31 +03:00
tpl: Polish i18n tests
* Make the type/var names more specific. They live in the test namespace, but there are other tests there. * Camel case variable * Small change suggested by Golint
This commit is contained in:
parent
e7e2a1ca02
commit
2071d470e6
1 changed files with 36 additions and 36 deletions
|
@ -21,13 +21,13 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
type test struct {
|
type i18nTest struct {
|
||||||
data map[string][]byte
|
data map[string][]byte
|
||||||
args interface{}
|
args interface{}
|
||||||
lang, id, expected, expected_flag string
|
lang, id, expected, expectedFlag string
|
||||||
}
|
}
|
||||||
|
|
||||||
var tests []test = []test{
|
var i18nTests = []i18nTest{
|
||||||
// All translations present
|
// All translations present
|
||||||
{
|
{
|
||||||
data: map[string][]byte{
|
data: map[string][]byte{
|
||||||
|
@ -38,7 +38,7 @@ var tests []test = []test{
|
||||||
lang: "es",
|
lang: "es",
|
||||||
id: "hello",
|
id: "hello",
|
||||||
expected: "¡Hola, Mundo!",
|
expected: "¡Hola, Mundo!",
|
||||||
expected_flag: "¡Hola, Mundo!",
|
expectedFlag: "¡Hola, Mundo!",
|
||||||
},
|
},
|
||||||
// Translation missing in current language but present in default
|
// Translation missing in current language but present in default
|
||||||
{
|
{
|
||||||
|
@ -50,7 +50,7 @@ var tests []test = []test{
|
||||||
lang: "es",
|
lang: "es",
|
||||||
id: "hello",
|
id: "hello",
|
||||||
expected: "Hello, World!",
|
expected: "Hello, World!",
|
||||||
expected_flag: "[i18n] hello",
|
expectedFlag: "[i18n] hello",
|
||||||
},
|
},
|
||||||
// Translation missing in default language but present in current
|
// Translation missing in default language but present in current
|
||||||
{
|
{
|
||||||
|
@ -62,7 +62,7 @@ var tests []test = []test{
|
||||||
lang: "es",
|
lang: "es",
|
||||||
id: "hello",
|
id: "hello",
|
||||||
expected: "¡Hola, Mundo!",
|
expected: "¡Hola, Mundo!",
|
||||||
expected_flag: "¡Hola, Mundo!",
|
expectedFlag: "¡Hola, Mundo!",
|
||||||
},
|
},
|
||||||
// Translation missing in both default and current language
|
// Translation missing in both default and current language
|
||||||
{
|
{
|
||||||
|
@ -74,7 +74,7 @@ var tests []test = []test{
|
||||||
lang: "es",
|
lang: "es",
|
||||||
id: "hello",
|
id: "hello",
|
||||||
expected: "",
|
expected: "",
|
||||||
expected_flag: "[i18n] hello",
|
expectedFlag: "[i18n] hello",
|
||||||
},
|
},
|
||||||
// Default translation file missing or empty
|
// Default translation file missing or empty
|
||||||
{
|
{
|
||||||
|
@ -85,7 +85,7 @@ var tests []test = []test{
|
||||||
lang: "es",
|
lang: "es",
|
||||||
id: "hello",
|
id: "hello",
|
||||||
expected: "",
|
expected: "",
|
||||||
expected_flag: "[i18n] hello",
|
expectedFlag: "[i18n] hello",
|
||||||
},
|
},
|
||||||
// Context provided
|
// Context provided
|
||||||
{
|
{
|
||||||
|
@ -101,7 +101,7 @@ var tests []test = []test{
|
||||||
lang: "es",
|
lang: "es",
|
||||||
id: "wordCount",
|
id: "wordCount",
|
||||||
expected: "¡Hola, 50 gente!",
|
expected: "¡Hola, 50 gente!",
|
||||||
expected_flag: "¡Hola, 50 gente!",
|
expectedFlag: "¡Hola, 50 gente!",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,9 +134,9 @@ func TestI18nTranslate(t *testing.T) {
|
||||||
for _, enablePlaceholders := range []bool{false, true} {
|
for _, enablePlaceholders := range []bool{false, true} {
|
||||||
viper.Set("EnableMissingTranslationPlaceholders", enablePlaceholders)
|
viper.Set("EnableMissingTranslationPlaceholders", enablePlaceholders)
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range i18nTests {
|
||||||
if enablePlaceholders {
|
if enablePlaceholders {
|
||||||
expected = test.expected_flag
|
expected = test.expectedFlag
|
||||||
} else {
|
} else {
|
||||||
expected = test.expected
|
expected = test.expected
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue