github.com/goki/ki@v1.1.11/ki/props_test.go (about)

     1  // Copyright (c) 2018, The GoKi Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package ki
     6  
     7  import (
     8  	"encoding/json"
     9  	"testing"
    10  
    11  	"github.com/goki/ki/kit"
    12  )
    13  
    14  var PropsTest = Props{
    15  	"intprop":    -17,
    16  	"floatprop":  3.1415,
    17  	"stringprop": "type string",
    18  	"#subprops": Props{
    19  		"sp1": "#FFE",
    20  		"sp2": 42.2,
    21  	},
    22  	"subtype": NodeEmbed{
    23  		Mbr1: "smbr",
    24  		Mbr2: 17,
    25  	},
    26  	"testenum": kit.TestFlag2,
    27  }
    28  
    29  func TestPropsJSonSave(t *testing.T) {
    30  	b, err := json.MarshalIndent(PropsTest, "", "  ")
    31  	if err != nil {
    32  		t.Error(err)
    33  		// } else {
    34  		// 	fmt.Printf("props json output:\n%v\n", string(b))
    35  	}
    36  
    37  	tstload := make(Props)
    38  	err = json.Unmarshal(b, &tstload)
    39  	if err != nil {
    40  		t.Error(err)
    41  		// } else {
    42  		// 	// tstb, _ := json.MarshalIndent(tstload, "", "  ")
    43  		// fmt.Printf("props test loaded json output:\n%v\n", string(tstb))
    44  		// because of the map randomization, this is not testable, do it manually..
    45  		// if !bytes.Equal(tstb, b) {
    46  		// 	t.Error("props original and unmarshal'd json rep are not equivalent")
    47  		// }
    48  	}
    49  }