summaryrefslogtreecommitdiff
path: root/libgo/go/encoding/xml/xml_test.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2020-01-02 15:05:27 -0800
committerIan Lance Taylor <iant@golang.org>2020-01-21 23:53:22 -0800
commit5a8ea165926cb0737ab03bc48c18dc5198ab5305 (patch)
tree962dc3357c57f019f85658f99e2e753e30201c27 /libgo/go/encoding/xml/xml_test.go
parent6ac6529e155c9baa0aaaed7aca06bd38ebda5b43 (diff)
libgo: update to Go1.14beta1
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/214297
Diffstat (limited to 'libgo/go/encoding/xml/xml_test.go')
-rw-r--r--libgo/go/encoding/xml/xml_test.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/libgo/go/encoding/xml/xml_test.go b/libgo/go/encoding/xml/xml_test.go
index ee4ffa24208..efddca43e91 100644
--- a/libgo/go/encoding/xml/xml_test.go
+++ b/libgo/go/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"