File: xmlseq_whitespace_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 (43 lines) | stat: -rw-r--r-- 1,189 bytes parent folder | download
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
package mxj

import "testing"

var whiteSpaceDataSeqTest = []byte(`<books>
   <book seq="1" ser="5">
      <author>William T. Gaddis </author>
      <title> The Recognitions </title>
      <review> One of the great seminal American novels of the 20th century.</review>
   </book>
   <book seq="2">
      <author>Austin Tappan Wright</author>
      <title>Islandia</title>
      <review>An example of earlier 20th century American utopian fiction.</review>
   </book>
   <book seq="3" ser="6">
      <author> John Hawkes </author>
      <title> The Beetle Leg </title>
      <review> A lyrical novel about the construction of Ft. Peck Dam in Montana. </review>
   </book>
</books>`)

func TestNewMapXmlSeqWhiteSpace(t *testing.T) {
	t.Run("Testing NewMapFormattedXmlSeq with WhiteSpacing", func(t *testing.T) {
		DisableTrimWhiteSpace(true)

		m, err := NewMapFormattedXmlSeq(whiteSpaceDataSeqTest)
		if err != nil {
			t.Fatal(err)
		}

		m1 := MapSeq(m)
		x, err := m1.XmlIndent("", "   ")
		if err != nil {
			t.Fatal(err)
		}

		if string(x) != string(whiteSpaceDataSeqTest) {
			t.Fatalf("expected\n'%s' \ngot \n'%s'", whiteSpaceDataSeqTest, x)
		}
	})
	DisableTrimWhiteSpace(false)
}