Codebase list golang-github-mitchellh-colorstring-upstream / c2c00be
Added tests for convenience wrapper functions Ryan Armstrong 9 years ago
1 changed file(s) with 44 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
00 package colorstring
11
22 import (
3 "os"
34 "testing"
45 )
56
101102 output)
102103 }
103104 }
105
106 func TestConvenienceWrappers(t *testing.T) {
107 var length int
108 printInput := "[bold]Print:\t\t[default][red]R[green]G[blue]B[cyan]C[magenta]M[yellow]Y\n"
109 printlnInput := "[bold]Println:\t[default][red]R[green]G[blue]B[cyan]C[magenta]M[yellow]Y"
110 printfInput := "[bold]Printf:\t\t[default][red]R[green]G[blue]B[cyan]C[magenta]M[yellow]Y\n"
111 fprintInput := "[bold]Fprint:\t\t[default][red]R[green]G[blue]B[cyan]C[magenta]M[yellow]Y\n"
112 fprintlnInput := "[bold]Fprintln:\t[default][red]R[green]G[blue]B[cyan]C[magenta]M[yellow]Y"
113 fprintfInput := "[bold]Fprintf:\t[default][red]R[green]G[blue]B[cyan]C[magenta]M[yellow]Y\n"
114
115 // colorstring.Print
116 length, _ = Print(printInput)
117 assertOutputLength(t, printInput, 58, length)
118
119 // colorstring.Println
120 length, _ = Println(printlnInput)
121 assertOutputLength(t, printlnInput, 59, length)
122
123 // colorstring.Printf
124 length, _ = Printf(printfInput)
125 assertOutputLength(t, printfInput, 59, length)
126
127 // colorstring.Fprint
128 length, _ = Fprint(os.Stdout, fprintInput)
129 assertOutputLength(t, fprintInput, 59, length)
130
131 // colorstring.Fprintln
132 length, _ = Fprintln(os.Stdout, fprintlnInput)
133 assertOutputLength(t, fprintlnInput, 60, length)
134
135 // colorstring.Fprintf
136 length, _ = Fprintf(os.Stdout, fprintfInput)
137 assertOutputLength(t, fprintfInput, 59, length)
138 }
139
140 func assertOutputLength(t *testing.T, input string, expectedLength int, actualLength int) {
141 if actualLength != expectedLength {
142 t.Errorf("Input: %#v\n\n Output length: %d\n\n Expected: %d",
143 input,
144 actualLength,
145 expectedLength)
146 }
147 }