-
Notifications
You must be signed in to change notification settings - Fork 13
/
builder_test.go
49 lines (36 loc) · 1012 Bytes
/
builder_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
package marker
import (
"fmt"
"testing"
"github.com/fatih/color"
"github.com/stretchr/testify/assert"
)
func Test_Builder(t *testing.T) {
blueFg := color.New(color.FgBlue)
blueFg.EnableColor()
blue := blueFg.SprintFunc()
redFg := color.New(color.FgRed)
redFg.EnableColor()
red := redFg.SprintFunc()
b := MarkBuilder{}
actualString := b.SetString("Skydome is a data company.").
Mark(MatchAll("Skydome"), blueFg).
MarkMany(redFg, MatchAll("data"), MatchAll("company")).
Build()
expectedString := fmt.Sprintf("%s is a %s %s.", blue("Skydome"), red("data"), red("company"))
assert.Equal(t, expectedString, actualString)
}
func Benchmark_Builder(b *testing.B) {
blueFg := color.New(color.FgBlue)
blueFg.EnableColor()
redFg := color.New(color.FgRed)
redFg.EnableColor()
b.ReportAllocs()
builder := MarkBuilder{}
skydomeMatcher := MatchAll("Skydome")
for i := 0; i < b.N; i++ {
builder.SetString("Skydome is a data company.").
Mark(skydomeMatcher, blueFg).
Build()
}
}