Skip to content

Commit

Permalink
internal: fixed parsing for two consecutive formatted groups
Browse files Browse the repository at this point in the history
  • Loading branch information
i582 committed Apr 9, 2021
1 parent 5ce0a51 commit b5e8f07
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ func Parse(text string) string {
inText = true

lastIsFormatGroup = false

if s == '{' {
index--
}

continue
}
continue
Expand Down
7 changes: 7 additions & 0 deletions tests/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ func TestParse(t *testing.T) {
return cfmt.Sprintf("{{%s}}::red|underline", s)
})

cfmt.RegisterStyle("flag", func(s string) string {
return cfmt.Sprintf("{{--%s}}::green (-%c)", s, s[0])
})

flag := "help"
cfmt.Printf("{{%s}}::flag \n", flag)
cfmt.Println("{{こんにちは, correct group}}::code sdas")
cfmt.Println("{{привет, correct group}}::red|underline and {{other}}::red")
cfmt.Print("{{error group}} \n")
Expand All @@ -27,4 +33,5 @@ func TestParse(t *testing.T) {
cfmt.Printf(cfmt.Sprintf("{{background color %s}}::bg#ffff00\n", "hex color"))
cfmt.Printf("{{{hello}}}::red|underline\n")
cfmt.Printf("{{some test struct: %v}}::red|underline\n", TestStruct{"hello", 1})
cfmt.Println("{{hello}}::red{{world}}::green")
}

0 comments on commit b5e8f07

Please sign in to comment.