github.com/sohaha/zlsgo@v1.7.13-0.20240501141223-10dd1a906f76/zjson/format_test.go (about)

     1  package zjson
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/sohaha/zlsgo"
     7  	"github.com/sohaha/zlsgo/zstring"
     8  )
     9  
    10  var demo = `{
    11  	"i":100,"f":1.6,"ii":-999,"time":"2019-09-10 13:48:22","index.key":"66.6",
    12  "quality":"highLevel","user":{"name":"暴龙兽"},"children":["阿古兽","暴龙兽","机器暴龙兽",{}],"other":["\"",666,"1.8","$1",{"rank":["t",1,2,3]}],"bool":false,"boolTrue":true,"none":"","friends":[{"name":"天使兽","quality":"highLevel","age":1},{"age":5,"name":"天女兽",
    13    "quality":"super"}]}`
    14  
    15  func TestDiscard(T *testing.T) {
    16  	t := zlsgo.NewTest(T)
    17  	t.Log(Discard(`{
    18  // 这是测试
    19  "user":{"name":"暴龙兽"}
    20  }`))
    21  }
    22  
    23  func TestFormat(t *testing.T) {
    24  	tt := zlsgo.NewTest(t)
    25  	pretty := Format(zstring.String2Bytes(demo))
    26  	tt.Log(zstring.Bytes2String(pretty))
    27  
    28  	str2 := Ugly(pretty)
    29  	tt.Log(zstring.Bytes2String(str2))
    30  
    31  	str3 := FormatOptions(str2, &StFormatOptions{Width: 5, Prefix: "", SortKeys: true})
    32  	tt.Log(zstring.Bytes2String(str3))
    33  
    34  	str4 := Ugly(str3)
    35  	tt.Log(zstring.Bytes2String(str4))
    36  
    37  	str5 := Format([]byte("1668"))
    38  	tt.Log(zstring.Bytes2String(str5))
    39  
    40  	str6 := Ugly(str5)
    41  	tt.Log(zstring.Bytes2String(str6))
    42  }