Skip to content

Commit 1a7f45e

Browse files
committed
✨ (clockface): add svg struct for parser
1 parent 57ef7cc commit 1a7f45e

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

clockface_sample/clockface/clockface_acceptance_test.go

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,59 @@
11
package clockface_test
22

33
import (
4+
"bytes"
5+
"encoding/xml"
46
"strings"
57
"testing"
68
"time"
79

810
clockface "github.com/leetcode-golang-classroom/learn-golang-with-tests/clockface_sample/clockface"
911
)
1012

13+
type Svg struct {
14+
XMLName xml.Name `xml:"svg"`
15+
Text string `xml:",chardata"`
16+
Xmlns string `xml:"xmlns,attr"`
17+
Width string `xml:"width,attr"`
18+
Height string `xml:"height,attr"`
19+
ViewBox string `xml:"viewBox,attr"`
20+
Version string `xml:"version,attr"`
21+
Circle struct {
22+
Text string `xml:",chardata"`
23+
Cx string `xml:"cx,attr"`
24+
Cy string `xml:"cy,attr"`
25+
R string `xml:"r,attr"`
26+
Style string `xml:"style,attr"`
27+
} `xml:"circle"`
28+
Line []struct {
29+
Text string `xml:",chardata"`
30+
X1 string `xml:"x1,attr"`
31+
Y1 string `xml:"y1,attr"`
32+
X2 string `xml:"x2,attr"`
33+
Y2 string `xml:"y2,attr"`
34+
Style string `xml:"style,attr"`
35+
} `xml:"line"`
36+
}
37+
1138
func TestSVGWriterAtMidnight(t *testing.T) {
1239
tm := time.Date(1337, time.January, 1, 0, 0, 0, 0, time.UTC)
1340

14-
var b strings.Builder
41+
b := bytes.Buffer{}
1542
clockface.SVGWriter(&b, tm)
16-
got := b.String()
43+
svg := Svg{}
1744

18-
want := `<line x1="150" y1="150" x2="150.000" y2="60.000"`
45+
xml.Unmarshal(b.Bytes(), &svg)
1946

20-
if !strings.Contains(got, want) {
21-
t.Errorf("Expected to find the second hand %v, in the SVG output %v", want, got)
47+
x2 := "150.000"
48+
y2 := "60.000"
49+
50+
for _, line := range svg.Line {
51+
if line.X2 == x2 && line.Y2 == y2 {
52+
return
53+
}
2254
}
55+
56+
t.Errorf("Expected to find the second hand with x2 of %v and y2 of %v, in the SVG output %v", x2, y2, b.String())
2357
}
2458

2559
func TestSVGWriterAt30Seconds(t *testing.T) {

0 commit comments

Comments
 (0)