| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
package encoding |
| 16 |
|
| 17 |
import ( |
| 18 |
"errors" |
| 19 |
"testing" |
| 20 |
|
| 21 |
"golang.org/x/text/transform" |
| 22 |
) |
| 23 |
|
| 24 |
func TestUTF8(t *testing.T) { |
| 25 |
t.Logf("ASCII UTF8 identity transforms") |
| 26 |
for i := 0; i < 128; i++ { |
| 27 |
verifyMap(t, UTF8, byte(i), rune(i)) |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
func TestDstShortUTF8Decoder(t *testing.T) { |
| 32 |
decoder := ISO8859_1.NewDecoder() |
| 33 |
|
| 34 |
out := make([]byte, 1) |
| 35 |
nat := []byte{0xC0} |
| 36 |
|
| 37 |
_, _, err := decoder.Transform(out, nat, true) |
| 38 |
if err == nil { |
| 39 |
t.Errorf("Passed but should not have") |
| 40 |
} else if !errors.Is(err, transform.ErrShortDst) { |
| 41 |
t.Errorf("Wrong error return: %v", err) |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
func TestDstShortUTF8Encoder(t *testing.T) { |
| 46 |
|
| 47 |
encoder := UTF8.NewEncoder() |
| 48 |
nat := []byte("À") |
| 49 |
out := make([]byte, 1) |
| 50 |
_, _, err := encoder.Transform(out, nat, true) |
| 51 |
if err == nil { |
| 52 |
t.Errorf("Passed but should not have") |
| 53 |
} else if !errors.Is(err, transform.ErrShortDst) { |
| 54 |
t.Errorf("Wrong error return: %v", err) |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
func TestSrcShortUTF8(t *testing.T) { |
| 59 |
encoder := ISO8859_1.NewEncoder() |
| 60 |
|
| 61 |
out := make([]byte, 2) |
| 62 |
nat := []byte("À") |
| 63 |
nat = nat[0:1] |
| 64 |
|
| 65 |
_, _, err := encoder.Transform(out, nat, true) |
| 66 |
if err == nil { |
| 67 |
t.Errorf("Passed but should not have: %v", nat) |
| 68 |
} else if !errors.Is(err, transform.ErrShortSrc) { |
| 69 |
t.Errorf("Wrong error return: %v %v", nat, err) |
| 70 |
} |
| 71 |
} |