1 package mxj 2 3 import ( 4 "fmt" 5 "testing" 6 ) 7 8 func TestExists(t *testing.T) { 9 fmt.Println("------------ exists_test.go") 10 m := map[string]interface{}{ 11 "Div": map[string]interface{}{ 12 "Colour": "blue", 13 }, 14 } 15 mv := Map(m) 16 17 if v, _ := mv.Exists("Div.Colour"); !v { 18 t.Fatal("Haven't found an existing element") 19 } 20 21 if v, _ := mv.Exists("Div.Color"); v { 22 t.Fatal("Have found a non existing element") 23 } 24 } 25 26 /* 27 var existsDoc = []byte(` 28 <doc> 29 <books> 30 <book seq="1"> 31 <author>William T. Gaddis</author> 32 <title>The Recognitions</title> 33 <review>One of the great seminal American novels of the 20th century.</review> 34 </book> 35 </books> 36 <book>Something else.</book> 37 </doc> 38 `) 39 40 func TestExistsWithSubKeys(t *testing.T) { 41 mv, err := NewMapXml(existsDoc) 42 if err != nil { 43 t.Fatal("err:", err.Error()) 44 } 45 46 if !mv.Exists("doc.books.book", "-seq:1") { 47 t.Fatal("Did't find an existing element") 48 } 49 50 if mv.Exists("doc.books.book", "-seq:2") { 51 t.Fatal("Found a non-existing element") 52 } 53 } 54 */ 55