...

Source file src/github.com/clbanning/mxj/v2/mxj_test.go

Documentation: github.com/clbanning/mxj/v2

     1  package mxj
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  )
     7  
     8  func TestMxjHeader(t *testing.T) {
     9  	fmt.Println("\n----------------  mxj_test.go ...")
    10  }
    11  
    12  func TestMap(t *testing.T) {
    13  	m := New()
    14  
    15  	m["key"] = interface{}("value")
    16  	v := map[string]interface{}{"bool": true, "float": 3.14159, "string": "Now is the time"}
    17  	vv := []interface{}{3.1415962535, false, "for all good men"}
    18  	v["listkey"] = interface{}(vv)
    19  	m["newkey"] = interface{}(v)
    20  
    21  	fmt.Println("TestMap, m:")
    22  	fmt.Printf("%#v\n", m)
    23  	fmt.Println("TestMap, StringIndent -")
    24  	fmt.Println(m.StringIndent())
    25  	fmt.Println("TestMap, StringIndent NoTypeInfo -")
    26  	fmt.Println(m.StringIndentNoTypeInfo())
    27  
    28  	o := interface{}(m.Old())
    29  	switch o.(type) {
    30  	case map[string]interface{}:
    31  		// do nothing
    32  	default:
    33  		t.Fatal("invalid type for m.Old()")
    34  	}
    35  
    36  	m, _ = NewMapXml([]byte(`<doc><tag><sub_tag1>Hello</sub_tag1><sub_tag2>World</sub_tag2></tag></doc>`))
    37  	fmt.Println("TestMap, m_fromXML:")
    38  	fmt.Printf("%#v\n", m)
    39  	fmt.Println("TestMap, StringIndent -")
    40  	fmt.Println( m.StringIndent())
    41  	fmt.Println("TestMap, StringIndent NoTypeInfo -")
    42  	fmt.Println( m.StringIndentNoTypeInfo())
    43  
    44  	mm, _ := m.Copy()
    45  	fmt.Println("TestMap, m.Copy() -\n", mm)
    46  }
    47  

View as plain text