From 55821af49884a192dd850869636ba3acd09222da Mon Sep 17 00:00:00 2001 From: Celestino Amoroso Date: Sun, 25 Feb 2024 08:32:27 +0100 Subject: [PATCH] Added temporary (pseudo)Test functions TestSprintf() and TestPrintf() --- tty.go | 36 ++++++++++++++++++------------------ tty_test.go | 31 ++++++++++++++++++++++++------- 2 files changed, 42 insertions(+), 25 deletions(-) diff --git a/tty.go b/tty.go index 69ae3ca..23d9750 100644 --- a/tty.go +++ b/tty.go @@ -9,6 +9,24 @@ import ( "strings" ) +type caseMode uint8 + +const ( + normal = caseMode(iota) + upper + lower + title + firstOnly +) + +type alignMode uint8 + +const ( + noAlign = alignMode(iota) + alignLeft + alignRight +) + type ctxFmt struct { isTTY bool ansiLen int @@ -114,24 +132,6 @@ func (ctx *ctxFmt) putAnsiReset(sb *strings.Builder) { } } -type caseMode uint8 - -const ( - normal = caseMode(iota) - upper - lower - title - firstOnly -) - -type alignMode uint8 - -const ( - noAlign = alignMode(iota) - alignLeft - alignRight -) - func (ctx *ctxFmt) putText(sb *strings.Builder, text string, start int, mode caseMode, align alignMode, fieldSize int, filler byte) (offset int) { if t := text[start+1:]; len(t) > 0 { if align == alignRight { diff --git a/tty_test.go b/tty_test.go index 2e67892..4d890f8 100644 --- a/tty_test.go +++ b/tty_test.go @@ -3,25 +3,42 @@ package text import ( "fmt" - "os" "testing" ) -func TestSprintf(t *testing.T) { - list := []string{ +func testCases() []string { + return []string{ + "#{<(.20)-Param}: #{>(06)-123}", + "ciao #{c(r)i<(12)-GIAN Carlo}. #{ub-Come} #{c(G)b-Stai}?", + "ciao #{c(r)i>(12)-GIAN Carlo}. #{ub-Come} #{c(G)b-Stai}?", "ciao #{c(red);i}Mario#. #{u;b}Come# #{GREEN;b}Stai#{.}?", - "ciao #{c(red)i-Mario}. #{ub-Come} #{GREEN;b-Stai#}?", + "ciao #{c(red)i-Mario}. #{ub-Come} #{GREEN;b-Stai}?", + "ciao #{c(r)i-Mario}. #{ub-Come} #{Gr;b-Stai}?", + "ciao #{c(r)i-Mario}. #{ub-Come} #{c(G)b-Stai}?", + "ciao #{c(r)i'-gian carlo}. #{ub-Come} #{c(G)b-Stai}?", + "ciao #{c(r)i\"-gian carlo}. #{ub-Come} #{c(G)b-Stai}?", + "ciao #{c(r)i,-GIAN Carlo}. #{ub-Come} #{c(G)b-Stai}?", + "ciao #{c(r)i^-GIAN Carlo}. #{ub-Come} #{c(G)b-Stai}?", } - //s := Sprintf("ciao #{fg(139);i}Mario#. #{u;b}Come# #{GREEN;b}%s#{.}?", "Stai") + +} + +func TestSprintf(t *testing.T) { + list := testCases() fmt.Println("--- Sprintf() ---") for i, s := range list { x := Sprintf(s) fmt.Printf("--- Test nr %d: %q\n", i+1, s) fmt.Println(x) } - fmt.Println("\n--- Sprintf() ---") +} + +func TestPrintf(t *testing.T) { + list := testCases() + fmt.Println("\n--- Printf() ---") for i, s := range list { fmt.Printf("--- Test nr %d: %q\n", i+1, s) - Fprintf(os.Stdout, s) + Printf(s) + fmt.Println() } }