1package message
2
3import (
4 "io"
5 "strings"
6 "testing"
7)
8
9func TestDecodeReader(t *testing.T) {
10 check := func(charset, input, output string) {
11 t.Helper()
12 buf, err := io.ReadAll(DecodeReader(charset, strings.NewReader(input)))
13 tcheck(t, err, "decode")
14 if string(buf) != output {
15 t.Fatalf("decoding %q with charset %q, got %q, expected %q", input, charset, buf, output)
16 }
17 }
18
19 check("", "☺", "☺") // No decoding.
20 check("us-ascii", "☺", "☺") // No decoding.
21 check("utf-8", "☺", "☺")
22 check("iso-8859-1", string([]byte{0xa9}), "©")
23 check("iso-8859-5", string([]byte{0xd0}), "а")
24}
25