mirror of
https://github.com/gizak/termui.git
synced 2025-04-24 13:48:50 +08:00
clean up and new broken test but with good indexes to hit
This commit is contained in:
parent
f9eac67f00
commit
ea81b84555
@ -79,14 +79,14 @@ func lookRightForEndStyle(s string) int {
|
||||
return strings.Index(s, ")")
|
||||
}
|
||||
|
||||
type StyleStringPosition struct {
|
||||
Start int
|
||||
End int
|
||||
IsStyle bool
|
||||
type StyleBlock struct {
|
||||
Start int
|
||||
End int
|
||||
}
|
||||
|
||||
func BreakByStyles(s string) []string {
|
||||
return []string{}
|
||||
func FindStyleBlocks(s string) []StyleBlock {
|
||||
items := []StyleBlock{}
|
||||
return items
|
||||
}
|
||||
|
||||
func FindStylePositions(s string) []int {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package termui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@ -22,22 +21,20 @@ func TestFindStylePositions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBreakByStylesComplex(t *testing.T) {
|
||||
items := BreakByStyles("test [blue](fg:blue,mod:bold) and [red](fg:red) and maybe even [foo](bg:red)!")
|
||||
if len(items) != 10 {
|
||||
func TestFindStyleBlocks(t *testing.T) {
|
||||
items := FindStyleBlocks("test [blue](fg:blue,mod:bold) and [red](fg:red) and maybe even [foo](bg:red)!")
|
||||
if len(items) != 3 {
|
||||
t.Fatal("wrong length", len(items))
|
||||
}
|
||||
text := strings.Join(items, " ")
|
||||
if text != "test blue fg:blue,bg:white,mod:bold and red fg:red and maybe even foo bg:red !" {
|
||||
t.Fatal("wrong text", text)
|
||||
if items[0].Start != 5 && items[0].End != 28 {
|
||||
t.Fatal("wrong index", items[0])
|
||||
}
|
||||
if items[1].Start != 34 && items[1].End != 46 {
|
||||
t.Fatal("wrong index", items[1])
|
||||
}
|
||||
if items[2].Start != 63 && items[2].End != 75 {
|
||||
t.Fatal("wrong index", items[2])
|
||||
}
|
||||
}
|
||||
func TestBreakByStylesSimpler(t *testing.T) {
|
||||
items := BreakByStyles("[blue](fg:blue) [1]")
|
||||
// [blue](fg:blue) [1]
|
||||
// 012345678901234
|
||||
// 0-14, rest
|
||||
fmt.Println(items, len(items))
|
||||
}
|
||||
|
||||
func TestParseStyles(t *testing.T) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user