|
1 | 1 | package pythonconfig
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "strings" |
| 4 | + "reflect" |
5 | 5 | "testing"
|
6 | 6 |
|
7 | 7 | "github.com/bazelbuild/rules_python/gazelle/pythonconfig"
|
8 | 8 | )
|
9 | 9 |
|
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"}, |
16 | 19 | }
|
17 |
| -} |
18 |
| - |
19 |
| -func TestDistributionStripsUnallowedCharacters(t *testing.T) { |
20 |
| - distname := "some-dist.with.bad-chars" |
21 |
| - sanitized := pythonconfig.SanitizeDistribution(distname) |
22 | 20 |
|
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 | + }) |
25 | 28 | }
|
26 | 29 | }
|
0 commit comments