|
@@ -2,7 +2,9 @@ package door
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
+ "strings"
|
|
|
"testing"
|
|
|
+ "unicode"
|
|
|
)
|
|
|
|
|
|
func TestLine(t *testing.T) {
|
|
@@ -18,7 +20,7 @@ func TestLine(t *testing.T) {
|
|
|
t.Error("Line: No updater, should return false")
|
|
|
}
|
|
|
|
|
|
- line.DefaultColor = Color(0)
|
|
|
+ line.DefaultColor = Color([]int{0})
|
|
|
line.Width = 8
|
|
|
output = line.Output()
|
|
|
expect = "\x1b[0mTest Me "
|
|
@@ -111,3 +113,69 @@ func TestLineCP437(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// Benchmarks / profiling
|
|
|
+
|
|
|
+func BenchmarkLine(b *testing.B) {
|
|
|
+
|
|
|
+ var render = func(text string) string {
|
|
|
+ var output strings.Builder
|
|
|
+ var last *string
|
|
|
+ // var r Render = Render{Line: text}
|
|
|
+
|
|
|
+ var Up string = ColorText("BLUE")
|
|
|
+ var Down string = ColorText("BOLD BLUE")
|
|
|
+ var Num string = ColorText("BRI GREEN")
|
|
|
+ var Sym string = ColorText("CYAN")
|
|
|
+
|
|
|
+ for _, letter := range text {
|
|
|
+ if unicode.IsUpper(letter) {
|
|
|
+ if last != &Up {
|
|
|
+ output.WriteString(Up)
|
|
|
+ last = &Up
|
|
|
+ }
|
|
|
+ // r.Append(Up, 1)
|
|
|
+ } else if unicode.IsLower(letter) {
|
|
|
+ if last != &Down {
|
|
|
+ output.WriteString(Down)
|
|
|
+ last = &Down
|
|
|
+ }
|
|
|
+ // r.Append(Down, 1)
|
|
|
+ } else if unicode.IsDigit(letter) {
|
|
|
+ if last != &Num {
|
|
|
+ output.WriteString(Num)
|
|
|
+ last = &Num
|
|
|
+ }
|
|
|
+ // r.Append(Num, 1)
|
|
|
+ } else {
|
|
|
+ if last != &Sym {
|
|
|
+ output.WriteString(Sym)
|
|
|
+ last = &Sym
|
|
|
+ }
|
|
|
+ //r.Append(Sym, 1)
|
|
|
+ }
|
|
|
+ output.WriteRune(letter)
|
|
|
+ // output.WriteString(string(letter))
|
|
|
+ }
|
|
|
+ return output.String()
|
|
|
+ // return r.Result
|
|
|
+ }
|
|
|
+
|
|
|
+ for i := 0; i < b.N; i++ {
|
|
|
+ var up = 0
|
|
|
+ var updater = func() string {
|
|
|
+ up++
|
|
|
+ return fmt.Sprintf("The Value: %d", up)
|
|
|
+ }
|
|
|
+
|
|
|
+ var line Line = Line{Text: updater(),
|
|
|
+ UpdateF: updater,
|
|
|
+ RenderF: render,
|
|
|
+ Width: 18}
|
|
|
+ line.Output()
|
|
|
+ for l := 0; l < 10; l++ {
|
|
|
+ line.Update()
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|