github.com/kotovmak/go-admin@v1.1.1/modules/language/language_test.go (about)

     1  package language
     2  
     3  import (
     4  	"html/template"
     5  	"testing"
     6  
     7  	"github.com/kotovmak/go-admin/modules/config"
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestAdd(t *testing.T) {
    12  	Add("cn", map[string]string{})
    13  }
    14  
    15  func TestGetWithScope(t *testing.T) {
    16  	config.Initialize(&config.Config{
    17  		Language: CN,
    18  	})
    19  	cn["foo"] = "bar"
    20  	assert.Equal(t, GetWithScope("foo"), "bar")
    21  	cn["user.table.foo2"] = "bar"
    22  	assert.Equal(t, GetWithScope("foo2"), "foo2")
    23  	assert.Equal(t, GetWithScope("foo2", "user"), "foo2")
    24  	assert.Equal(t, GetWithScope("foo2", "user", "table"), "bar")
    25  }
    26  
    27  func TestGet(t *testing.T) {
    28  	config.Initialize(&config.Config{
    29  		Language: CN,
    30  	})
    31  	cn["foo"] = "bar"
    32  	assert.Equal(t, Get("foo"), "bar")
    33  }
    34  
    35  func TestWithScopes(t *testing.T) {
    36  	assert.Equal(t, WithScopes("foo", "user", "table"), "user.table.foo")
    37  }
    38  
    39  func TestGetFromHtml(t *testing.T) {
    40  	config.Initialize(&config.Config{
    41  		Language: CN,
    42  	})
    43  	cn["user.table.foo"] = "bar"
    44  	assert.Equal(t, GetFromHtml("foo", "user", "table"), template.HTML("bar"))
    45  }