Skip to content

Commit 78bdc57

Browse files
author
Gusted
committed
Fix some test
1 parent ddaf0cb commit 78bdc57

File tree

3 files changed

+4
-53
lines changed

3 files changed

+4
-53
lines changed

modules/timeutil/since_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func TestHtmlTimeSince(t *testing.T) {
119119
setting.DefaultUILocation = time.UTC
120120
// test that `diff` yields a result containing `expected`
121121
test := func(expected string, diff time.Duration) {
122-
actual := htmlTimeSince(BaseDate, BaseDate.Add(diff), "en")
122+
actual := htmlTimeSince(BaseDate, BaseDate.Add(diff), translation.NewLocale("en-US"))
123123
assert.Contains(t, actual, `title="Sat Jan 1 00:00:00 UTC 2000"`)
124124
assert.Contains(t, actual, expected)
125125
}

modules/translation/i18n/i18n.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ func (ls *LocaleStore) AddLocaleByIni(langName, langDesc string, localeFile inte
6262
ls.langNames = append(ls.langNames, langName)
6363
ls.langDescs = append(ls.langDescs, langDesc)
6464

65+
// Specify the offset for translationValues.
66+
ls.langOffsets = append(ls.langOffsets, len(ls.langOffsets))
67+
6568
// Make a distinquishment between production and development.
6669
// For development, live-reload of the translation files is important.
6770
// For production, we can do some expensive work and then make the querying fast.

modules/translation/i18n/i18n_test.go

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package i18n
77
import (
88
"testing"
99

10-
"code.gitea.io/gitea/modules/setting"
1110
"github.com/stretchr/testify/assert"
1211
)
1312

@@ -56,54 +55,3 @@ sub = Changed Sub String
5655
assert.Equal(t, []string{"Lang1", "Lang2"}, descs)
5756
assert.Equal(t, []int{0, 1}, offsets)
5857
}
59-
60-
func Test_TrProd(t *testing.T) {
61-
setting.IsProd = true
62-
defer func() {
63-
setting.IsProd = false
64-
}()
65-
66-
testData1 := []byte(`
67-
.dot.name = Dot Name
68-
fmt = %[1]s %[2]s
69-
70-
[section]
71-
sub = Sub String
72-
mixed = test value; <span style="color: red\; background: none;">more text</span>
73-
`)
74-
75-
testData2 := []byte(`
76-
fmt = %[2]s %[1]s
77-
78-
[section]
79-
sub = Changed Sub String
80-
`)
81-
82-
ls := NewLocaleStore()
83-
assert.NoError(t, ls.AddLocaleByIni("lang1", "Lang1", testData1))
84-
assert.NoError(t, ls.AddLocaleByIni("lang2", "Lang2", testData2))
85-
ls.SetDefaultLang("lang1")
86-
87-
result := ls.Tr("lang1", "fmt", "a", "b")
88-
assert.Equal(t, "a b", result)
89-
90-
result = ls.Tr("lang2", "fmt", "a", "b")
91-
assert.Equal(t, "b a", result)
92-
93-
result = ls.Tr("lang1", "section.sub")
94-
assert.Equal(t, "Sub String", result)
95-
96-
result = ls.Tr("lang2", "section.sub")
97-
assert.Equal(t, "Changed Sub String", result)
98-
99-
result = ls.Tr("", ".dot.name")
100-
assert.Equal(t, "Dot Name", result)
101-
102-
result = ls.Tr("lang2", "section.mixed")
103-
assert.Equal(t, `test value; <span style="color: red; background: none;">more text</span>`, result)
104-
105-
langs, descs, offsets := ls.ListLangNameDescOffsets()
106-
assert.Equal(t, []string{"lang1", "lang2"}, langs)
107-
assert.Equal(t, []string{"Lang1", "Lang2"}, descs)
108-
assert.Equal(t, []int{0, 1}, offsets)
109-
}

0 commit comments

Comments
 (0)