|
14 | 14 | package i18n |
15 | 15 |
|
16 | 16 | import ( |
| 17 | + "fmt" |
17 | 18 | "path/filepath" |
18 | 19 | "testing" |
19 | 20 |
|
@@ -125,6 +126,35 @@ var i18nTests = []i18nTest{ |
125 | 126 | expected: "¡Hola, 50 gente!", |
126 | 127 | expectedFlag: "¡Hola, 50 gente!", |
127 | 128 | }, |
| 129 | + // https://github.com/gohugoio/hugo/issues/7787 |
| 130 | + { |
| 131 | + name: "readingTime-one", |
| 132 | + data: map[string][]byte{ |
| 133 | + "en.toml": []byte(`[readingTime] |
| 134 | +one = "One minute to read" |
| 135 | +other = "{{ .Count }} minutes to read" |
| 136 | +`), |
| 137 | + }, |
| 138 | + args: 1, |
| 139 | + lang: "en", |
| 140 | + id: "readingTime", |
| 141 | + expected: "One minute to read", |
| 142 | + expectedFlag: "One minute to read", |
| 143 | + }, |
| 144 | + { |
| 145 | + name: "readingTime-many", |
| 146 | + data: map[string][]byte{ |
| 147 | + "en.toml": []byte(`[readingTime] |
| 148 | +one = "One minute to read" |
| 149 | +other = "{{ .Count }} minutes to read" |
| 150 | +`), |
| 151 | + }, |
| 152 | + args: 21, |
| 153 | + lang: "en", |
| 154 | + id: "readingTime", |
| 155 | + expected: "21 minutes to read", |
| 156 | + expectedFlag: "21 minutes to read", |
| 157 | + }, |
128 | 158 | // Same id and translation in current language |
129 | 159 | // https://github.com/gohugoio/hugo/issues/2607 |
130 | 160 | { |
@@ -242,13 +272,15 @@ func TestI18nTranslate(t *testing.T) { |
242 | 272 | v.Set("enableMissingTranslationPlaceholders", enablePlaceholders) |
243 | 273 |
|
244 | 274 | for _, test := range i18nTests { |
245 | | - if enablePlaceholders { |
246 | | - expected = test.expectedFlag |
247 | | - } else { |
248 | | - expected = test.expected |
249 | | - } |
250 | | - actual = doTestI18nTranslate(t, test, v) |
251 | | - c.Assert(actual, qt.Equals, expected) |
| 275 | + c.Run(fmt.Sprintf("%s-%t", test.name, enablePlaceholders), func(c *qt.C) { |
| 276 | + if enablePlaceholders { |
| 277 | + expected = test.expectedFlag |
| 278 | + } else { |
| 279 | + expected = test.expected |
| 280 | + } |
| 281 | + actual = doTestI18nTranslate(t, test, v) |
| 282 | + c.Assert(actual, qt.Equals, expected) |
| 283 | + }) |
252 | 284 | } |
253 | 285 | } |
254 | 286 | } |
|
0 commit comments