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
140
style_test.go
140
style_test.go
|
|
@ -3,121 +3,121 @@ package chart
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/blend/go-sdk/assert"
|
||||
"github.com/golang/freetype/truetype"
|
||||
"github.com/wcharczuk/go-chart/drawing"
|
||||
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||
"github.com/wcharczuk/go-chart/v2/testutil"
|
||||
)
|
||||
|
||||
func TestStyleIsZero(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
zero := Style{}
|
||||
assert.True(zero.IsZero())
|
||||
testutil.AssertTrue(t, zero.IsZero())
|
||||
|
||||
strokeColor := Style{StrokeColor: drawing.ColorWhite}
|
||||
assert.False(strokeColor.IsZero())
|
||||
testutil.AssertFalse(t, strokeColor.IsZero())
|
||||
|
||||
fillColor := Style{FillColor: drawing.ColorWhite}
|
||||
assert.False(fillColor.IsZero())
|
||||
testutil.AssertFalse(t, fillColor.IsZero())
|
||||
|
||||
strokeWidth := Style{StrokeWidth: 5.0}
|
||||
assert.False(strokeWidth.IsZero())
|
||||
testutil.AssertFalse(t, strokeWidth.IsZero())
|
||||
|
||||
fontSize := Style{FontSize: 12.0}
|
||||
assert.False(fontSize.IsZero())
|
||||
testutil.AssertFalse(t, fontSize.IsZero())
|
||||
|
||||
fontColor := Style{FontColor: drawing.ColorWhite}
|
||||
assert.False(fontColor.IsZero())
|
||||
testutil.AssertFalse(t, fontColor.IsZero())
|
||||
|
||||
font := Style{Font: &truetype.Font{}}
|
||||
assert.False(font.IsZero())
|
||||
testutil.AssertFalse(t, font.IsZero())
|
||||
}
|
||||
|
||||
func TestStyleGetStrokeColor(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
unset := Style{}
|
||||
assert.Equal(drawing.ColorTransparent, unset.GetStrokeColor())
|
||||
assert.Equal(drawing.ColorWhite, unset.GetStrokeColor(drawing.ColorWhite))
|
||||
testutil.AssertEqual(t, drawing.ColorTransparent, unset.GetStrokeColor())
|
||||
testutil.AssertEqual(t, drawing.ColorWhite, unset.GetStrokeColor(drawing.ColorWhite))
|
||||
|
||||
set := Style{StrokeColor: drawing.ColorWhite}
|
||||
assert.Equal(drawing.ColorWhite, set.GetStrokeColor())
|
||||
assert.Equal(drawing.ColorWhite, set.GetStrokeColor(drawing.ColorBlack))
|
||||
testutil.AssertEqual(t, drawing.ColorWhite, set.GetStrokeColor())
|
||||
testutil.AssertEqual(t, drawing.ColorWhite, set.GetStrokeColor(drawing.ColorBlack))
|
||||
}
|
||||
|
||||
func TestStyleGetFillColor(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
unset := Style{}
|
||||
assert.Equal(drawing.ColorTransparent, unset.GetFillColor())
|
||||
assert.Equal(drawing.ColorWhite, unset.GetFillColor(drawing.ColorWhite))
|
||||
testutil.AssertEqual(t, drawing.ColorTransparent, unset.GetFillColor())
|
||||
testutil.AssertEqual(t, drawing.ColorWhite, unset.GetFillColor(drawing.ColorWhite))
|
||||
|
||||
set := Style{FillColor: drawing.ColorWhite}
|
||||
assert.Equal(drawing.ColorWhite, set.GetFillColor())
|
||||
assert.Equal(drawing.ColorWhite, set.GetFillColor(drawing.ColorBlack))
|
||||
testutil.AssertEqual(t, drawing.ColorWhite, set.GetFillColor())
|
||||
testutil.AssertEqual(t, drawing.ColorWhite, set.GetFillColor(drawing.ColorBlack))
|
||||
}
|
||||
|
||||
func TestStyleGetStrokeWidth(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
unset := Style{}
|
||||
assert.Equal(DefaultStrokeWidth, unset.GetStrokeWidth())
|
||||
assert.Equal(DefaultStrokeWidth+1, unset.GetStrokeWidth(DefaultStrokeWidth+1))
|
||||
testutil.AssertEqual(t, DefaultStrokeWidth, unset.GetStrokeWidth())
|
||||
testutil.AssertEqual(t, DefaultStrokeWidth+1, unset.GetStrokeWidth(DefaultStrokeWidth+1))
|
||||
|
||||
set := Style{StrokeWidth: DefaultStrokeWidth + 2}
|
||||
assert.Equal(DefaultStrokeWidth+2, set.GetStrokeWidth())
|
||||
assert.Equal(DefaultStrokeWidth+2, set.GetStrokeWidth(DefaultStrokeWidth+1))
|
||||
testutil.AssertEqual(t, DefaultStrokeWidth+2, set.GetStrokeWidth())
|
||||
testutil.AssertEqual(t, DefaultStrokeWidth+2, set.GetStrokeWidth(DefaultStrokeWidth+1))
|
||||
}
|
||||
|
||||
func TestStyleGetFontSize(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
unset := Style{}
|
||||
assert.Equal(DefaultFontSize, unset.GetFontSize())
|
||||
assert.Equal(DefaultFontSize+1, unset.GetFontSize(DefaultFontSize+1))
|
||||
testutil.AssertEqual(t, DefaultFontSize, unset.GetFontSize())
|
||||
testutil.AssertEqual(t, DefaultFontSize+1, unset.GetFontSize(DefaultFontSize+1))
|
||||
|
||||
set := Style{FontSize: DefaultFontSize + 2}
|
||||
assert.Equal(DefaultFontSize+2, set.GetFontSize())
|
||||
assert.Equal(DefaultFontSize+2, set.GetFontSize(DefaultFontSize+1))
|
||||
testutil.AssertEqual(t, DefaultFontSize+2, set.GetFontSize())
|
||||
testutil.AssertEqual(t, DefaultFontSize+2, set.GetFontSize(DefaultFontSize+1))
|
||||
}
|
||||
|
||||
func TestStyleGetFontColor(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
unset := Style{}
|
||||
assert.Equal(drawing.ColorTransparent, unset.GetFontColor())
|
||||
assert.Equal(drawing.ColorWhite, unset.GetFontColor(drawing.ColorWhite))
|
||||
testutil.AssertEqual(t, drawing.ColorTransparent, unset.GetFontColor())
|
||||
testutil.AssertEqual(t, drawing.ColorWhite, unset.GetFontColor(drawing.ColorWhite))
|
||||
|
||||
set := Style{FontColor: drawing.ColorWhite}
|
||||
assert.Equal(drawing.ColorWhite, set.GetFontColor())
|
||||
assert.Equal(drawing.ColorWhite, set.GetFontColor(drawing.ColorBlack))
|
||||
testutil.AssertEqual(t, drawing.ColorWhite, set.GetFontColor())
|
||||
testutil.AssertEqual(t, drawing.ColorWhite, set.GetFontColor(drawing.ColorBlack))
|
||||
}
|
||||
|
||||
func TestStyleGetFont(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
f, err := GetDefaultFont()
|
||||
assert.Nil(err)
|
||||
testutil.AssertNil(t, err)
|
||||
|
||||
unset := Style{}
|
||||
assert.Nil(unset.GetFont())
|
||||
assert.Equal(f, unset.GetFont(f))
|
||||
testutil.AssertNil(t, unset.GetFont())
|
||||
testutil.AssertEqual(t, f, unset.GetFont(f))
|
||||
|
||||
set := Style{Font: f}
|
||||
assert.NotNil(set.GetFont())
|
||||
testutil.AssertNotNil(t, set.GetFont())
|
||||
}
|
||||
|
||||
func TestStyleGetPadding(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
unset := Style{}
|
||||
assert.True(unset.GetPadding().IsZero())
|
||||
assert.False(unset.GetPadding(DefaultBackgroundPadding).IsZero())
|
||||
assert.Equal(DefaultBackgroundPadding, unset.GetPadding(DefaultBackgroundPadding))
|
||||
testutil.AssertTrue(t, unset.GetPadding().IsZero())
|
||||
testutil.AssertFalse(t, unset.GetPadding(DefaultBackgroundPadding).IsZero())
|
||||
testutil.AssertEqual(t, DefaultBackgroundPadding, unset.GetPadding(DefaultBackgroundPadding))
|
||||
|
||||
set := Style{Padding: DefaultBackgroundPadding}
|
||||
assert.False(set.GetPadding().IsZero())
|
||||
assert.Equal(DefaultBackgroundPadding, set.GetPadding())
|
||||
assert.Equal(DefaultBackgroundPadding, set.GetPadding(Box{
|
||||
testutil.AssertFalse(t, set.GetPadding().IsZero())
|
||||
testutil.AssertEqual(t, DefaultBackgroundPadding, set.GetPadding())
|
||||
testutil.AssertEqual(t, DefaultBackgroundPadding, set.GetPadding(Box{
|
||||
Top: DefaultBackgroundPadding.Top + 1,
|
||||
Left: DefaultBackgroundPadding.Left + 1,
|
||||
Right: DefaultBackgroundPadding.Right + 1,
|
||||
|
|
@ -126,10 +126,10 @@ func TestStyleGetPadding(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestStyleWithDefaultsFrom(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
f, err := GetDefaultFont()
|
||||
assert.Nil(err)
|
||||
testutil.AssertNil(t, err)
|
||||
|
||||
unset := Style{}
|
||||
set := Style{
|
||||
|
|
@ -142,11 +142,11 @@ func TestStyleWithDefaultsFrom(t *testing.T) {
|
|||
}
|
||||
|
||||
coalesced := unset.InheritFrom(set)
|
||||
assert.Equal(set, coalesced)
|
||||
testutil.AssertEqual(t, set, coalesced)
|
||||
}
|
||||
|
||||
func TestStyleGetStrokeOptions(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
set := Style{
|
||||
StrokeColor: drawing.ColorWhite,
|
||||
|
|
@ -156,14 +156,14 @@ func TestStyleGetStrokeOptions(t *testing.T) {
|
|||
Padding: DefaultBackgroundPadding,
|
||||
}
|
||||
svgStroke := set.GetStrokeOptions()
|
||||
assert.False(svgStroke.StrokeColor.IsZero())
|
||||
assert.NotZero(svgStroke.StrokeWidth)
|
||||
assert.True(svgStroke.FillColor.IsZero())
|
||||
assert.True(svgStroke.FontColor.IsZero())
|
||||
testutil.AssertFalse(t, svgStroke.StrokeColor.IsZero())
|
||||
testutil.AssertNotZero(t, svgStroke.StrokeWidth)
|
||||
testutil.AssertTrue(t, svgStroke.FillColor.IsZero())
|
||||
testutil.AssertTrue(t, svgStroke.FontColor.IsZero())
|
||||
}
|
||||
|
||||
func TestStyleGetFillOptions(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
set := Style{
|
||||
StrokeColor: drawing.ColorWhite,
|
||||
|
|
@ -173,14 +173,14 @@ func TestStyleGetFillOptions(t *testing.T) {
|
|||
Padding: DefaultBackgroundPadding,
|
||||
}
|
||||
svgFill := set.GetFillOptions()
|
||||
assert.False(svgFill.FillColor.IsZero())
|
||||
assert.Zero(svgFill.StrokeWidth)
|
||||
assert.True(svgFill.StrokeColor.IsZero())
|
||||
assert.True(svgFill.FontColor.IsZero())
|
||||
testutil.AssertFalse(t, svgFill.FillColor.IsZero())
|
||||
testutil.AssertZero(t, svgFill.StrokeWidth)
|
||||
testutil.AssertTrue(t, svgFill.StrokeColor.IsZero())
|
||||
testutil.AssertTrue(t, svgFill.FontColor.IsZero())
|
||||
}
|
||||
|
||||
func TestStyleGetFillAndStrokeOptions(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
set := Style{
|
||||
StrokeColor: drawing.ColorWhite,
|
||||
|
|
@ -190,14 +190,14 @@ func TestStyleGetFillAndStrokeOptions(t *testing.T) {
|
|||
Padding: DefaultBackgroundPadding,
|
||||
}
|
||||
svgFillAndStroke := set.GetFillAndStrokeOptions()
|
||||
assert.False(svgFillAndStroke.FillColor.IsZero())
|
||||
assert.NotZero(svgFillAndStroke.StrokeWidth)
|
||||
assert.False(svgFillAndStroke.StrokeColor.IsZero())
|
||||
assert.True(svgFillAndStroke.FontColor.IsZero())
|
||||
testutil.AssertFalse(t, svgFillAndStroke.FillColor.IsZero())
|
||||
testutil.AssertNotZero(t, svgFillAndStroke.StrokeWidth)
|
||||
testutil.AssertFalse(t, svgFillAndStroke.StrokeColor.IsZero())
|
||||
testutil.AssertTrue(t, svgFillAndStroke.FontColor.IsZero())
|
||||
}
|
||||
|
||||
func TestStyleGetTextOptions(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
// replaced new assertions helper
|
||||
|
||||
set := Style{
|
||||
StrokeColor: drawing.ColorWhite,
|
||||
|
|
@ -207,8 +207,8 @@ func TestStyleGetTextOptions(t *testing.T) {
|
|||
Padding: DefaultBackgroundPadding,
|
||||
}
|
||||
svgStroke := set.GetTextOptions()
|
||||
assert.True(svgStroke.StrokeColor.IsZero())
|
||||
assert.Zero(svgStroke.StrokeWidth)
|
||||
assert.True(svgStroke.FillColor.IsZero())
|
||||
assert.False(svgStroke.FontColor.IsZero())
|
||||
testutil.AssertTrue(t, svgStroke.StrokeColor.IsZero())
|
||||
testutil.AssertZero(t, svgStroke.StrokeWidth)
|
||||
testutil.AssertTrue(t, svgStroke.FillColor.IsZero())
|
||||
testutil.AssertFalse(t, svgStroke.FontColor.IsZero())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue