draw2d/draw2dsvg/xml_test.go

59 lines
1.3 KiB
Go
Raw Normal View History

2017-12-21 17:18:29 +00:00
// Copyright 2015 The draw2d Authors. All rights reserved.
// created: 16/12/2017 by Drahoslav Bednář
// Package draw2dsvg_test gives test coverage with the command:
// go test -cover ./... | grep -v "no test"
// (It should be run from its parent draw2d directory.)
package draw2dsvg
import (
"encoding/xml"
2017-12-24 14:31:09 +00:00
"testing"
2017-12-21 17:18:29 +00:00
)
// Test basic encoding of svg/xml elements
func TestXml(t *testing.T) {
2017-12-22 21:40:56 +00:00
2017-12-21 17:18:29 +00:00
svg := NewSvg()
svg.Groups = []*Group{&Group{
Groups: []*Group{
&Group{}, // nested groups
&Group{},
2017-12-21 17:18:29 +00:00
},
Texts: []*Text{
&Text{Text: "Hello"}, // text
&Text{Text: "world", Style: "opacity: 0.5"}, // text with style
2017-12-21 17:18:29 +00:00
},
Paths: []*Path{
&Path{Desc: "M100,200 C100,100 250,100 250,200 S400,300 400,200"}, // simple path
&Path{}, // empty path
2017-12-21 17:18:29 +00:00
},
}}
2017-12-24 14:31:09 +00:00
expectedOut := `<svg xmlns="http://www.w3.org/2000/svg" fill="none" stroke="none">
<defs></defs>
2017-12-21 17:18:29 +00:00
<g>
<g></g>
<g></g>
<path d="M100,200 C100,100 250,100 250,200 S400,300 400,200"></path>
<path d=""></path>
<text>Hello</text>
2017-12-24 14:31:09 +00:00
<text style="opacity: 0.5">world</text>
2017-12-21 17:18:29 +00:00
</g>
</svg>`
out, err := xml.MarshalIndent(svg, "", " ")
if err != nil {
t.Error(err)
}
if string(out) != expectedOut {
t.Errorf("svg output is not as expected\n"+
"got:\n%s\n\n"+
"want:\n%s\n",
string(out),
expectedOut,
)
}
}