github.com/ipfans/trojan-go@v0.11.0/log/golog/colorful/colorful_test.go (about) 1 // The color engine for the go-log library 2 // Copyright (c) 2017 Fadhli Dzil Ikram 3 // 4 // Test file 5 6 package colorful 7 8 import ( 9 "testing" 10 11 . "github.com/smartystreets/goconvey/convey" 12 13 "github.com/ipfans/trojan-go/log/golog/buffer" 14 ) 15 16 func TestColorBuffer(t *testing.T) { 17 Convey("Given empty color buffer and test data", t, func() { 18 var cb ColorBuffer 19 var result buffer.Buffer 20 21 // Add color to the result buffer 22 result.Append(colorRed) 23 result.Append(colorGreen) 24 result.Append(colorOrange) 25 result.Append(colorBlue) 26 result.Append(colorPurple) 27 result.Append(colorCyan) 28 result.Append(colorGray) 29 result.Append(colorOff) 30 31 Convey("When appended with color", func() { 32 cb.Red() 33 cb.Green() 34 cb.Orange() 35 cb.Blue() 36 cb.Purple() 37 cb.Cyan() 38 cb.Gray() 39 cb.Off() 40 41 Convey("It should have same content with the test data", func() { 42 So(result.Bytes(), ShouldResemble, cb.Bytes()) 43 }) 44 }) 45 }) 46 } 47 48 func TestColorMixer(t *testing.T) { 49 Convey("Given mixer test result data", t, func() { 50 var ( 51 data = []byte("Hello") 52 resultRed buffer.Buffer 53 resultGreen buffer.Buffer 54 resultOrange buffer.Buffer 55 resultBlue buffer.Buffer 56 resultPurple buffer.Buffer 57 resultCyan buffer.Buffer 58 resultGray buffer.Buffer 59 ) 60 61 // Add result to buffer 62 resultRed.Append(colorRed) 63 resultRed.Append(data) 64 resultRed.Append(colorOff) 65 66 resultGreen.Append(colorGreen) 67 resultGreen.Append(data) 68 resultGreen.Append(colorOff) 69 70 resultOrange.Append(colorOrange) 71 resultOrange.Append(data) 72 resultOrange.Append(colorOff) 73 74 resultBlue.Append(colorBlue) 75 resultBlue.Append(data) 76 resultBlue.Append(colorOff) 77 78 resultPurple.Append(colorPurple) 79 resultPurple.Append(data) 80 resultPurple.Append(colorOff) 81 82 resultCyan.Append(colorCyan) 83 resultCyan.Append(data) 84 resultCyan.Append(colorOff) 85 86 resultGray.Append(colorGray) 87 resultGray.Append(data) 88 resultGray.Append(colorOff) 89 90 Convey("It should have same result when data appended with Red color", func() { 91 So(Red(data), ShouldResemble, resultRed.Bytes()) 92 }) 93 94 Convey("It should have same result when data appended with Green color", func() { 95 So(Green(data), ShouldResemble, resultGreen.Bytes()) 96 }) 97 98 Convey("It should have same result when data appended with Orange color", func() { 99 So(Orange(data), ShouldResemble, resultOrange.Bytes()) 100 }) 101 102 Convey("It should have same result when data appended with Blue color", func() { 103 So(Blue(data), ShouldResemble, resultBlue.Bytes()) 104 }) 105 106 Convey("It should have same result when data appended with Purple color", func() { 107 So(Purple(data), ShouldResemble, resultPurple.Bytes()) 108 }) 109 110 Convey("It should have same result when data appended with Cyan color", func() { 111 So(Cyan(data), ShouldResemble, resultCyan.Bytes()) 112 }) 113 114 Convey("It should have same result when data appended with Gray color", func() { 115 So(Gray(data), ShouldResemble, resultGray.Bytes()) 116 }) 117 }) 118 }