File: xmlstruct_test.go

package info (click to toggle)
golang-github-christrenkamp-goxpath 1.0~alpha3%2Bgit20170922.c385f95-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 308 kB
  • sloc: sh: 16; makefile: 3; xml: 3
file content (49 lines) | stat: -rw-r--r-- 867 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
package xmlstruct

import (
	"encoding/xml"
	"testing"

	"github.com/ChrisTrenkamp/goxpath"
)

func TestSingleFields(t *testing.T) {
	str := struct {
		XMLName xml.Name `xml:"struct"`
		Elem    string   `xml:"elem"`
		Attr    string   `xml:"attr,attr"`
		Attr2   string   `xml:",attr"`
		Comm    string   `xml:",comment"`
		CD      string   `xml:",chardata"`
		Test    interface{}
	}{
		Elem:  "foo",
		Attr:  "bar",
		Attr2: "baz",
		Comm:  "steak",
		CD:    "eggs",
		Test: struct {
			Elem2 string `xml:"elem2"`
			Attr3 string `xml:",attr"`
		}{
			Elem2: "elem2",
			Attr3: "attr3",
		},
	}

	x := MustParseStruct(&str)
	x1, err := xml.Marshal(str)
	str1 := string(x1)
	if err != nil {
		t.Error(err)
	}
	str2, err := goxpath.MarshalStr(x)
	if err != nil {
		t.Error(err)
	}
	if str1 != str2 {
		t.Error("Strings not equal")
		t.Error(str1)
		t.Error(str2)
	}
}