mirror of
https://github.com/mjl-/mox.git
synced 2024-12-27 08:53:48 +03:00
25 lines
614 B
Go
25 lines
614 B
Go
|
package moxio
|
|||
|
|
|||
|
import (
|
|||
|
"io"
|
|||
|
"strings"
|
|||
|
"testing"
|
|||
|
)
|
|||
|
|
|||
|
func TestDecodeReader(t *testing.T) {
|
|||
|
check := func(charset, input, output string) {
|
|||
|
t.Helper()
|
|||
|
buf, err := io.ReadAll(DecodeReader(charset, strings.NewReader(input)))
|
|||
|
tcheckf(t, err, "decode")
|
|||
|
if string(buf) != output {
|
|||
|
t.Fatalf("decoding %q with charset %q, got %q, expected %q", input, charset, buf, output)
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
check("", "☺", "☺") // No decoding.
|
|||
|
check("us-ascii", "☺", "☺") // No decoding.
|
|||
|
check("utf-8", "☺", "☺")
|
|||
|
check("iso-8859-1", string([]byte{0xa9}), "©")
|
|||
|
check("iso-8859-5", string([]byte{0xd0}), "а")
|
|||
|
}
|