mox/message/decode_test.go
Mechiel Lukkien 72ac1fde29
expose fewer internals in packages, for easier software reuse
- prometheus is now behind an interface, they aren't dependencies for the
  reusable components anymore.
- some dependencies have been inverted: instead of packages importing a main
  package to get configuration, the main package now sets configuration in
  these packages. that means fewer internals are pulled in.
- some functions now have new parameters for values that were retrieved from
  package "mox-".
2023-12-14 15:39:36 +01:00

24 lines
615 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package message
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)))
tcheck(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}), "а")
}