Added tests for convenience wrapper functions
Ryan Armstrong
9 years ago
0 | 0 | package colorstring |
1 | 1 | |
2 | 2 | import ( |
3 | "os" | |
3 | 4 | "testing" |
4 | 5 | ) |
5 | 6 | |
101 | 102 | output) |
102 | 103 | } |
103 | 104 | } |
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 | } |