/
t_colorize.clj
60 lines (45 loc) · 2.22 KB
/
t_colorize.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
(ns midje.emission.t-colorize
(:use midje.sweet
[midje.util.ecosystem :only [getenv on-windows?]])
(:require [midje.emission.colorize :as color]
[midje.config :as config]))
(tabular
(fact "wraps string in ascii color if the user so desires"
(prerequisites (color/config-choice :colorize) => ?config-choice
(getenv "MIDJE_COLORIZE") => ?env-choice)
(color/init!)
(?color-fn "string") => ?result)
?color-fn ?env-choice ?config-choice ?result
;; On windows, the config-choice defaults to false
color/fail "FALSE" false "string"
color/fail "TRUE" false "\u001b[31mstring\u001b[0m"
color/fail "reverse" false "\u001b[41mstring\u001b[0m"
color/fail nil false "string"
;; On Unixoids, the config-choice defaults to true
color/fail "FALSE" true "string"
color/fail "TRUE" true "\u001b[31mstring\u001b[0m"
color/fail "reverse" true "\u001b[41mstring\u001b[0m"
color/fail nil true "\u001b[31mstring\u001b[0m"
;; The user can set the config variable.
color/fail nil :reverse "\u001b[41mstring\u001b[0m"
;; The environment variable takes precedence
color/fail "false" :reverse "string")
(tabular
(fact "about the escape strings that apply to different choices"
(prerequisite (getenv "MIDJE_COLORIZE") => ?env-value)
(color/init!)
(?color-fn "string") => ?result)
?color-fn ?env-value ?result
color/fail "FALSE" "string"
color/fail "TRUE" "\u001b[31mstring\u001b[0m"
color/fail "reverse" "\u001b[41mstring\u001b[0m"
color/note "FALSE" "string"
color/note "TRUE" "\u001b[36mstring\u001b[0m"
color/note "reverse" "\u001b[46mstring\u001b[0m")
;; Reset to user's default colorization.
(color/init!)
(fact "access environment vars only when namespace is loaded, not on each report line"
(prerequisite (getenv "MIDJE_COLORIZE") => anything :times 0)
(color/fail "a") => anything
(color/note "b") => anything
(color/fail "c") => anything)