Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislas-m committed Nov 18, 2017
1 parent 6863025 commit b165a30
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
31 changes: 31 additions & 0 deletions middleware/i18n/i18n_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import (
"github.com/stretchr/testify/require"
)

type User struct {
FirstName string
LastName string
}

func app() *buffalo.App {
app := buffalo.New(buffalo.Options{})

Expand All @@ -30,6 +35,13 @@ func app() *buffalo.App {
app.GET("/plural", func(c buffalo.Context) error {
return c.Render(200, r.HTML("plural.html"))
})
app.GET("/format", func(c buffalo.Context) error {
usersList := make([]User, 0)
usersList = append(usersList, User{"Mark", "Bates"})
usersList = append(usersList, User{"Chuck", "Berry"})
c.Set("Users", usersList)
return c.Render(200, r.HTML("format.html"))
})
return app
}

Expand Down Expand Up @@ -70,3 +82,22 @@ func Test_i18n_plural_fr(t *testing.T) {
res := req.Get()
r.Equal("Bonjour, tout seul !\nBonjour, 5 personnes !\n", res.Body.String())
}

func Test_i18n_format(t *testing.T) {
r := require.New(t)

w := willie.New(app())
res := w.Request("/format").Get()
r.Equal("Hello Mark!\n\n\t* Mr. Mark Bates\n\n\t* Mr. Chuck Berry\n", res.Body.String())
}

func Test_i18n_format_fr(t *testing.T) {
r := require.New(t)

w := willie.New(app())
req := w.Request("/format")
// Set language as "french"
req.Headers["Accept-Language"] = "fr-fr"
res := req.Get()
r.Equal("Bonjour Mark !\n\n\t* M. Mark Bates\n\n\t* M. Chuck Berry\n", res.Body.String())
}
5 changes: 4 additions & 1 deletion middleware/i18n/locales/test.en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
other: "Hello, {{.Count}} people!"

- id: test-format
translation: "Hello {{.Name}}!"
translation: "Hello {{.Name}}!"

- id: test-format-loop
translation: "Mr. {{.FirstName}} {{.LastName}}"
5 changes: 4 additions & 1 deletion middleware/i18n/locales/test.fr-fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
other: "Bonjour, {{.Count}} personnes !"

- id: test-format
translation: "Bonjour {{.Name}} !"
translation: "Bonjour {{.Name}} !"

- id: test-format-loop
translation: "M. {{.FirstName}} {{.LastName}}"
4 changes: 4 additions & 0 deletions middleware/i18n/templates/format.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<%= t("test-format", {Name: "Mark"}) %>
<%= for (u) in Users { %>
* <%= t("test-format-loop", u) %>
<% } %>

0 comments on commit b165a30

Please sign in to comment.