-
Notifications
You must be signed in to change notification settings - Fork 89
/
options_test.go
46 lines (41 loc) · 1.18 KB
/
options_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
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)
}