From 805f10a923eea48331bd4dd5efcbe8a6c8604868 Mon Sep 17 00:00:00 2001 From: Will Charczuk Date: Sun, 10 Jul 2016 23:21:19 -0700 Subject: [PATCH] things. --- vector_renderer_test.go | 52 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 vector_renderer_test.go diff --git a/vector_renderer_test.go b/vector_renderer_test.go new file mode 100644 index 0000000..e8f6b03 --- /dev/null +++ b/vector_renderer_test.go @@ -0,0 +1,52 @@ +package chart + +import ( + "bytes" + "strings" + "testing" + + "github.com/blendlabs/go-assert" +) + +func TestVectorRendererPath(t *testing.T) { + assert := assert.New(t) + + vr, err := SVG(100, 100) + assert.Nil(err) + + typed, isTyped := vr.(*vectorRenderer) + assert.True(isTyped) + + typed.MoveTo(0, 0) + typed.LineTo(100, 100) + typed.LineTo(0, 100) + typed.Close() + typed.FillStroke() + + buffer := bytes.NewBuffer([]byte{}) + err = typed.Save(buffer) + assert.Nil(err) + + raw := string(buffer.Bytes()) + + assert.True(strings.HasPrefix(raw, "")) +} + +func TestVectorRendererMeasureText(t *testing.T) { + assert := assert.New(t) + + f, err := GetDefaultFont() + assert.Nil(err) + + vr, err := SVG(100, 100) + assert.Nil(err) + + vr.SetDPI(DefaultDPI) + vr.SetFont(f) + vr.SetFontSize(12.0) + + w, h := vr.MeasureText("Ljp") + assert.Equal(26, w) + assert.Equal(15, h) +}