Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
raspi committed Aug 12, 2020
1 parent befb92d commit dd9cdeb
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,48 @@ func TestPageTranslationVariable(t *testing.T) {
}
}
}

func TestCache(t *testing.T) {
translations := getTestTranslations()

tpl := New(`<html>{{- T "t" -}}</html>`, template.FuncMap{})
tpl.AddPage(`test`, ``, translations)

var tmp bytes.Buffer

for i := 0; i < 10; i++ {
for _, l := range translations.Languages() {
tmp.Reset()

err := tpl.Render(&tmp, `test`, l, nil)
if err != nil {
t.Fail()
}

printer := message.NewPrinter(l, message.Catalog(translations))
expected := `<html>` + printer.Sprintf(`t`) + `</html>`

if expected != tmp.String() {
t.Fail()
}
}
}
}

func TestPageTokenTranslation(t *testing.T) {
translations := getTestTranslations()

tpl := New(``, template.FuncMap{})
tpl.AddPage(`test`, ``, translations)

for _, l := range translations.Languages() {
actual := tpl.Translate(`test`, `t`, l)

printer := message.NewPrinter(l, message.Catalog(translations))
expected := printer.Sprintf(`t`)

if expected != actual {
t.Fail()
}
}
}

0 comments on commit dd9cdeb

Please sign in to comment.