github.com/la5nta/wl2k-go@v0.11.8/fbb/header_test.go (about) 1 package fbb 2 3 import "testing" 4 5 func TestSubjectDecode(t *testing.T) { 6 raw := []byte{0x74, 0x65, 0x73, 0x74, 0x20, 0xe6, 0xf8, 0xe5} // test æøå 7 8 // RMS Express compatibility test (encodes subject as ISO-8859-1) 9 msg := &Message{Header: Header{"Subject": []string{string(raw)}}} 10 if decoded := msg.Subject(); decoded != "test æøå" { 11 t.Errorf("Subject with no word-encoding not decoded as ISO-8859-1.") 12 } 13 14 msg.Header["Subject"] = []string{"=?utf-8?q?=C2=A1Hola,_se=C3=B1or!?="} 15 if decoded := msg.Subject(); decoded != "¡Hola, señor!" { 16 t.Errorf("Subject with Q-encoded utf-8 not decoded correctly.") 17 } 18 19 msg.Header["Subject"] = []string{"=?ISO-8859-1?q?Test_=E6=F8=E5_abc?="} 20 if decoded := msg.Subject(); decoded != "Test æøå abc" { 21 t.Errorf("Subject with Q-encoded ISO-8859-1 not decoded correctly.") 22 } 23 } 24 25 func TestSubjectEncode(t *testing.T) { 26 msg := &Message{Header: make(Header, 1)} 27 28 msg.SetSubject("Test æøå abc") 29 if msg.Header["Subject"][0] != "=?ISO-8859-1?q?Test_=E6=F8=E5_abc?=" { 30 t.Errorf("Subject not Q-encoded using ISO-8859-1.") 31 } 32 33 msg.SetSubject("Test 123 foo bar") 34 if msg.Header["Subject"][0] != "Test 123 foo bar" { 35 t.Errorf("ASCII-only subject modified on encode.") 36 } 37 } 38 39 func TestSubjectRoundtrip(t *testing.T) { 40 msg := &Message{Header: make(Header, 1)} 41 42 str := "Hello, æøå" 43 msg.SetSubject(str) 44 45 if msg.Subject() != str { 46 t.Errorf("Subject encode/decode roundtrip failed. (%s)", msg.Subject()) 47 } 48 }