Skip to content

Commit 46355c0

Browse files
committed
Refactor tests.
Prefer table driven tests to individual test cases.
1 parent d120522 commit 46355c0

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed
Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
package pythonconfig
22

33
import (
4-
"strings"
4+
"reflect"
55
"testing"
66

77
"github.com/bazelbuild/rules_python/gazelle/pythonconfig"
88
)
99

10-
func TestDistributionSanitizingUpperCase(t *testing.T) {
11-
distname := "DistWithUpperCase"
12-
sanitized := pythonconfig.SanitizeDistribution(distname)
13-
14-
if sanitized != strings.ToLower(distname) {
15-
t.Fatalf("Expected sanitized distribution name not to contain any upper case characters, got %s", sanitized)
10+
func TestDistributionSanitizing(t *testing.T) {
11+
tests := map[string]struct {
12+
input string
13+
want string
14+
}{
15+
"upper case": {input: "DistWithUpperCase", want: "distwithuppercase"},
16+
"dashes": {input: "dist-with-dashes", want: "dist_with_dashes"},
17+
"dots": {input: "dist.with.dots", want: "dist_with_dots"},
18+
"mixed": {input: "To-be.sanitized", want: "to_be_sanitized"},
1619
}
17-
}
18-
19-
func TestDistributionStripsUnallowedCharacters(t *testing.T) {
20-
distname := "some-dist.with.bad-chars"
21-
sanitized := pythonconfig.SanitizeDistribution(distname)
2220

23-
if strings.Contains(sanitized, "-") || strings.Contains(sanitized, "."){
24-
t.Fatalf("Expected sanitized distribution name not to contain any unallowed charecters ('-', '.'), got %s", sanitized)
21+
for name, tc := range tests {
22+
t.Run(name, func(t *testing.T) {
23+
got := pythonconfig.SanitizeDistribution(tc.input)
24+
if !reflect.DeepEqual(tc.want, got) {
25+
t.Fatalf("expected %#v, got %#v", tc.want, got)
26+
}
27+
})
2528
}
2629
}

0 commit comments

Comments
 (0)