github.com/cloudfoundry-attic/ltc@v0.0.0-20151123212628-098adc7919fc/terminal/colors/colorize_test.go (about) 1 package colors_test 2 3 import ( 4 "os" 5 6 . "github.com/onsi/ginkgo" 7 . "github.com/onsi/gomega" 8 9 "github.com/cloudfoundry-incubator/ltc/terminal/colors" 10 ) 11 12 var _ = Describe("Colorize", func() { 13 Context("when $TERM is set", func() { 14 var previousTerm string 15 16 BeforeEach(func() { 17 previousTerm = os.Getenv("TERM") 18 Expect(os.Setenv("TERM", "xterm")).To(Succeed()) 19 }) 20 21 AfterEach(func() { 22 Expect(os.Setenv("TERM", previousTerm)).To(Succeed()) 23 }) 24 25 It("colors the text with printf-style syntax", func() { 26 Expect(colors.Colorize("\x1b[98m", "%dxyz%s", 23, "happy")).To(Equal("\x1b[98m23xyzhappy\x1b[0m")) 27 }) 28 29 It("colors the text without printf-style syntax", func() { 30 Expect(colors.Colorize("\x1b[98m", "happy")).To(Equal("\x1b[98mhappy\x1b[0m")) 31 }) 32 }) 33 34 Context("when $TERM is not set", func() { 35 var previousTerm string 36 37 BeforeEach(func() { 38 previousTerm = os.Getenv("TERM") 39 Expect(os.Unsetenv("TERM")).To(Succeed()) 40 }) 41 42 AfterEach(func() { 43 Expect(os.Setenv("TERM", previousTerm)).To(Succeed()) 44 }) 45 46 It("colors the text with printf-style syntax", func() { 47 Expect(colors.Colorize("\x1b[98m", "%dxyz%s", 23, "happy")).To(Equal("23xyzhappy")) 48 }) 49 50 It("colors the text without printf-style syntax", func() { 51 Expect(colors.Colorize("\x1b[98m", "happy")).To(Equal("happy")) 52 }) 53 }) 54 })