Skip to content

Commit 1017774

Browse files
committed
add TestTokenAutoClose
1 parent 7cc605b commit 1017774

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/encoding/xml/xml_test.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,37 @@ func TestValuelessAttrs(t *testing.T) {
644644
}
645645
}
646646

647+
const testInputAutoClose = `
648+
<lol>
649+
<lol></lol>
650+
`
651+
652+
var cookedTokensAutoClose = []Token{
653+
CharData("\n"),
654+
StartElement{Name:Name{Space:"", Local:"lol"}, Attr:[]Attr{}},
655+
EndElement{Name:Name{Space:"", Local:"lol"}},
656+
CharData("\n"),
657+
StartElement{Name:Name{Space:"", Local:"lol"}, Attr:[]Attr{}},
658+
EndElement{Name:Name{Space:"", Local:"lol"}},
659+
CharData("\n"),
660+
}
661+
662+
func TestTokenAutoClose(t *testing.T) {
663+
d := NewDecoder(strings.NewReader(testInputAutoClose))
664+
d.Strict = false
665+
d.AutoClose = []string{"LOL"}
666+
667+
for i, want := range cookedTokensAutoClose {
668+
have, err := d.Token()
669+
if err != nil {
670+
t.Fatalf("token %d: unexpected error: %s", i, err)
671+
}
672+
if !reflect.DeepEqual(have, want) {
673+
t.Errorf("token %d = %#v want %#v", i, have, want)
674+
}
675+
}
676+
}
677+
647678
func TestCopyTokenCharData(t *testing.T) {
648679
data := []byte("same data")
649680
var tok1 Token = CharData(data)
@@ -789,7 +820,6 @@ var characterTests = []struct {
789820
}
790821

791822
func TestDisallowedCharacters(t *testing.T) {
792-
793823
for i, tt := range characterTests {
794824
d := NewDecoder(strings.NewReader(tt.in))
795825
var err error

0 commit comments

Comments
 (0)