github.com/cellofellow/gopkg@v0.0.0-20140722061823-eec0544a62ad/colorprint/printing_test.go (about) 1 package colorprint 2 3 import ( 4 "fmt" 5 "testing" 6 ) 7 8 // colour parsing for foreground 9 func TestForegroundRed(t *testing.T) { 10 c := colourText("r", "test") 11 v := fmt.Sprintf("%s", Red("test")) 12 13 fmt.Printf("%s vs %s\n", c, v) 14 15 if c != v { 16 t.Fail() 17 } 18 } 19 20 func TestForegroundGreen(t *testing.T) { 21 c := colourText("g", "test") 22 v := fmt.Sprintf("%s", Green("test")) 23 24 fmt.Printf("%s vs %s\n", c, v) 25 26 if c != v { 27 t.Fail() 28 } 29 } 30 31 func TestForegroundYellow(t *testing.T) { 32 c := colourText("y", "test") 33 v := fmt.Sprintf("%s", Yellow("test")) 34 35 fmt.Printf("%s vs %s\n", c, v) 36 37 if c != v { 38 t.Fail() 39 } 40 } 41 42 func TestForegroundBlue(t *testing.T) { 43 c := colourText("b", "test") 44 v := fmt.Sprintf("%s", Blue("test")) 45 46 fmt.Printf("%s vs %s\n", c, v) 47 48 if c != v { 49 t.Fail() 50 } 51 } 52 53 func TestForegroundBlack(t *testing.T) { 54 c := colourText("x", "test") 55 v := fmt.Sprintf("%s", Black("test")) 56 57 fmt.Printf("%s vs %s\n", c, v) 58 59 if c != v { 60 t.Fail() 61 } 62 } 63 64 func TestForegroundMagenta(t *testing.T) { 65 c := colourText("m", "test") 66 v := fmt.Sprintf("%s", Magenta("test")) 67 68 fmt.Printf("%s vs %s\n", c, v) 69 70 if c != v { 71 t.Fail() 72 } 73 } 74 75 func TestForegroundCyan(t *testing.T) { 76 c := colourText("c", "test") 77 v := fmt.Sprintf("%s", Cyan("test")) 78 79 fmt.Printf("%s vs %s\n", c, v) 80 81 if c != v { 82 t.Fail() 83 } 84 } 85 86 func TestForegroundWhite(t *testing.T) { 87 c := colourText("w", "test") 88 v := fmt.Sprintf("%s", White("test")) 89 90 fmt.Printf("%s vs %s\n", c, v) 91 92 if c != v { 93 t.Fail() 94 } 95 } 96 97 // colour parsing for background 98 func TestBackgroundRed(t *testing.T) { 99 c := colourText("R", "test") 100 v := fmt.Sprintf("%s", BgRed("test")) 101 102 fmt.Printf("%s vs %s\n", c, v) 103 104 if c != v { 105 t.Fail() 106 } 107 } 108 109 func TestBackgroundGreen(t *testing.T) { 110 c := colourText("G", "test") 111 v := fmt.Sprintf("%s", BgGreen("test")) 112 113 fmt.Printf("%s vs %s\n", c, v) 114 115 if c != v { 116 t.Fail() 117 } 118 } 119 120 func TestBackgroundYellow(t *testing.T) { 121 c := colourText("Y", "test") 122 v := fmt.Sprintf("%s", BgYellow("test")) 123 124 fmt.Printf("%s vs %s\n", c, v) 125 126 if c != v { 127 t.Fail() 128 } 129 } 130 131 func TestBackgroundBlue(t *testing.T) { 132 c := colourText("B", "test") 133 v := fmt.Sprintf("%s", BgBlue("test")) 134 135 fmt.Printf("%s vs %s\n", c, v) 136 137 if c != v { 138 t.Fail() 139 } 140 } 141 142 func TestBackgroundMagenta(t *testing.T) { 143 c := colourText("M", "test") 144 v := fmt.Sprintf("%s", BgMagenta("test")) 145 146 fmt.Printf("%s vs %s\n", c, v) 147 148 if c != v { 149 t.Fail() 150 } 151 } 152 153 func TestBackgroundCyan(t *testing.T) { 154 c := colourText("C", "test") 155 v := fmt.Sprintf("%s", BgCyan("test")) 156 157 fmt.Printf("%s vs %s\n", c, v) 158 159 if c != v { 160 t.Fail() 161 } 162 } 163 164 func TestBackgroundWhite(t *testing.T) { 165 c := colourText("W", "test") 166 v := fmt.Sprintf("%s", BgWhite("test")) 167 168 fmt.Printf("%s vs %s\n", c, v) 169 170 if c != v { 171 t.Fail() 172 } 173 } 174 175 // some multiple parsings 176 func TestBoldMagenta(t *testing.T) { 177 c := colourText("+m", "test") 178 v := fmt.Sprintf("%s", Bold(Magenta("test"))) 179 180 fmt.Printf("%s vs %s\n", c, v) 181 } 182 183 func TestUnderlinedRed(t *testing.T) { 184 c := colourText("_r", "test") 185 v := fmt.Sprintf("%s", Underline(Red("test"))) 186 187 fmt.Printf("%s vs %s\n", c, v) 188 } 189 190 func TestGreenOnYellow(t *testing.T) { 191 c := colourText("gY", "test") 192 v := fmt.Sprintf("%s", Green(BgYellow("test"))) 193 194 fmt.Printf("%s vs %s\n", c, v) 195 } 196 197 func TestConcealed(t *testing.T) { 198 c := colourText("?", "test") 199 v := fmt.Sprintf("%s", Concealed("test")) 200 201 fmt.Printf("%s vs %s\n", c, v) 202 if c != v { 203 t.Fail() 204 } 205 } 206 207 func TestReverse(t *testing.T) { 208 c := colourText("~", "test") 209 v := fmt.Sprintf("%s", Reverse("test")) 210 211 fmt.Printf("%s vs %s\n", c, v) 212 if c != v { 213 t.Fail() 214 } 215 } 216 217 // printing 218 func TestPrintf(t *testing.T) { 219 Printf("*r", "%s\n", "printf italic red") 220 } 221 222 func TestPrint(t *testing.T) { 223 Print("+y", "print bold yellow") 224 } 225 226 func TestPrintln(t *testing.T) { 227 Print("g", "println green") 228 }