2017-07-05 23:10:57 +00:00
|
|
|
/*
|
|
|
|
* This file is subject to the terms and conditions defined in
|
|
|
|
* file 'LICENSE.md', which is part of this source code package.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package textencoding
|
|
|
|
|
2019-03-24 00:13:35 +00:00
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
2017-07-05 23:10:57 +00:00
|
|
|
|
|
|
|
func TestWinAnsiEncoder(t *testing.T) {
|
2019-01-01 21:17:57 +02:00
|
|
|
enc := NewWinAnsiEncoder()
|
2017-07-05 23:10:57 +00:00
|
|
|
|
2019-01-01 23:24:11 +02:00
|
|
|
r, found := enc.CharcodeToRune(32)
|
|
|
|
if !found || r != ' ' {
|
|
|
|
t.Errorf("rune != space")
|
2017-07-05 23:10:57 +00:00
|
|
|
return
|
|
|
|
}
|
2018-12-29 19:01:05 +02:00
|
|
|
code, found := enc.RuneToCharcode('þ')
|
|
|
|
if !found || code != 254 {
|
|
|
|
t.Errorf("code != 254")
|
|
|
|
return
|
|
|
|
}
|
2017-07-05 23:10:57 +00:00
|
|
|
|
2019-01-01 23:24:11 +02:00
|
|
|
glyph, found := RuneToGlyph('þ')
|
2017-07-05 23:10:57 +00:00
|
|
|
if !found || glyph != "thorn" {
|
|
|
|
t.Errorf("Glyph != thorn")
|
|
|
|
return
|
|
|
|
}
|
2019-03-24 00:13:35 +00:00
|
|
|
|
|
|
|
// Should encode hyphen to 0x2D consistently (not alternative 0xAD)
|
|
|
|
b := enc.Encode(strings.Repeat("-", 100))
|
|
|
|
if !bytes.Equal(b, bytes.Repeat([]byte{0x2D}, 100)) {
|
|
|
|
t.Fatalf("Incorrect encoding of hyphen")
|
|
|
|
}
|
|
|
|
|
|
|
|
s := enc.Decode([]byte{0xAD, 0x2D})
|
|
|
|
if s != "--" {
|
|
|
|
t.Fatalf("Incorrect decoding of hyphen")
|
|
|
|
}
|
2017-07-05 23:10:57 +00:00
|
|
|
}
|