@@ -3,7 +3,9 @@ package api
33import (
44 "path/filepath"
55 "runtime"
6+ "strings"
67 "testing"
8+ "unicode/utf8"
79)
810
911func TestNewIteration (t * testing.T ) {
@@ -14,6 +16,8 @@ func TestNewIteration(t *testing.T) {
1416 filepath .Join (dir , "python" , "leap" , "one.py" ),
1517 filepath .Join (dir , "python" , "leap" , "two.py" ),
1618 filepath .Join (dir , "python" , "leap" , "lib" , "three.py" ),
19+ filepath .Join (dir , "python" , "leap" , "utf16le.py" ),
20+ filepath .Join (dir , "python" , "leap" , "utf16be.py" ),
1721 }
1822
1923 iter , err := NewIteration (dir , files )
@@ -28,18 +32,25 @@ func TestNewIteration(t *testing.T) {
2832 t .Errorf ("Expected problem to be leap, was %s" , iter .Problem )
2933 }
3034
31- if len (iter .Solution ) != 3 {
35+ if len (iter .Solution ) != 5 {
3236 t .Fatalf ("Expected solution to have 3 files, had %d" , len (iter .Solution ))
3337 }
3438
3539 expected := map [string ]string {
36- "one.py" : "# one\n " ,
37- "two.py" : "# two\n " ,
38- "lib/three.py" : "# three\n " ,
40+ "one.py" : "# one" ,
41+ "two.py" : "# two" ,
42+ filepath .Join ("lib" , "three.py" ): "# three" ,
43+ "utf16le.py" : "# utf16le" ,
44+ "utf16be.py" : "# utf16be" ,
3945 }
46+
4047 for filename , code := range expected {
41- if iter .Solution [filename ] != code {
42- t .Errorf ("Expected %s to contain %s, had %s" , filename , code , iter .Solution [filename ])
48+ if ! utf8 .ValidString (iter .Solution [filename ]) {
49+ t .Errorf ("Iteration content is not valid UTF-8 data: %s" , iter .Solution [filename ])
50+ }
51+
52+ if ! strings .HasPrefix (iter .Solution [filename ], code ) {
53+ t .Errorf ("Expected %s to contain `%s', had `%s'" , filename , code , iter .Solution [filename ])
4354 }
4455 }
4556}
0 commit comments