(t *testing.T)
| 129 | } |
| 130 | |
| 131 | func TestConvertToUTF8(t *testing.T) { |
| 132 | t.Run("utf-8 passthrough", func(t *testing.T) { |
| 133 | input := []byte("Привет мир") |
| 134 | got := convertToUTF8(input, "utf-8") |
| 135 | if string(got) != "Привет мир" { |
| 136 | t.Errorf("got %q", got) |
| 137 | } |
| 138 | }) |
| 139 | |
| 140 | t.Run("empty charset passthrough", func(t *testing.T) { |
| 141 | input := []byte("hello") |
| 142 | got := convertToUTF8(input, "") |
| 143 | if string(got) != "hello" { |
| 144 | t.Errorf("got %q", got) |
| 145 | } |
| 146 | }) |
| 147 | |
| 148 | t.Run("windows-1250 czech", func(t *testing.T) { |
| 149 | // "týmu se vám ozve" in windows-1250 |
| 150 | win1250 := []byte{0x74, 0xFD, 0x6D, 0x75, 0x20, 0x73, 0x65, 0x20, 0x76, 0xE1, 0x6D, 0x20, 0x6F, 0x7A, 0x76, 0x65} |
| 151 | got := convertToUTF8(win1250, "windows-1250") |
| 152 | want := "týmu se vám ozve" |
| 153 | if string(got) != want { |
| 154 | t.Errorf("got %q, want %q", got, want) |
| 155 | } |
| 156 | }) |
| 157 | |
| 158 | t.Run("iso-8859-1 latin", func(t *testing.T) { |
| 159 | // "café" in iso-8859-1: 0x63 0x61 0x66 0xe9 |
| 160 | latin1 := []byte{0x63, 0x61, 0x66, 0xe9} |
| 161 | got := convertToUTF8(latin1, "iso-8859-1") |
| 162 | if string(got) != "café" { |
| 163 | t.Errorf("got %q, want %q", got, "café") |
| 164 | } |
| 165 | }) |
| 166 | |
| 167 | t.Run("unknown charset passthrough", func(t *testing.T) { |
| 168 | input := []byte("data") |
| 169 | got := convertToUTF8(input, "x-nonexistent-999") |
| 170 | if string(got) != "data" { |
| 171 | t.Errorf("got %q", got) |
| 172 | } |
| 173 | }) |
| 174 | } |
| 175 | |
| 176 | func TestParseEmail_CharsetConversion(t *testing.T) { |
| 177 | t.Run("single part windows-1250", func(t *testing.T) { |
nothing calls this directly
no test coverage detected