Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
38ff98b4
Commit
38ff98b4
authored
Jan 03, 2012
by
Michael Shields
Committed by
Andrew Gerrand
Jan 03, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
encoding/xml: use strings.Reader in tests.
R=golang-dev, adg CC=golang-dev
https://golang.org/cl/5502083
parent
c2b87ce0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
51 deletions
+27
-51
src/pkg/encoding/xml/embed_test.go
src/pkg/encoding/xml/embed_test.go
+8
-5
src/pkg/encoding/xml/read_test.go
src/pkg/encoding/xml/read_test.go
+6
-5
src/pkg/encoding/xml/xml_test.go
src/pkg/encoding/xml/xml_test.go
+13
-41
No files found.
src/pkg/encoding/xml/embed_test.go
View file @
38ff98b4
...
...
@@ -4,7 +4,10 @@
package
xml
import
"testing"
import
(
"strings"
"testing"
)
type
C
struct
{
Name
string
...
...
@@ -41,7 +44,7 @@ const _1a = `
// Tests that embedded structs are marshalled.
func
TestEmbedded1
(
t
*
testing
.
T
)
{
var
a
A
if
e
:=
Unmarshal
(
String
Reader
(
_1a
),
&
a
);
e
!=
nil
{
if
e
:=
Unmarshal
(
strings
.
New
Reader
(
_1a
),
&
a
);
e
!=
nil
{
t
.
Fatalf
(
"Unmarshal: %s"
,
e
)
}
if
a
.
FieldA
!=
"foo"
{
...
...
@@ -80,7 +83,7 @@ const _2a = `
// Tests that conflicting field names get excluded.
func
TestEmbedded2
(
t
*
testing
.
T
)
{
var
a
A2
if
e
:=
Unmarshal
(
String
Reader
(
_2a
),
&
a
);
e
!=
nil
{
if
e
:=
Unmarshal
(
strings
.
New
Reader
(
_2a
),
&
a
);
e
!=
nil
{
t
.
Fatalf
(
"Unmarshal: %s"
,
e
)
}
if
a
.
XY
!=
""
{
...
...
@@ -99,7 +102,7 @@ type A3 struct {
// Tests that private fields are not set.
func
TestEmbedded3
(
t
*
testing
.
T
)
{
var
a
A3
if
e
:=
Unmarshal
(
String
Reader
(
_2a
),
&
a
);
e
!=
nil
{
if
e
:=
Unmarshal
(
strings
.
New
Reader
(
_2a
),
&
a
);
e
!=
nil
{
t
.
Fatalf
(
"Unmarshal: %s"
,
e
)
}
if
a
.
xy
!=
""
{
...
...
@@ -115,7 +118,7 @@ type A4 struct {
// Tests that private fields are not set.
func
TestEmbedded4
(
t
*
testing
.
T
)
{
var
a
A4
if
e
:=
Unmarshal
(
String
Reader
(
_2a
),
&
a
);
e
!=
nil
{
if
e
:=
Unmarshal
(
strings
.
New
Reader
(
_2a
),
&
a
);
e
!=
nil
{
t
.
Fatalf
(
"Unmarshal: %s"
,
e
)
}
if
a
.
Any
!=
"foo"
{
...
...
src/pkg/encoding/xml/read_test.go
View file @
38ff98b4
...
...
@@ -6,6 +6,7 @@ package xml
import
(
"reflect"
"strings"
"testing"
)
...
...
@@ -13,7 +14,7 @@ import (
func
TestUnmarshalFeed
(
t
*
testing
.
T
)
{
var
f
Feed
if
err
:=
Unmarshal
(
String
Reader
(
atomFeedString
),
&
f
);
err
!=
nil
{
if
err
:=
Unmarshal
(
strings
.
New
Reader
(
atomFeedString
),
&
f
);
err
!=
nil
{
t
.
Fatalf
(
"Unmarshal: %s"
,
err
)
}
if
!
reflect
.
DeepEqual
(
f
,
atomFeed
)
{
...
...
@@ -298,7 +299,7 @@ var pathTests = []interface{}{
func
TestUnmarshalPaths
(
t
*
testing
.
T
)
{
for
_
,
pt
:=
range
pathTests
{
v
:=
reflect
.
New
(
reflect
.
TypeOf
(
pt
)
.
Elem
())
.
Interface
()
if
err
:=
Unmarshal
(
String
Reader
(
pathTestString
),
v
);
err
!=
nil
{
if
err
:=
Unmarshal
(
strings
.
New
Reader
(
pathTestString
),
v
);
err
!=
nil
{
t
.
Fatalf
(
"Unmarshal: %s"
,
err
)
}
if
!
reflect
.
DeepEqual
(
v
,
pt
)
{
...
...
@@ -328,7 +329,7 @@ var badPathTests = []struct {
func
TestUnmarshalBadPaths
(
t
*
testing
.
T
)
{
for
_
,
tt
:=
range
badPathTests
{
err
:=
Unmarshal
(
String
Reader
(
pathTestString
),
tt
.
v
)
err
:=
Unmarshal
(
strings
.
New
Reader
(
pathTestString
),
tt
.
v
)
if
!
reflect
.
DeepEqual
(
err
,
tt
.
e
)
{
t
.
Fatalf
(
"Unmarshal with %#v didn't fail properly: %#v"
,
tt
.
v
,
err
)
}
...
...
@@ -337,7 +338,7 @@ func TestUnmarshalBadPaths(t *testing.T) {
func
TestUnmarshalAttrs
(
t
*
testing
.
T
)
{
var
f
AttrTest
if
err
:=
Unmarshal
(
String
Reader
(
attrString
),
&
f
);
err
!=
nil
{
if
err
:=
Unmarshal
(
strings
.
New
Reader
(
attrString
),
&
f
);
err
!=
nil
{
t
.
Fatalf
(
"Unmarshal: %s"
,
err
)
}
if
!
reflect
.
DeepEqual
(
f
,
attrStruct
)
{
...
...
@@ -393,7 +394,7 @@ type TestThree struct {
func
TestUnmarshalWithoutNameType
(
t
*
testing
.
T
)
{
var
x
TestThree
if
err
:=
Unmarshal
(
String
Reader
(
withoutNameTypeData
),
&
x
);
err
!=
nil
{
if
err
:=
Unmarshal
(
strings
.
New
Reader
(
withoutNameTypeData
),
&
x
);
err
!=
nil
{
t
.
Fatalf
(
"Unmarshal: %s"
,
err
)
}
if
x
.
Attr
!=
OK
{
...
...
src/pkg/encoding/xml/xml_test.go
View file @
38ff98b4
...
...
@@ -154,36 +154,8 @@ var xmlInput = []string{
"<t>cdata]]></t>"
,
}
type
stringReader
struct
{
s
string
off
int
}
func
(
r
*
stringReader
)
Read
(
b
[]
byte
)
(
n
int
,
err
error
)
{
if
r
.
off
>=
len
(
r
.
s
)
{
return
0
,
io
.
EOF
}
for
r
.
off
<
len
(
r
.
s
)
&&
n
<
len
(
b
)
{
b
[
n
]
=
r
.
s
[
r
.
off
]
n
++
r
.
off
++
}
return
}
func
(
r
*
stringReader
)
ReadByte
()
(
b
byte
,
err
error
)
{
if
r
.
off
>=
len
(
r
.
s
)
{
return
0
,
io
.
EOF
}
b
=
r
.
s
[
r
.
off
]
r
.
off
++
return
}
func
StringReader
(
s
string
)
io
.
Reader
{
return
&
stringReader
{
s
,
0
}
}
func
TestRawToken
(
t
*
testing
.
T
)
{
p
:=
NewParser
(
String
Reader
(
testInput
))
p
:=
NewParser
(
strings
.
New
Reader
(
testInput
))
testRawToken
(
t
,
p
,
rawTokens
)
}
...
...
@@ -207,7 +179,7 @@ func (d *downCaser) Read(p []byte) (int, error) {
func
TestRawTokenAltEncoding
(
t
*
testing
.
T
)
{
sawEncoding
:=
""
p
:=
NewParser
(
String
Reader
(
testInputAltEncoding
))
p
:=
NewParser
(
strings
.
New
Reader
(
testInputAltEncoding
))
p
.
CharsetReader
=
func
(
charset
string
,
input
io
.
Reader
)
(
io
.
Reader
,
error
)
{
sawEncoding
=
charset
if
charset
!=
"x-testing-uppercase"
{
...
...
@@ -219,7 +191,7 @@ func TestRawTokenAltEncoding(t *testing.T) {
}
func
TestRawTokenAltEncodingNoConverter
(
t
*
testing
.
T
)
{
p
:=
NewParser
(
String
Reader
(
testInputAltEncoding
))
p
:=
NewParser
(
strings
.
New
Reader
(
testInputAltEncoding
))
token
,
err
:=
p
.
RawToken
()
if
token
==
nil
{
t
.
Fatalf
(
"expected a token on first RawToken call"
)
...
...
@@ -286,7 +258,7 @@ var nestedDirectivesTokens = []Token{
}
func
TestNestedDirectives
(
t
*
testing
.
T
)
{
p
:=
NewParser
(
String
Reader
(
nestedDirectivesInput
))
p
:=
NewParser
(
strings
.
New
Reader
(
nestedDirectivesInput
))
for
i
,
want
:=
range
nestedDirectivesTokens
{
have
,
err
:=
p
.
Token
()
...
...
@@ -300,7 +272,7 @@ func TestNestedDirectives(t *testing.T) {
}
func
TestToken
(
t
*
testing
.
T
)
{
p
:=
NewParser
(
String
Reader
(
testInput
))
p
:=
NewParser
(
strings
.
New
Reader
(
testInput
))
for
i
,
want
:=
range
cookedTokens
{
have
,
err
:=
p
.
Token
()
...
...
@@ -315,7 +287,7 @@ func TestToken(t *testing.T) {
func
TestSyntax
(
t
*
testing
.
T
)
{
for
i
:=
range
xmlInput
{
p
:=
NewParser
(
String
Reader
(
xmlInput
[
i
]))
p
:=
NewParser
(
strings
.
New
Reader
(
xmlInput
[
i
]))
var
err
error
for
_
,
err
=
p
.
Token
();
err
==
nil
;
_
,
err
=
p
.
Token
()
{
}
...
...
@@ -424,7 +396,7 @@ func TestIssue569(t *testing.T) {
func
TestUnquotedAttrs
(
t
*
testing
.
T
)
{
data
:=
"<tag attr=azAZ09:-_
\t
>"
p
:=
NewParser
(
String
Reader
(
data
))
p
:=
NewParser
(
strings
.
New
Reader
(
data
))
p
.
Strict
=
false
token
,
err
:=
p
.
Token
()
if
_
,
ok
:=
err
.
(
*
SyntaxError
);
ok
{
...
...
@@ -450,7 +422,7 @@ func TestValuelessAttrs(t *testing.T) {
{
"<input checked />"
,
"input"
,
"checked"
},
}
for
_
,
test
:=
range
tests
{
p
:=
NewParser
(
String
Reader
(
test
[
0
]))
p
:=
NewParser
(
strings
.
New
Reader
(
test
[
0
]))
p
.
Strict
=
false
token
,
err
:=
p
.
Token
()
if
_
,
ok
:=
err
.
(
*
SyntaxError
);
ok
{
...
...
@@ -500,7 +472,7 @@ func TestCopyTokenStartElement(t *testing.T) {
func
TestSyntaxErrorLineNum
(
t
*
testing
.
T
)
{
testInput
:=
"<P>Foo<P>
\n\n
<P>Bar</>
\n
"
p
:=
NewParser
(
String
Reader
(
testInput
))
p
:=
NewParser
(
strings
.
New
Reader
(
testInput
))
var
err
error
for
_
,
err
=
p
.
Token
();
err
==
nil
;
_
,
err
=
p
.
Token
()
{
}
...
...
@@ -515,7 +487,7 @@ func TestSyntaxErrorLineNum(t *testing.T) {
func
TestTrailingRawToken
(
t
*
testing
.
T
)
{
input
:=
`<FOO></FOO> `
p
:=
NewParser
(
String
Reader
(
input
))
p
:=
NewParser
(
strings
.
New
Reader
(
input
))
var
err
error
for
_
,
err
=
p
.
RawToken
();
err
==
nil
;
_
,
err
=
p
.
RawToken
()
{
}
...
...
@@ -526,7 +498,7 @@ func TestTrailingRawToken(t *testing.T) {
func
TestTrailingToken
(
t
*
testing
.
T
)
{
input
:=
`<FOO></FOO> `
p
:=
NewParser
(
String
Reader
(
input
))
p
:=
NewParser
(
strings
.
New
Reader
(
input
))
var
err
error
for
_
,
err
=
p
.
Token
();
err
==
nil
;
_
,
err
=
p
.
Token
()
{
}
...
...
@@ -537,7 +509,7 @@ func TestTrailingToken(t *testing.T) {
func
TestEntityInsideCDATA
(
t
*
testing
.
T
)
{
input
:=
`<test><![CDATA[ &val=foo ]]></test>`
p
:=
NewParser
(
String
Reader
(
input
))
p
:=
NewParser
(
strings
.
New
Reader
(
input
))
var
err
error
for
_
,
err
=
p
.
Token
();
err
==
nil
;
_
,
err
=
p
.
Token
()
{
}
...
...
@@ -569,7 +541,7 @@ var characterTests = []struct {
func
TestDisallowedCharacters
(
t
*
testing
.
T
)
{
for
i
,
tt
:=
range
characterTests
{
p
:=
NewParser
(
String
Reader
(
tt
.
in
))
p
:=
NewParser
(
strings
.
New
Reader
(
tt
.
in
))
var
err
error
for
err
==
nil
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment