Added temporary (pseudo)Test functions TestSprintf() and TestPrintf()
This commit is contained in:
parent
01ec36c7b6
commit
55821af498
36
tty.go
36
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 {
|
||||
|
31
tty_test.go
31
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()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user