Added temporary (pseudo)Test functions TestSprintf() and TestPrintf()

This commit is contained in:
Celestino Amoroso 2024-02-25 08:32:27 +01:00
parent 01ec36c7b6
commit 55821af498
2 changed files with 42 additions and 25 deletions

36
tty.go
View File

@ -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 {

View File

@ -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()
}
}