Skip to content

Commit

Permalink
test: improve coverage for i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonTian authored and yndu13 committed Feb 2, 2024
1 parent 5e11771 commit f5e4133
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions i18n/environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package i18n

import (
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -25,3 +26,12 @@ func TestEnvironment(t *testing.T) {
SetLanguage("zh")
assert.Equal(t, "zh", GetLanguage())
}

func TestGetLanguageFromEnv(t *testing.T) {
originLANG := os.Getenv("LANG")
defer os.Setenv("LANG", originLANG)
os.Setenv("LANG", "zh_CN.UTF-8")
assert.Equal(t, "zh", getLanguageFromEnv())
os.Setenv("LANG", "en_US.UTF-8")
assert.Equal(t, "en", getLanguageFromEnv())
}
8 changes: 8 additions & 0 deletions i18n/text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ func TestText(t *testing.T) {
assert.Equal(t, "你好", tx.Text())
}

func TestGetData(t *testing.T) {
tx := T("hello", "你好")
expected := make(map[string]string)
expected["en"] = "hello"
expected["zh"] = "你好"
assert.Equal(t, expected, tx.GetData())
}

func TestLibrary(t *testing.T) {
//Test T(en string, zh string)*Text
text := T("hello", "你好")
Expand Down

0 comments on commit f5e4133

Please sign in to comment.