File: options_test.go

package info (click to toggle)
golang-github-antchfx-xmlquery 1.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 196 kB
  • sloc: makefile: 2
file content (46 lines) | stat: -rw-r--r-- 1,209 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
44
45
46
package xmlquery

import (
	"bytes"
	"encoding/xml"
	"testing"
)

func TestApplyOptions(t *testing.T) {
	parser := &parser{
		decoder: xml.NewDecoder(bytes.NewReader(make([]byte, 0))),
	}
	options := ParserOptions{
		Decoder: &DecoderOptions{
			Strict: false,
			AutoClose: []string{"foo"},
			Entity: map[string]string{
				"bar": "baz",
			},
		},
	}

	options.apply(parser)
	if parser.decoder.Strict != options.Decoder.Strict {
		t.Fatalf("Expected Strict attribute of %v, got %v instead", options.Decoder.Strict, parser.decoder.Strict)
	}
	if parser.decoder.AutoClose[0] != options.Decoder.AutoClose[0] {
		t.Fatalf("Expected AutoClose attribute with %v, got %v instead", options.Decoder.AutoClose, parser.decoder.AutoClose)
	}
	if parser.decoder.Entity["bar"] != options.Decoder.Entity["bar"] {
		t.Fatalf("Expected Entity mode of %v, got %v instead", options.Decoder.Entity, parser.decoder.Entity)
	}
}

func TestApplyEmptyOptions(t *testing.T) {
	parser := &parser{
		decoder: xml.NewDecoder(bytes.NewReader(make([]byte, 0))),
	}
	options := ParserOptions{
		Decoder: nil,
	}

	// Only testing for the absence of errors since we are not
	// expecting this call to do anything
	options.apply(parser)
}