Repository navigation
Expand file tree
/
Copy pathiteration_test.go
More file actions
94 lines (83 loc) · 2.07 KB
/
Copy pathiteration_test.go
File metadata and controls
94 lines (83 loc) · 2.07 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package api
import (
"path/filepath"
"runtime"
"strings"
"testing"
"unicode/utf8"
)
func TestNewIteration(t *testing.T) {
_, path, _, _ := runtime.Caller(0)
dir := filepath.Join(path, "..", "..", "fixtures", "iteration")
files := []string{
filepath.Join(dir, "python", "leap", "one.py"),
filepath.Join(dir, "python", "leap", "two.py"),
filepath.Join(dir, "python", "leap", "lib", "three.py"),
filepath.Join(dir, "python", "leap", "utf16le.py"),
filepath.Join(dir, "python", "leap", "utf16be.py"),
}
iter, err := NewIteration(dir, files)
if err != nil {
t.Fatal(err)
}
if iter.TrackID != "python" {
t.Errorf("Expected language to be python, was %s", iter.TrackID)
}
if iter.Problem != "leap" {
t.Errorf("Expected problem to be leap, was %s", iter.Problem)
}
if len(iter.Solution) != 5 {
t.Fatalf("Expected solution to have 3 files, had %d", len(iter.Solution))
}
expected := map[string]string{
"one.py": "# one",
"two.py": "# two",
filepath.Join("lib", "three.py"): "# three",
"utf16le.py": "# utf16le",
"utf16be.py": "# utf16be",
}
for filename, code := range expected {
if !utf8.ValidString(iter.Solution[filename]) {
t.Errorf("Iteration content is not valid UTF-8 data: %s", iter.Solution[filename])
}
if !strings.HasPrefix(iter.Solution[filename], code) {
t.Errorf("Expected %s to contain `%s', had `%s'", filename, code, iter.Solution[filename])
}
}
}
func TestIterationValidFile(t *testing.T) {
testCases := []struct {
file string
ok bool
}{
{
file: "/Users/me/exercism/ruby/bob/totally/fine/deep/path/src/bob.rb",
ok: true,
},
{
file: "/Users/me/exercism/ruby/bob/bob.rb",
ok: true,
},
{
file: "/users/me/exercism/ruby/bob/bob.rb",
ok: true,
},
{
file: "/Users/me/bob.rb",
ok: false,
},
{
file: "/tmp/bob.rb",
ok: false,
},
}
for _, tt := range testCases {
iter := &Iteration{
Dir: "/Users/me/exercism",
}
ok := iter.isValidFilepath(tt.file)
if ok && !tt.ok {
t.Errorf("Expected %s to be invalid.", tt.file)
}
}
}