Skip to content

Commit e03bb39

Browse files
authored
Merge pull request #352 from exercism/lowercase-segments
Fix case sensitivity on slug and track ID iteration.
2 parents 201e3d6 + a491021 commit e03bb39

3 files changed

Lines changed: 42 additions & 4 deletions

File tree

api/iteration.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ func NewIteration(dir string, filenames []string) (*Iteration, error) {
102102
// is still bad. Has the user modified their path in some way?
103103
return nil, newIterationError(msgGenericPathError, iter.Dir)
104104
}
105-
iter.TrackID = segments[1]
106-
iter.Problem = segments[2]
105+
iter.TrackID = strings.ToLower(segments[1])
106+
iter.Problem = strings.ToLower(segments[2])
107107

108108
for _, filename := range filenames {
109109
fileContents, err := readFileAsUTF8String(filename)

api/iteration_darwin_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package api
2+
3+
import (
4+
"path/filepath"
5+
"runtime"
6+
"testing"
7+
)
8+
9+
func TestNewIteration_CaseSensitive(t *testing.T) {
10+
_, path, _, _ := runtime.Caller(0)
11+
dir := filepath.Join(path, "..", "..", "fixtures", "iteration")
12+
13+
testCases := []map[string][]string{
14+
{
15+
"file": []string{filepath.Join(dir, "python", "leap", "one.py")},
16+
},
17+
{
18+
"file": []string{filepath.Join(dir, "Python", "leap", "one.py")},
19+
},
20+
{
21+
"file": []string{filepath.Join(dir, "Python", "Leap", "one.py")},
22+
},
23+
}
24+
25+
for _, testCase := range testCases {
26+
iter, err := NewIteration(dir, testCase["file"])
27+
if err != nil {
28+
t.Fatal(err)
29+
}
30+
31+
if iter.TrackID != "python" {
32+
t.Errorf("Expected language to be python, was %s", iter.TrackID)
33+
}
34+
if iter.Problem != "leap" {
35+
t.Errorf("Expected problem to be leap, was %s", iter.Problem)
36+
}
37+
}
38+
}

cmd/submit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import (
77
"os"
88
"path/filepath"
99

10-
"github.com/urfave/cli"
1110
"github.com/exercism/cli/api"
1211
"github.com/exercism/cli/config"
1312
"github.com/exercism/cli/paths"
13+
"github.com/urfave/cli"
1414
)
1515

1616
// Submit posts an iteration to the API.
@@ -89,7 +89,7 @@ func Submit(ctx *cli.Context) error {
8989

9090
iteration, err := api.NewIteration(dir, files)
9191
if err != nil {
92-
log.Fatalf("Unable to submit - %s", err)
92+
log.Fatalf("unable to submit - %s", err)
9393
}
9494
iteration.Key = c.APIKey
9595
iteration.Comment = ctx.String("comment")

0 commit comments

Comments
 (0)