1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
package gocolorize
import (
"fmt"
"log"
"testing"
)
var (
DEBUG *log.Logger
WARN *log.Logger
)
func TestPaint(t *testing.T) {
var blue Colorize
//set some state
blue.SetColor(Blue)
outString := fmt.Sprintf("Testing %s", blue.Paint("paint"))
basisString := "Testing \033[0;34mpaint\033[0m"
if outString != basisString {
t.Errorf("Error: string '%s' does not match '%s'\n", outString, basisString)
} else {
fmt.Printf("Success: string: '%s' matches '%s'\n", outString, basisString)
}
}
func TestPaintString(t *testing.T) {
var red Colorize
//set some state
red.SetColor(Red)
outString := red.Paint("Returning a string")
basisString := "\033[0;31mReturning a string\033[0m"
if outString != basisString {
t.Errorf("Error: string '%s' does not match '%s'\n", outString, basisString)
} else {
fmt.Printf("Success: string: '%s' matches '%s'\n", outString, basisString)
}
}
func TestSetColorSetBgColor(t *testing.T) {
var whiteRedBg Colorize
//set color and background
whiteRedBg.SetColor(White)
whiteRedBg.SetBgColor(Red)
outString := whiteRedBg.Paint("Setting a foreground and background color!")
basisString := "\033[0;37m\033[41mSetting a foreground and background color!\033[0m"
if outString != basisString {
t.Errorf("Error: string '%s' does not match '%s'\n", outString, basisString)
} else {
fmt.Printf("Success: string: '%s' matches '%s'\n", outString, basisString)
}
}
func TestPaintMultipleInterface(t *testing.T) {
blue := Colorize{Fg: Blue}
outString := blue.Paint("Multiple types of args:", 1, 1.24)
basisString := "\033[0;34mMultiple types of args: 1 1.24\033[0m"
if outString != basisString {
t.Errorf("Error: string '%s' does not match '%s'\n", outString, basisString)
} else {
fmt.Printf("Success: string: '%s' matches '%s'\n", outString, basisString)
}
}
func TestPaintComplexType(t *testing.T) {
green := Colorize{Bg: Green}
outString := green.Paint("Complex types:",
struct {
int
string
}{})
basisString := fmt.Sprintf("\033[42mComplex types: %v\033[0m", struct {
int
string
}{})
if outString != basisString {
t.Errorf("Error: string '%s' does not match '%s'\n", outString, basisString)
} else {
fmt.Printf("Success: string: '%s' matches '%s'\n", outString, basisString)
}
}
func TestInitialize(t *testing.T) {
blackOnWhite := Colorize{Fg: Black, Bg: White}
f := blackOnWhite.Paint
outString := f("Now this is cool")
basisString := "\033[0;30m\033[47mNow this is cool\033[0m"
if outString != basisString {
t.Errorf("Error: string '%s' does not match '%s'\n", outString, basisString)
} else {
fmt.Printf("Success: string: '%s' matches '%s'\n", outString, basisString)
}
}
func TestToggle(t *testing.T) {
craziness := Colorize{Fg: Yellow, Bg: Black}
craziness.ToggleFgIntensity()
craziness.ToggleBgIntensity()
craziness.ToggleBold()
craziness.ToggleBlink()
craziness.ToggleUnderline()
craziness.ToggleInverse()
outString := craziness.Paint("craziness")
basisString := "\033[0;1;5;4;7;93m\033[100mcraziness\033[0m"
if outString != basisString {
t.Errorf("Error: string '%s' does not match '%s'\n", outString, basisString)
} else {
fmt.Printf("Success: string: '%s' matches '%s'\n", outString, basisString)
}
}
func TestNewAllToggle(t *testing.T) {
n := NewColor("yellow+bBuih:black+h")
outString := n.Paint("all toggles in 1 line!")
basisString := "\033[0;1;5;4;7;93m\033[100mall toggles in 1 line!\033[0m"
if outString != basisString {
t.Errorf("Error: string '%s' does not match '%s'\n", outString, basisString)
} else {
fmt.Printf("Success: string: '%s' matches '%s'\n", outString, basisString)
}
}
func TestPlain(t *testing.T) {
plain := Colorize{Fg: Magenta}
SetPlain(true)
outString := plain.Paint("plain", "text")
basisString := "plain text"
if outString != basisString {
t.Errorf("Error: string '%s' does not match '%s'\n", outString, basisString)
} else {
fmt.Printf("Success: string: '%s' matches '%s'\n", outString, basisString)
}
SetPlain(false)
}
|