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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
diff --git a/colorsbg_test.go b/colorsbg_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..df910c4dc8857696f46a09f488f40f9e277e64c8
--- /dev/null
+++ b/colorsbg_test.go
@@ -0,0 +1,48 @@
+package ansi
+
+import (
+ "fmt"
+ "testing"
+)
+
+func TestSetBG(t *testing.T) {
+ type testContainer struct {
+ f func(...interface{}) string
+ v string
+ }
+
+ BGColors := map[string]testContainer{
+ "black": {f: BlackBG, v: blackbg},
+ "red": {f: RedBG, v: redbg},
+ "green": {f: GreenBG, v: greenbg},
+ "yellow": {f: YellowBG, v: yellowbg},
+ "blue": {f: BlueBG, v: bluebg},
+ "magenta": {f: MagentaBG, v: magentabg},
+ "cyan": {f: CyanBG, v: cyanbg},
+ "white": {f: WhiteBG, v: whitebg},
+ "256": {f: func(v ...interface{}) string {
+ return Color256BG(42, v...)
+ }, v: fmt.Sprintf(bg256, 42)},
+ "true": {f: func(v ...interface{}) string {
+ return ColorTrueBG(42, 420, 69, v...)
+ }, v: fmt.Sprintf(bgtrue, 42, 420, 69)},
+ }
+
+ for name, data := range BGColors {
+ t.Run(name, func(t *testing.T) {
+ if data.f("teststring") != escape+data.v+set+"teststring"+escape+resetbg+set {
+ t.Log("did not correctly build for BG color: ", name)
+ t.Fail()
+ }
+ fmt.Println(data.f(" ", name, " "))
+
+ nocolorIsSet = true
+ t.Cleanup(func() { nocolorIsSet = false })
+
+ if data.f("teststring") != "teststring" {
+ t.Log("did not honor NO_COLOR for BG color: ", name)
+ t.Fail()
+ }
+ })
+ }
+}
diff --git a/colorsfg_test.go b/colorsfg_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..ab064f91ca84f85cf3741719e76b88911aea371a
--- /dev/null
+++ b/colorsfg_test.go
@@ -0,0 +1,48 @@
+package ansi
+
+import (
+ "fmt"
+ "testing"
+)
+
+func TestSetColor(t *testing.T) {
+ type testContainer struct {
+ f func(...interface{}) string
+ v string
+ }
+
+ BGColors := map[string]testContainer{
+ "black": {f: Black, v: blackfg},
+ "red": {f: Red, v: redfg},
+ "green": {f: Green, v: greenfg},
+ "yellow": {f: Yellow, v: yellowfg},
+ "blue": {f: Blue, v: bluefg},
+ "magenta": {f: Magenta, v: magentafg},
+ "cyan": {f: Cyan, v: cyanfg},
+ "white": {f: White, v: whitefg},
+ "256": {f: func(v ...interface{}) string {
+ return Color256(42, v...)
+ }, v: fmt.Sprintf(fg256, 42)},
+ "true": {f: func(v ...interface{}) string {
+ return ColorTrue(42, 420, 69, v...)
+ }, v: fmt.Sprintf(fgtrue, 42, 420, 69)},
+ }
+
+ for name, data := range BGColors {
+ t.Run(name, func(t *testing.T) {
+ if data.f("teststring") != escape+data.v+set+"teststring"+escape+resetfg+set {
+ t.Log("did not correctly build for FG color: ", name)
+ t.Fail()
+ }
+ fmt.Println(data.f(" ", name, " "))
+
+ nocolorIsSet = true
+ t.Cleanup(func() { nocolorIsSet = false })
+
+ if data.f("teststring") != "teststring" {
+ t.Log("did not honor NO_COLOR for FG color: ", name)
+ t.Fail()
+ }
+ })
+ }
+}
|