-
Notifications
You must be signed in to change notification settings - Fork 28
/
decoder_test.go
58 lines (49 loc) · 1.13 KB
/
decoder_test.go
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
package dbf
import (
"bytes"
"testing"
)
func TestUTF8Decoder_Decode(t *testing.T) {
dec := new(UTF8Decoder)
in := []byte("Tésting ㇹ Д")
b, err := dec.Decode(in)
if err != nil {
t.Fatalf("error in decode: %s", err)
}
if bytes.Equal(in, b) == false {
t.Errorf("Want %s, have %s", string(in), string(b))
}
}
func TestWin1250Decoder_Decode(t *testing.T) {
dec := new(Win1250Decoder)
in := []byte{0xC4, 0xF5}
b, err := dec.Decode(in)
if err != nil {
t.Fatalf("error in decode: %s", err)
}
want := "Äő"
if string(b) != want {
t.Errorf("Want %s, have %s", want, string(b))
}
}
func TestUTF8UTF8Validator_Decode(t *testing.T) {
dec := new(UTF8Validator)
// Test valid UTF-8 data
in := []byte("Tésting ㇹ Д")
b, err := dec.Decode(in)
if err != nil {
t.Fatalf("error in decode: %s", err)
}
if bytes.Equal(in, b) == false {
t.Errorf("Want %s, have %s", string(in), string(b))
}
// Test invalid UTF-8
in = []byte{0xff}
_, err = dec.Decode(in)
if err == nil {
t.Fatalf("wanted an error in Decode, but have no error")
}
if err != ErrInvalidUTF8 {
t.Fatalf("wanted error %s, have %s", ErrInvalidUTF8, err)
}
}