Skip to content

Commit 96012af

Browse files
committed
add tests for miku#6
1 parent 57a6cd7 commit 96012af

File tree

5 files changed

+50
-4
lines changed

5 files changed

+50
-4
lines changed

structwriter_test.go

+20-4
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@ func skipUntilType(b []byte) []byte {
5252

5353
func TestWriteNode(t *testing.T) {
5454
var cases = []struct {
55-
input string // Input XML filename.
56-
result string // Generated struct filename.
57-
withComments bool
58-
err error
55+
input string // Input XML filename.
56+
result string // Generated struct filename.
57+
withComments bool
58+
uniqueExamples bool
59+
err error
5960
}{
6061
{
6162
input: "testdata/w.1.xml",
@@ -116,6 +117,20 @@ func TestWriteNode(t *testing.T) {
116117
withComments: true,
117118
err: nil,
118119
},
120+
{
121+
input: "testdata/w.12.xml",
122+
result: "testdata/w.12.go",
123+
withComments: true,
124+
uniqueExamples: false,
125+
err: nil,
126+
},
127+
{
128+
input: "testdata/w.13.xml",
129+
result: "testdata/w.13.go",
130+
withComments: true,
131+
uniqueExamples: true,
132+
err: nil,
133+
},
119134
}
120135

121136
for _, c := range cases {
@@ -135,6 +150,7 @@ func TestWriteNode(t *testing.T) {
135150
var buf bytes.Buffer
136151
sw := NewStructWriter(&buf)
137152
sw.WithComments = c.withComments
153+
sw.UniqueExamples = c.uniqueExamples
138154

139155
if err := sw.WriteNode(node); err != c.err {
140156
t.Errorf("WriteNode failed: got %v, want %v", err, c.err)

testdata/w.12.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import "encoding/xml"
2+
3+
// List was generated 2018-11-23 14:50:36 by tir on nexus.
4+
type List struct {
5+
XMLName xml.Name `xml:"list"`
6+
Text string `xml:",chardata"`
7+
Value []struct {
8+
Text string `xml:",chardata"` // a, a
9+
} `xml:"value"`
10+
}
11+

testdata/w.12.xml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<list>
2+
<value>a</value>
3+
<value>a</value>
4+
</list>

testdata/w.13.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import "encoding/xml"
2+
3+
// List was generated 2018-11-23 14:50:36 by tir on nexus.
4+
type List struct {
5+
XMLName xml.Name `xml:"list"`
6+
Text string `xml:",chardata"`
7+
Value []struct {
8+
Text string `xml:",chardata"` // a
9+
} `xml:"value"`
10+
}
11+

testdata/w.13.xml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<list>
2+
<value>a</value>
3+
<value>a</value>
4+
</list>

0 commit comments

Comments
 (0)