Debian Codegraph @

pkg/color/util_test.go

raw symbols SCIP
1 package colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/
2
3 import (
4 "osscip-go gomod github.com/golang/go/src . os/"
5 "testingscip-go gomod github.com/golang/go/src . testing/"
6
7 "github.com/stretchr/testify/assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/"
8 "github.com/stretchr/testify/requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/"
9 )
10
11 func Test_boolPtrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Test_boolPtr().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
12 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
13 tests := []struct {
14 name string
15 input bool
16 checkPtr func(*testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#, *bool)
17 }{
18 {
19 name: "returns pointer to true",
20 input: true,
21 checkPtr: func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#, p *bool) {
22 t.Helperscip-go gomod github.com/golang/go/src . testing/common#Helper().()
23 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NotNilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NotNil().(t, p)
24 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Truescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/True().(t, *p)
25 },
26 },
27 {
28 name: "returns pointer to false",
29 input: false,
30 checkPtr: func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#, p *bool) {
31 t.Helperscip-go gomod github.com/golang/go/src . testing/common#Helper().()
32 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NotNilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NotNil().(t, p)
33 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Falsescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/False().(t, *p)
34 },
35 },
36 }
37
38 for _, tt := range tests {
39 t.Runscip-go gomod github.com/golang/go/src . testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
40 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
41
42 result := boolPtrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/boolPtr().(tt.input)
43 tt.checkPtr(t, result)
44 })
45 }
46 }
47
48 //nolint:paralleltest // This test cannot run in parallel because it manipulates environment variables.
49 func Test_noColorIsSetscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Test_noColorIsSet().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
50 tests := []struct {
51 name string
52 setEnv bool // whether to set the environment variable
53 envValue string // the value to set (only used if setEnv is true)
54 expectSet bool
55 }{
56 {
57 name: "returns false when NO_COLOR is not set",
58 setEnv: false,
59 envValue: "",
60 expectSet: false,
61 },
62 {
63 name: "returns true when NO_COLOR is set to empty string",
64 setEnv: true,
65 envValue: "",
66 expectSet: true,
67 },
68 {
69 name: "returns true when NO_COLOR is set to 0",
70 setEnv: true,
71 envValue: "0",
72 expectSet: true,
73 },
74 {
75 name: "returns true when NO_COLOR is set to false",
76 setEnv: true,
77 envValue: "false",
78 expectSet: true,
79 },
80 {
81 name: "returns true when NO_COLOR is set to any value",
82 setEnv: true,
83 envValue: "1",
84 expectSet: true,
85 },
86 }
87
88 for _, tt := range tests {
89 t.Runscip-go gomod github.com/golang/go/src . testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
90 // Save original environment before each subtest
91 originalEnv, hadOriginal := osscip-go gomod github.com/golang/go/src . os/.LookupEnvscip-go gomod github.com/golang/go/src . os/LookupEnv().("NO_COLOR")
92
93 // Set or unset environment variable
94 if tt.setEnv {
95 osscip-go gomod github.com/golang/go/src . os/.Setenvscip-go gomod github.com/golang/go/src . os/Setenv().("NO_COLOR", tt.envValue)
96 } else {
97 osscip-go gomod github.com/golang/go/src . os/.Unsetenvscip-go gomod github.com/golang/go/src . os/Unsetenv().("NO_COLOR")
98 }
99
100 // Defer cleanup to restore original state
101 defer func() {
102 if hadOriginal {
103 osscip-go gomod github.com/golang/go/src . os/.Setenvscip-go gomod github.com/golang/go/src . os/Setenv().("NO_COLOR", originalEnv)
104 } else {
105 osscip-go gomod github.com/golang/go/src . os/.Unsetenvscip-go gomod github.com/golang/go/src . os/Unsetenv().("NO_COLOR")
106 }
107 }()
108
109 result := noColorIsSetscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/noColorIsSet().()
110 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.expectSet, result)
111 })
112 }
113 }
114
115 func Test_sprintlnscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Test_sprintln().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
116 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
117
118 tests := []struct {
119 name string
120 input []any
121 expected string
122 }{
123 {
124 name: "empty input returns empty string",
125 input: []any{},
126 expected: "",
127 },
128 {
129 name: "single string removes trailing newline",
130 input: []any{"hello"},
131 expected: "hello",
132 },
133 {
134 name: "single integer",
135 input: []any{42},
136 expected: "42",
137 },
138 {
139 name: "multiple arguments",
140 input: []any{"hello", "world"},
141 expected: "hello world",
142 },
143 {
144 name: "mixed types",
145 input: []any{"count:", 123, "pi:", 3.14},
146 expected: "count: 123 pi: 3.14",
147 },
148 {
149 name: "string with spaces",
150 input: []any{"hello world"},
151 expected: "hello world",
152 },
153 {
154 name: "empty string",
155 input: []any{""},
156 expected: "",
157 },
158 }
159
160 for _, tt := range tests {
161 t.Runscip-go gomod github.com/golang/go/src . testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
162 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
163
164 result := sprintlnscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/sprintln().(tt.input...)
165 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.expected, result)
166 })
167 }
168 }