| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
package encoding |
| 15 |
|
| 16 |
import ( |
| 17 |
"testing" |
| 18 |
|
| 19 |
"github.com/gdamore/tcell/v3" |
| 20 |
) |
| 21 |
|
| 22 |
func TestGBK(t *testing.T) { |
| 23 |
enc := tcell.GetEncoding("GBK") |
| 24 |
if enc == nil { |
| 25 |
t.Fatal("NULL encoding for GBK") |
| 26 |
} |
| 27 |
glyph, _ := enc.NewDecoder().Bytes([]byte{0x82, 0x74}) |
| 28 |
if string(glyph) != "倀" { |
| 29 |
t.Errorf("failed to match: %s != 倀", string(glyph)) |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
func TestAscii(t *testing.T) { |
| 34 |
encodings := []string{ |
| 35 |
"ASCII", |
| 36 |
"ISO-8859-1", |
| 37 |
"KOI8-R", |
| 38 |
"KOI8-U", |
| 39 |
"SJIS", |
| 40 |
"Big5", |
| 41 |
"GB2312", |
| 42 |
"GB18030", |
| 43 |
"EUC-JP", |
| 44 |
"EUCKR", |
| 45 |
} |
| 46 |
|
| 47 |
for _, name := range encodings { |
| 48 |
t.Run(name, func(t *testing.T) { |
| 49 |
enc := tcell.GetEncoding(name) |
| 50 |
if enc == nil { |
| 51 |
t.Errorf("Failed getting encoding for %s", name) |
| 52 |
return |
| 53 |
} |
| 54 |
encoder := enc.NewEncoder() |
| 55 |
decoder := enc.NewDecoder() |
| 56 |
|
| 57 |
for i := byte(0); i < 126; i++ { |
| 58 |
s := string([]byte{i}) |
| 59 |
if x, err := encoder.String(s); err != nil || x != s { |
| 60 |
t.Errorf("failed encoding for character: %d, err %v expect %s got %s", i, err, s, x) |
| 61 |
} |
| 62 |
if x, err := decoder.String(s); err != nil || x != s { |
| 63 |
t.Errorf("failed decoding for character: %d, err %v expect %s got %s", i, err, s, x) |
| 64 |
} |
| 65 |
} |
| 66 |
}) |
| 67 |
} |
| 68 |
} |