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