github.com/sereiner/library@v0.0.0-20200518095232-1fa3e640cc5f/jsons/json_test.go (about)

     1  package jsons
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  )
     7  
     8  func TestEscape(t *testing.T) {
     9  	input := "\\u0026123\\u003c1\\u003e"
    10  	except := "&123<1>"
    11  	actual := Escape(input)
    12  	if !strings.EqualFold(actual, except) {
    13  		t.Errorf("test fail actual:%s, except:%s", actual, except)
    14  	}
    15  }
    16  
    17  type User struct {
    18  	Name    string `json:"name" `
    19  	Age     int    `json:"age" ms:"age"`
    20  	Addr    string `json:"addr"`
    21  	Country string `json:"country" ms:"country"`
    22  }
    23  
    24  func TestMarshal(t *testing.T) {
    25  
    26  	u := User{
    27  		Name:    "jack",
    28  		Age:     22,
    29  		Addr:    "成都",
    30  		Country: "中国",
    31  	}
    32  
    33  	gotA, err := Marshal(u)
    34  	if err != nil {
    35  		t.Error(err)
    36  	}
    37  	t.Log(string(gotA))
    38  
    39  	gotB, err := Marshal(u, "ms")
    40  	if err != nil {
    41  		t.Error(err)
    42  	}
    43  	t.Log(string(gotB))
    44  }