forked from wcharczuk/go-chart
-
Notifications
You must be signed in to change notification settings - Fork 1
/
text_test.go
60 lines (46 loc) · 1.7 KB
/
text_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package chart
import (
"testing"
"github.com/wcharczuk/go-chart/v2/testutil"
)
func TestTextWrapWord(t *testing.T) {
// replaced new assertions helper
r, err := PNG(1024, 1024)
testutil.AssertNil(t, err)
f, err := GetDefaultFont()
testutil.AssertNil(t, err)
basicTextStyle := Style{Font: f, FontSize: 24}
output := Text.WrapFitWord(r, "this is a test string", 100, basicTextStyle)
testutil.AssertNotEmpty(t, output)
testutil.AssertLen(t, output, 3)
for _, line := range output {
basicTextStyle.WriteToRenderer(r)
lineBox := r.MeasureText(line)
testutil.AssertTrue(t, lineBox.Width() < 100, line+": "+lineBox.String())
}
testutil.AssertEqual(t, "this is", output[0])
testutil.AssertEqual(t, "a test", output[1])
testutil.AssertEqual(t, "string", output[2])
output = Text.WrapFitWord(r, "foo", 100, basicTextStyle)
testutil.AssertLen(t, output, 1)
testutil.AssertEqual(t, "foo", output[0])
// test that it handles newlines.
output = Text.WrapFitWord(r, "this\nis\na\ntest\nstring", 100, basicTextStyle)
testutil.AssertLen(t, output, 5)
// test that it handles newlines and long lines.
output = Text.WrapFitWord(r, "this\nis\na\ntest\nstring that is very long", 100, basicTextStyle)
testutil.AssertLen(t, output, 8)
}
func TestTextWrapRune(t *testing.T) {
// replaced new assertions helper
r, err := PNG(1024, 1024)
testutil.AssertNil(t, err)
f, err := GetDefaultFont()
testutil.AssertNil(t, err)
basicTextStyle := Style{Font: f, FontSize: 24}
output := Text.WrapFitRune(r, "this is a test string", 150, basicTextStyle)
testutil.AssertNotEmpty(t, output)
testutil.AssertLen(t, output, 2)
testutil.AssertEqual(t, "this is a t", output[0])
testutil.AssertEqual(t, "est string", output[1])
}