github.com/technosophos/deis@v1.7.1-0.20150915173815-f9005256004b/pkg/prettyprint/colorizer_test.go (about) 1 package prettyprint 2 3 import ( 4 "fmt" 5 "strings" 6 "testing" 7 ) 8 9 func TestColorize(t *testing.T) { 10 out := Colorize("{{.Red}}Hello {{.Default}}World{{.UnderGreen}}!{{.Default}}") 11 expected := "\033[0;31mHello \033[0mWorld\033[4;32m!\033[0m" 12 if out != expected { 13 t.Errorf("Expected '%s', got '%s'", expected, out) 14 } 15 } 16 17 func TestColorizeVars(t *testing.T) { 18 vars := map[string]string{"Who": "World"} 19 tpl := "{{.C.Red}}Hello {{.C.Default}}{{.V.Who}}{{.C.UnderGreen}}!{{.C.Default}}" 20 out := ColorizeVars(tpl, vars) 21 expected := "\033[0;31mHello \033[0mWorld\033[4;32m!\033[0m" 22 if out != expected { 23 t.Errorf("Expected '%s', got '%s'", expected, out) 24 } 25 } 26 27 func TestNoColor(t *testing.T) { 28 tpl := "{{.Red}}{{.Yellow}}{{.Green}}coffee all the things!{{.Default}}" 29 expected := "coffee all the things!" 30 out := NoColor(tpl) 31 if out != expected { 32 t.Errorf("Expected `%s`, got `%s`", expected, out) 33 } 34 } 35 36 func ExampleColorize() { 37 out := Colorize("{{.Red}}Hello {{.Default}}World{{.UnderGreen}}!{{.Default}}") 38 fmt.Println(out) 39 } 40 41 func ExampleColorizeVars() { 42 vars := map[string]string{"Who": "World"} 43 tpl := "{{.C.Red}}Hello {{.C.Default}}{{.V.Who}}!" 44 out := ColorizeVars(tpl, vars) 45 fmt.Println(out) 46 } 47 48 func TestDeisIfy(t *testing.T) { 49 d := DeisIfy("Test") 50 if strings.Contains(d, "Deis1") { 51 t.Errorf("Failed to compile template") 52 } 53 if !strings.Contains(d, "Test") { 54 t.Errorf("Failed to render template") 55 } 56 } 57 58 func TestLogo(t *testing.T) { 59 l := Logo() 60 if l != Colors["Deis"] { 61 t.Errorf("Expected \n%s\n, Got\n%s\n", Colors["Deis"], Logo()) 62 } 63 } 64 65 func TestPrettyTabs(t *testing.T) { 66 test := map[string]string{ 67 "test": "testing", 68 "foo": "bar", 69 } 70 71 expected := `foo bar 72 test testing 73 ` 74 75 output := PrettyTabs(test, 1) 76 77 if output != expected { 78 t.Errorf("Expected '%s', Got '%s'", expected, output) 79 } 80 }