| 205 | } |
| 206 | |
| 207 | func TestMuted(t *testing.T) { |
| 208 | reset := "\x1b[0m" |
| 209 | gray4bit := "\x1b[0;90m" |
| 210 | gray8bit := "\x1b[38;5;242m" |
| 211 | brightBlack4bit := "\x1b[0;90m" |
| 212 | dimBlack4bit := "\x1b[0;2;37m" |
| 213 | |
| 214 | tests := []struct { |
| 215 | name string |
| 216 | cs *ColorScheme |
| 217 | input string |
| 218 | expected string |
| 219 | }{ |
| 220 | { |
| 221 | name: "when color is disabled but accessible colors are disabled, text is not stylized", |
| 222 | cs: &ColorScheme{}, |
| 223 | input: "this should not be stylized", |
| 224 | expected: "this should not be stylized", |
| 225 | }, |
| 226 | { |
| 227 | name: "when 4-bit color is enabled but accessible colors are disabled, legacy 4-bit gray color is used", |
| 228 | cs: &ColorScheme{ |
| 229 | Enabled: true, |
| 230 | }, |
| 231 | input: "this should be 4-bit gray", |
| 232 | expected: fmt.Sprintf("%sthis should be 4-bit gray%s", gray4bit, reset), |
| 233 | }, |
| 234 | { |
| 235 | name: "when 8-bit color is enabled but accessible colors are disabled, legacy 8-bit gray color is used", |
| 236 | cs: &ColorScheme{ |
| 237 | Enabled: true, |
| 238 | EightBitColor: true, |
| 239 | }, |
| 240 | input: "this should be 8-bit gray", |
| 241 | expected: fmt.Sprintf("%sthis should be 8-bit gray%s", gray8bit, reset), |
| 242 | }, |
| 243 | { |
| 244 | name: "when 24-bit color is enabled but accessible colors are disabled, legacy 8-bit gray color is used", |
| 245 | cs: &ColorScheme{ |
| 246 | Enabled: true, |
| 247 | EightBitColor: true, |
| 248 | TrueColor: true, |
| 249 | }, |
| 250 | input: "this should be 8-bit gray", |
| 251 | expected: fmt.Sprintf("%sthis should be 8-bit gray%s", gray8bit, reset), |
| 252 | }, |
| 253 | { |
| 254 | name: "when 4-bit color is enabled and theme is dark, 4-bit light color is used", |
| 255 | cs: &ColorScheme{ |
| 256 | Enabled: true, |
| 257 | EightBitColor: true, |
| 258 | TrueColor: true, |
| 259 | Accessible: true, |
| 260 | Theme: DarkTheme, |
| 261 | }, |
| 262 | input: "this should be 4-bit dim black", |
| 263 | expected: fmt.Sprintf("%sthis should be 4-bit dim black%s", dimBlack4bit, reset), |
| 264 | }, |