Skip to content

Commit 217aaea

Browse files
committed
iteration_test: Accept suffixes in addition to prefixes
An upcoming commit will soon add a test file for which the suffix is important, in addition to the prefix. The middle of the file will contain long text that is not desirable to test. Thus, testing suffixes is helpful. Note that all current tests have no suffixes, so all cases should pass.
1 parent a5046fb commit 217aaea

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

api/iteration_test.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,27 @@ func TestNewIteration(t *testing.T) {
3636
t.Fatalf("Expected solution to have 5 files, had %d", len(iter.Solution))
3737
}
3838

39-
expected := map[string]string{
40-
"one.py": "# one",
41-
"two.py": "# two",
42-
filepath.Join("lib", "three.py"): "# three",
43-
"utf16le.py": "# utf16le",
44-
"utf16be.py": "# utf16be",
39+
expected := map[string]struct {
40+
prefix string
41+
suffix string
42+
}{
43+
"one.py": {prefix: "# one"},
44+
"two.py": {prefix: "# two"},
45+
filepath.Join("lib", "three.py"): {prefix: "# three"},
46+
"utf16le.py": {prefix: "# utf16le"},
47+
"utf16be.py": {prefix: "# utf16be"},
4548
}
4649

4750
for filename, code := range expected {
4851
if !utf8.ValidString(iter.Solution[filename]) {
4952
t.Errorf("Iteration content is not valid UTF-8 data: %s", iter.Solution[filename])
5053
}
5154

52-
if !strings.HasPrefix(iter.Solution[filename], code) {
53-
t.Errorf("Expected %s to contain `%s', had `%s'", filename, code, iter.Solution[filename])
55+
if !strings.HasPrefix(iter.Solution[filename], code.prefix) {
56+
t.Errorf("Expected %s to start with `%s', had `%s'", filename, code.prefix, iter.Solution[filename])
57+
}
58+
if !strings.HasSuffix(iter.Solution[filename], code.suffix) {
59+
t.Errorf("Expected %s to end with `%s', had `%s'", filename, code.suffix, iter.Solution[filename])
5460
}
5561
}
5662
}

0 commit comments

Comments
 (0)