@@ -10,17 +10,22 @@ import (
10
10
"testing"
11
11
)
12
12
13
+ const (
14
+ iso88595TypeCode = 0x06
15
+ testDataDir = "testdata"
16
+ )
17
+
13
18
var (
14
- ISO88595_Bytes []byte = readBytesFromFile ("test_text /iso88595_test.txt" )
15
- Utf8_Bytes []byte = readBytesFromFile ("test_text /iso88595_test_utf8.txt" )
19
+ iso88595_Bytes []byte = readBytesFromFile (testDataDir + " /iso88595_test.txt" )
20
+ iso88595UTF8_Bytes []byte = readBytesFromFile (testDataDir + " /iso88595_test_utf8.txt" )
16
21
)
17
22
18
23
func TestISO88595Encoder (t * testing.T ) {
19
- want := []byte (ISO88595_Bytes )
20
- text := []byte (Utf8_Bytes )
24
+ want := []byte (iso88595_Bytes )
25
+ text := []byte (iso88595UTF8_Bytes )
21
26
s := ISO88595 (text )
22
- if s .Type () != 0x06 {
23
- t .Fatalf ("Unexpected data type; want 0x03 , have %d" , s .Type ())
27
+ if s .Type () != iso88595TypeCode {
28
+ t .Fatalf ("Unexpected data type; want %d , have %d" , iso88595TypeCode , s .Type ())
24
29
}
25
30
have := s .Encode ()
26
31
if ! bytes .Equal (want , have ) {
@@ -29,22 +34,22 @@ func TestISO88595Encoder(t *testing.T) {
29
34
}
30
35
31
36
func TestISO88595Decoder (t * testing.T ) {
32
- want := []byte (Utf8_Bytes )
33
- text := []byte (ISO88595_Bytes )
37
+ want := []byte (iso88595UTF8_Bytes )
38
+ text := []byte (iso88595_Bytes )
34
39
s := ISO88595 (text )
35
- if s .Type () != 0x06 {
36
- t .Fatalf ("Unexpected data type; want 0x03 , have %d" , s .Type ())
40
+ if s .Type () != iso88595TypeCode {
41
+ t .Fatalf ("Unexpected data type; want %d , have %d" , iso88595TypeCode , s .Type ())
37
42
}
38
43
have := s .Decode ()
39
44
if ! bytes .Equal (want , have ) {
40
45
t .Fatalf ("Unexpected text; want %q, have %q" , want , have )
41
46
}
42
47
}
43
48
44
- func readBytesFromFile (aFileName string ) []byte {
45
- dat , err := ioutil .ReadFile (aFileName )
49
+ func readBytesFromFile (filename string ) []byte {
50
+ dat , err := ioutil .ReadFile (filename )
46
51
if err != nil {
47
- return nil
52
+ panic ( "Error reading testdata file; " + filename + ", err " + err . Error ())
48
53
} else {
49
54
return dat
50
55
}
0 commit comments