From b5e8f0705a39490e75be71a97d1ae93fa2b3ba7e Mon Sep 17 00:00:00 2001 From: i582 Date: Fri, 9 Apr 2021 14:08:09 +0300 Subject: [PATCH] internal: fixed parsing for two consecutive formatted groups --- internal/parser.go | 5 +++++ tests/parser_test.go | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/internal/parser.go b/internal/parser.go index d080aef..eae9310 100644 --- a/internal/parser.go +++ b/internal/parser.go @@ -179,6 +179,11 @@ func Parse(text string) string { inText = true lastIsFormatGroup = false + + if s == '{' { + index-- + } + continue } continue diff --git a/tests/parser_test.go b/tests/parser_test.go index 8d00995..90670f0 100644 --- a/tests/parser_test.go +++ b/tests/parser_test.go @@ -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") @@ -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") }