From 968c823f2949ef0e2e5e35b5dac7b6715bc6aaed Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Tue, 30 Dec 2025 22:05:09 +0100 Subject: Simplified testing --- ki18n/ki18n_test.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'ki18n/ki18n_test.go') 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 -- cgit v1.3