aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/xml/xml_test.go
diff options
context:
space:
mode:
authorThan McIntosh <thanm@google.com>2019-11-01 10:44:44 -0400
committerThan McIntosh <thanm@google.com>2019-11-01 10:45:24 -0400
commitc0555a2a7a0ca83fdbb55219299fcfe1ff33e4df (patch)
tree25c35dc6bf5b8134906338df0f612fbe75089ca7 /src/encoding/xml/xml_test.go
parent219922e95b8e49cfb94da9de0c48edb22a2e7054 (diff)
parent8405cd3005a5274e80e41676146629c4086b6380 (diff)
downloadgo-c0555a2a7a0ca83fdbb55219299fcfe1ff33e4df.tar.xz
[dev.link] all: merge branch 'master' into dev.link
Fixed a couple of minor conflicts in lib.go and deadcode.go relating to debug logging. Change-Id: I58335fc42ab1f1f3409fd8354da4f26419e8fb22
Diffstat (limited to 'src/encoding/xml/xml_test.go')
-rw-r--r--src/encoding/xml/xml_test.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/encoding/xml/xml_test.go b/src/encoding/xml/xml_test.go
index ee4ffa2420..efddca43e9 100644
--- a/src/encoding/xml/xml_test.go
+++ b/src/encoding/xml/xml_test.go
@@ -14,6 +14,51 @@ import (
"unicode/utf8"
)
+type toks struct {
+ earlyEOF bool
+ t []Token
+}
+
+func (t *toks) Token() (Token, error) {
+ if len(t.t) == 0 {
+ return nil, io.EOF
+ }
+ var tok Token
+ tok, t.t = t.t[0], t.t[1:]
+ if t.earlyEOF && len(t.t) == 0 {
+ return tok, io.EOF
+ }
+ return tok, nil
+}
+
+func TestDecodeEOF(t *testing.T) {
+ start := StartElement{Name: Name{Local: "test"}}
+ t.Run("EarlyEOF", func(t *testing.T) {
+ d := NewTokenDecoder(&toks{earlyEOF: true, t: []Token{
+ start,
+ start.End(),
+ }})
+ err := d.Decode(&struct {
+ XMLName Name `xml:"test"`
+ }{})
+ if err != nil {
+ t.Error(err)
+ }
+ })
+ t.Run("LateEOF", func(t *testing.T) {
+ d := NewTokenDecoder(&toks{t: []Token{
+ start,
+ start.End(),
+ }})
+ err := d.Decode(&struct {
+ XMLName Name `xml:"test"`
+ }{})
+ if err != nil {
+ t.Error(err)
+ }
+ })
+}
+
const testInput = `
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"