1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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())
}
|