1package markdown 2 3import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7) 8 9func Test_Render(t *testing.T) { 10 type input struct { 11 text string 12 style string 13 } 14 type output struct { 15 wantsErr bool 16 } 17 tests := []struct { 18 name string 19 input input 20 output output 21 }{ 22 { 23 name: "invalid glamour style", 24 input: input{ 25 text: "some text", 26 style: "invalid", 27 }, 28 output: output{ 29 wantsErr: true, 30 }, 31 }, 32 { 33 name: "valid glamour style", 34 input: input{ 35 text: "some text", 36 style: "dark", 37 }, 38 output: output{ 39 wantsErr: false, 40 }, 41 }, 42 } 43 44 for _, tt := range tests { 45 t.Run(tt.name, func(t *testing.T) { 46 _, err := Render(tt.input.text, tt.input.style) 47 if tt.output.wantsErr { 48 assert.Error(t, err) 49 return 50 } 51 assert.NoError(t, err) 52 }) 53 } 54} 55 56func Test_GetStyle(t *testing.T) { 57 type input struct { 58 glamourStyle string 59 terminalTheme string 60 } 61 type output struct { 62 style string 63 } 64 tests := []struct { 65 name string 66 input input 67 output output 68 }{ 69 { 70 name: "no glamour style and no terminal theme", 71 input: input{ 72 glamourStyle: "", 73 terminalTheme: "none", 74 }, 75 output: output{ 76 style: "notty", 77 }, 78 }, 79 { 80 name: "auto glamour style and no terminal theme", 81 input: input{ 82 glamourStyle: "auto", 83 terminalTheme: "none", 84 }, 85 output: output{ 86 style: "notty", 87 }, 88 }, 89 { 90 name: "user glamour style and no terminal theme", 91 input: input{ 92 glamourStyle: "somestyle", 93 terminalTheme: "none", 94 }, 95 output: output{ 96 style: "somestyle", 97 }, 98 }, 99 { 100 name: "no glamour style and light terminal theme", 101 input: input{ 102 glamourStyle: "", 103 terminalTheme: "light", 104 }, 105 output: output{ 106 style: "light", 107 }, 108 }, 109 { 110 name: "no glamour style and dark terminal theme", 111 input: input{ 112 glamourStyle: "", 113 terminalTheme: "dark", 114 }, 115 output: output{ 116 style: "dark", 117 }, 118 }, 119 { 120 name: "no glamour style and unknown terminal theme", 121 input: input{ 122 glamourStyle: "", 123 terminalTheme: "unknown", 124 }, 125 output: output{ 126 style: "notty", 127 }, 128 }, 129 } 130 131 for _, tt := range tests { 132 fromEnv = func() string { 133 return tt.input.glamourStyle 134 } 135 136 t.Run(tt.name, func(t *testing.T) { 137 style := GetStyle(tt.input.terminalTheme) 138 assert.Equal(t, tt.output.style, style) 139 }) 140 } 141} 142