diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2025-12-30 22:05:09 +0100 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2025-12-30 22:05:09 +0100 |
| commit | 968c823f2949ef0e2e5e35b5dac7b6715bc6aaed (patch) | |
| tree | 354a2a2f359ca5068ed7dc71b673c4a85bf08c90 | |
| parent | 8a0c57a707a1d5e6ba75c0ca613b3e8b9e981326 (diff) | |
Simplified testing
| -rw-r--r-- | ki18n/ki18n_test.go | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/ki18n/ki18n_test.go b/ki18n/ki18n_test.go index 6d1395e..b9ad997 100644 --- a/ki18n/ki18n_test.go +++ b/ki18n/ki18n_test.go @@ -8,6 +8,7 @@ import ( "testing" "testing/fstest" + "github.com/a-h/templ" "github.com/stretchr/testify/assert" ) @@ -16,11 +17,8 @@ func TestSimpleText(t *testing.T) { "Hello you": "Bonjour toi", }) - c := Tr("fr-FR", "Hello you") - w := &bytes.Buffer{} - err := c.Render(context.Background(), w) - assert.NoError(t, err) - assert.Equal(t, "Bonjour toi", w.String()) + result := render(t, Tr("fr-FR", "Hello you")) + assert.Equal(t, "Bonjour toi", result) } func TestVariables(t *testing.T) { @@ -28,11 +26,17 @@ func TestVariables(t *testing.T) { "Hello %s": "Bonjour %s", }) - c := Tr("fr-FR", "Hello %s", "John") + result := render(t, Tr("fr-FR", "Hello %s", "John")) + assert.Equal(t, "Bonjour John", result) +} + +// render is a test helper that renders a component and returns the result as a string +func render(t *testing.T, c templ.Component) string { + t.Helper() w := &bytes.Buffer{} err := c.Render(context.Background(), w) assert.NoError(t, err) - assert.Equal(t, "Bonjour John", w.String()) + return w.String() } // initFrenchLocale creates a filesystem with fr-FR locale from a translation map |
