Adds support for go mod (finally) (#164)
This commit is contained in:
parent
962b9abdec
commit
c1468e8ae4
89 changed files with 1162 additions and 965 deletions
|
|
@ -6,18 +6,18 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/blend/go-sdk/assert"
|
||||
"github.com/wcharczuk/go-chart/drawing"
|
||||
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||
)
|
||||
|
||||
func TestVectorRendererPath(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
vr, err := SVG(100, 100)
|
||||
assert.Nil(err)
|
||||
testutil.AssertNil(t, err)
|
||||
|
||||
typed, isTyped := vr.(*vectorRenderer)
|
||||
assert.True(isTyped)
|
||||
testutil.AssertTrue(t, isTyped)
|
||||
|
||||
typed.MoveTo(0, 0)
|
||||
typed.LineTo(100, 100)
|
||||
|
|
@ -27,37 +27,37 @@ func TestVectorRendererPath(t *testing.T) {
|
|||
|
||||
buffer := bytes.NewBuffer([]byte{})
|
||||
err = typed.Save(buffer)
|
||||
assert.Nil(err)
|
||||
testutil.AssertNil(t, err)
|
||||
|
||||
raw := string(buffer.Bytes())
|
||||
|
||||
assert.True(strings.HasPrefix(raw, "<svg"))
|
||||
assert.True(strings.HasSuffix(raw, "</svg>"))
|
||||
testutil.AssertTrue(t, strings.HasPrefix(raw, "<svg"))
|
||||
testutil.AssertTrue(t, strings.HasSuffix(raw, "</svg>"))
|
||||
}
|
||||
|
||||
func TestVectorRendererMeasureText(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
f, err := GetDefaultFont()
|
||||
assert.Nil(err)
|
||||
testutil.AssertNil(t, err)
|
||||
|
||||
vr, err := SVG(100, 100)
|
||||
assert.Nil(err)
|
||||
testutil.AssertNil(t, err)
|
||||
|
||||
vr.SetDPI(DefaultDPI)
|
||||
vr.SetFont(f)
|
||||
vr.SetFontSize(12.0)
|
||||
|
||||
tb := vr.MeasureText("Ljp")
|
||||
assert.Equal(21, tb.Width())
|
||||
assert.Equal(15, tb.Height())
|
||||
testutil.AssertEqual(t, 21, tb.Width())
|
||||
testutil.AssertEqual(t, 15, tb.Height())
|
||||
}
|
||||
|
||||
func TestCanvasStyleSVG(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
f, err := GetDefaultFont()
|
||||
assert.Nil(err)
|
||||
testutil.AssertNil(t, err)
|
||||
|
||||
set := Style{
|
||||
StrokeColor: drawing.ColorWhite,
|
||||
|
|
@ -71,37 +71,35 @@ func TestCanvasStyleSVG(t *testing.T) {
|
|||
canvas := &canvas{dpi: DefaultDPI}
|
||||
|
||||
svgString := canvas.styleAsSVG(set)
|
||||
assert.NotEmpty(svgString)
|
||||
assert.True(strings.HasPrefix(svgString, "style=\""))
|
||||
assert.True(strings.Contains(svgString, "stroke:rgba(255,255,255,1.0)"))
|
||||
assert.True(strings.Contains(svgString, "stroke-width:5"))
|
||||
assert.True(strings.Contains(svgString, "fill:rgba(255,255,255,1.0)"))
|
||||
assert.True(strings.HasSuffix(svgString, "\""))
|
||||
testutil.AssertNotEmpty(t, svgString)
|
||||
testutil.AssertTrue(t, strings.HasPrefix(svgString, "style=\""))
|
||||
testutil.AssertTrue(t, strings.Contains(svgString, "stroke:rgba(255,255,255,1.0)"))
|
||||
testutil.AssertTrue(t, strings.Contains(svgString, "stroke-width:5"))
|
||||
testutil.AssertTrue(t, strings.Contains(svgString, "fill:rgba(255,255,255,1.0)"))
|
||||
testutil.AssertTrue(t, strings.HasSuffix(svgString, "\""))
|
||||
}
|
||||
|
||||
func TestCanvasClassSVG(t *testing.T) {
|
||||
as := assert.New(t)
|
||||
|
||||
set := Style{
|
||||
ClassName: "test-class",
|
||||
}
|
||||
|
||||
canvas := &canvas{dpi: DefaultDPI}
|
||||
|
||||
as.Equal("class=\"test-class\"", canvas.styleAsSVG(set))
|
||||
testutil.AssertEqual(t, "class=\"test-class\"", canvas.styleAsSVG(set))
|
||||
}
|
||||
|
||||
func TestCanvasCustomInlineStylesheet(t *testing.T) {
|
||||
b := strings.Builder{}
|
||||
|
||||
canvas := &canvas{
|
||||
w: &b,
|
||||
css: ".background { fill: red }",
|
||||
w: &b,
|
||||
css: ".background { fill: red }",
|
||||
}
|
||||
|
||||
canvas.Start(200, 200)
|
||||
|
||||
assert.New(t).Contains(b.String(), fmt.Sprintf(`<style type="text/css"><![CDATA[%s]]></style>`, canvas.css))
|
||||
testutil.AssertContains(t, b.String(), fmt.Sprintf(`<style type="text/css"><![CDATA[%s]]></style>`, canvas.css))
|
||||
}
|
||||
|
||||
func TestCanvasCustomInlineStylesheetWithNonce(t *testing.T) {
|
||||
|
|
@ -115,5 +113,5 @@ func TestCanvasCustomInlineStylesheetWithNonce(t *testing.T) {
|
|||
|
||||
canvas.Start(200, 200)
|
||||
|
||||
assert.New(t).Contains(b.String(), fmt.Sprintf(`<style type="text/css" nonce="%s"><![CDATA[%s]]></style>`, canvas.nonce, canvas.css))
|
||||
}
|
||||
testutil.AssertContains(t, b.String(), fmt.Sprintf(`<style type="text/css" nonce="%s"><![CDATA[%s]]></style>`, canvas.nonce, canvas.css))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue