Skip to content

Commit 7cc605b

Browse files
committed
test all cases of CopyToken
1 parent d3956dc commit 7cc605b

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/encoding/xml/xml_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,45 @@ func TestCopyTokenCharData(t *testing.T) {
657657
}
658658
}
659659

660+
func TestCopyTokenComment(t *testing.T) {
661+
data := []byte("same data")
662+
var tok1 Token = Comment(data)
663+
tok2 := CopyToken(tok1)
664+
if !reflect.DeepEqual(tok1, tok2) {
665+
t.Error("CopyToken(Comment) != Comment")
666+
}
667+
data[1] = 'o'
668+
if reflect.DeepEqual(tok1, tok2) {
669+
t.Error("CopyToken(Comment) uses same buffer.")
670+
}
671+
}
672+
673+
func TestCopyTokenDirective(t *testing.T) {
674+
data := []byte("same data")
675+
var tok1 Token = Directive(data)
676+
tok2 := CopyToken(tok1)
677+
if !reflect.DeepEqual(tok1, tok2) {
678+
t.Error("CopyToken(Directive) != Directive")
679+
}
680+
data[1] = 'o'
681+
if reflect.DeepEqual(tok1, tok2) {
682+
t.Error("CopyToken(Directive) uses same buffer.")
683+
}
684+
}
685+
686+
func TestCopyTokenProcInst(t *testing.T) {
687+
data := []byte("same data")
688+
var tok1 Token = ProcInst{"hello", data}
689+
tok2 := CopyToken(tok1)
690+
if !reflect.DeepEqual(tok1, tok2) {
691+
t.Error("CopyToken(ProcInst) != ProcInst")
692+
}
693+
data[1] = 'o'
694+
if reflect.DeepEqual(tok1, tok2) {
695+
t.Error("CopyToken(ProcInst) uses same buffer.")
696+
}
697+
}
698+
660699
func TestCopyTokenStartElement(t *testing.T) {
661700
elt := StartElement{Name{"", "hello"}, []Attr{{Name{"", "lang"}, "en"}}}
662701
var tok1 Token = elt
@@ -673,6 +712,19 @@ func TestCopyTokenStartElement(t *testing.T) {
673712
}
674713
}
675714

715+
func TestCopyTokenDefaultCase(t *testing.T) {
716+
data := []byte("same data")
717+
var tok1 = Token(data)
718+
tok2 := CopyToken(data)
719+
if !reflect.DeepEqual(tok1, tok2) {
720+
t.Error("CopyToken(Token]) != Token")
721+
}
722+
data[1] = 'o'
723+
if !reflect.DeepEqual(tok1, tok2) {
724+
t.Error("CopyToken(CharData) uses different buffer.")
725+
}
726+
}
727+
676728
func TestSyntaxErrorLineNum(t *testing.T) {
677729
testInput := "<P>Foo<P>\n\n<P>Bar</>\n"
678730
d := NewDecoder(strings.NewReader(testInput))

0 commit comments

Comments
 (0)