From ea81b84555700847898a4c549e2fbfa0b84af6c3 Mon Sep 17 00:00:00 2001 From: Andrew Arrow Date: Tue, 8 Nov 2022 09:11:41 -0800 Subject: [PATCH] clean up and new broken test but with good indexes to hit --- style_parser.go | 12 ++++++------ style_parser_test.go | 25 +++++++++++-------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/style_parser.go b/style_parser.go index 39fd81e..2854c00 100644 --- a/style_parser.go +++ b/style_parser.go @@ -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 { diff --git a/style_parser_test.go b/style_parser_test.go index d3088d2..776002c 100644 --- a/style_parser_test.go +++ b/style_parser_test.go @@ -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) {