mirror of
https://github.com/gizak/termui.git
synced 2025-04-29 13:48:51 +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, ")")
|
return strings.Index(s, ")")
|
||||||
}
|
}
|
||||||
|
|
||||||
type StyleStringPosition struct {
|
type StyleBlock struct {
|
||||||
Start int
|
Start int
|
||||||
End int
|
End int
|
||||||
IsStyle bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BreakByStyles(s string) []string {
|
func FindStyleBlocks(s string) []StyleBlock {
|
||||||
return []string{}
|
items := []StyleBlock{}
|
||||||
|
return items
|
||||||
}
|
}
|
||||||
|
|
||||||
func FindStylePositions(s string) []int {
|
func FindStylePositions(s string) []int {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package termui
|
package termui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@ -22,22 +21,20 @@ func TestFindStylePositions(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBreakByStylesComplex(t *testing.T) {
|
func TestFindStyleBlocks(t *testing.T) {
|
||||||
items := BreakByStyles("test [blue](fg:blue,mod:bold) and [red](fg:red) and maybe even [foo](bg:red)!")
|
items := FindStyleBlocks("test [blue](fg:blue,mod:bold) and [red](fg:red) and maybe even [foo](bg:red)!")
|
||||||
if len(items) != 10 {
|
if len(items) != 3 {
|
||||||
t.Fatal("wrong length", len(items))
|
t.Fatal("wrong length", len(items))
|
||||||
}
|
}
|
||||||
text := strings.Join(items, " ")
|
if items[0].Start != 5 && items[0].End != 28 {
|
||||||
if text != "test blue fg:blue,bg:white,mod:bold and red fg:red and maybe even foo bg:red !" {
|
t.Fatal("wrong index", items[0])
|
||||||
t.Fatal("wrong text", text)
|
}
|
||||||
|
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) {
|
func TestParseStyles(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user