package mxj import ( "testing" "github.com/google/go-cmp/cmp" ) var whiteSpaceDataSeqTest2 = []byte(` William T. Gaddis The Recognitions One of the great seminal American novels of the 20th century. Austin Tappan Wright Islandia An example of earlier 20th century American utopian fiction. John Hawkes The Beetle Leg A lyrical novel about the construction of Ft. Peck Dam in Montana. `) func TestSetGlobalKeyMapPrefix(t *testing.T) { prefixList := []struct { name string value string }{ { name: "Testing with % as Map Key Prefix", value: "%", }, { name: "Testing with _ as Map Key Prefix", value: "_", }, { name: "Testing with - as Map Key Prefix", value: "-", }, { name: "Testing with & as Map Key Prefix", value: "&", }, } for _, prefix := range prefixList { t.Run(prefix.name, func(t *testing.T) { // Testing MapSeq(Ordering) with whitespace and byte equivalence DisableTrimWhiteSpace(true) SetGlobalKeyMapPrefix(prefix.value) m, err := NewMapFormattedXmlSeq(whiteSpaceDataSeqTest2) if err != nil { t.Fatal(err) } m1 := MapSeq(m) x, err := m1.XmlIndent("", " ") if err != nil { t.Fatal(err) } if string(x) != string(whiteSpaceDataSeqTest2) { t.Fatalf("expected\n'%s' \ngot \n'%s'", whiteSpaceDataSeqTest2, x) } DisableTrimWhiteSpace(false) // Testing Map with whitespace and deep equivalence DisableTrimWhiteSpace(true) m3, err := NewMapXml(whiteSpaceDataSeqTest2) if err != nil { t.Fatal(err) } m4 := Map(m3) if !cmp.Equal(m3, m4) { t.Errorf("Maps unmatched using %s", prefix.value) } DisableTrimWhiteSpace(false) // Testing MapSeq(Ordering) without whitespace and byte equivalence m5, err := NewMapFormattedXmlSeq(whiteSpaceDataSeqTest2) if err != nil { t.Fatal(err) } m6 := MapSeq(m5) if !cmp.Equal(m5, m6) { t.Errorf("Maps unmatched using %s", prefix.value) } // Testing Map without whitespace and deep equivalence m7, err := NewMapXml(whiteSpaceDataSeqTest2) if err != nil { t.Fatal(err) } m8 := Map(m7) if !cmp.Equal(m7, m8) { t.Errorf("Maps unmatched using %s", prefix.value) } }) } SetGlobalKeyMapPrefix("#") }