File: exists_test.go

package info (click to toggle)
golang-github-clbanning-mxj 2.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,200 kB
  • sloc: xml: 176; makefile: 4
file content (54 lines) | stat: -rw-r--r-- 1,033 bytes parent folder | download | duplicates (2)
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")
	}
}
*/