diff options
Diffstat (limited to 'ki18n/ki18n_test.go')
| -rw-r--r-- | ki18n/ki18n_test.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/ki18n/ki18n_test.go b/ki18n/ki18n_test.go new file mode 100644 index 0000000..fc134fa --- /dev/null +++ b/ki18n/ki18n_test.go @@ -0,0 +1,38 @@ +package ki18n + +import ( + "bytes" + "context" + "testing" + "testing/fstest" + + "github.com/stretchr/testify/assert" +) + +func TestSimpleText(t *testing.T) { + fs := fstest.MapFS{ + "fr-FR/index.yml": &fstest.MapFile{ + Data: []byte("\"Hello you\": \"Bonjour toi\""), + }, + } + Init(fs) + 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()) +} + +func TestVariables(t *testing.T) { + fs := fstest.MapFS{ + "fr-FR/index.yml": &fstest.MapFile{ + Data: []byte("\"Hello %s\": \"Bonjour %s\""), + }, + } + Init(fs) + c := Tr("fr-FR", "Hello %s", "John") + w := &bytes.Buffer{} + err := c.Render(context.Background(), w) + assert.NoError(t, err) + assert.Equal(t, "Bonjour John", w.String()) +} |
