-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
auto_test.go
41 lines (39 loc) · 1.09 KB
/
auto_test.go
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
package color
import "testing"
func TestAutof(t *testing.T) {
scenarios := []struct {
InputFormat string
InputArguments []any
ExpectedOutput string
}{
{
InputFormat: "no args, no colors.",
InputArguments: nil,
ExpectedOutput: "no args, no colors.",
},
{
InputFormat: "hello, %s.",
InputArguments: []any{"world"},
ExpectedOutput: "hello, " + Red + "world" + Reset + ".",
},
{
InputFormat: "%s got %d%% in math.",
InputArguments: []any{"John Doe", 87},
ExpectedOutput: InRed("John Doe") + " got " + InGreen(87) + "% in math.",
},
{
InputFormat: "%s sent %s$%.02f to %s",
InputArguments: []any{"John", "USD", 123.4, "Jane"},
ExpectedOutput: InRed("John") + " sent " + InGreen("USD") + "$" + InYellow("123.40") + " to " + InBlue("Jane"),
},
}
for _, scenario := range scenarios {
t.Run(scenario.InputFormat, func(t *testing.T) {
output := Autof(scenario.InputFormat, scenario.InputArguments...)
if output != scenario.ExpectedOutput {
t.Errorf("expected %s, got %s", scenario.ExpectedOutput, output)
}
println(output)
})
}
}