@@ -31,3 +31,55 @@ func TestPostalAddressRoundTrip(t *testing.T) {
3131 })
3232 }
3333}
34+
35+ func TestPostalAddressUTF8Handling (t * testing.T ) {
36+ testCases := []struct {
37+ name string
38+ lines []string
39+ expected string
40+ }{
41+ {
42+ name : "emoji characters" ,
43+ lines : []string {"123 Main St 🏠" , "Tokyo 🗾" , "Japan 🇯🇵" },
44+ expected : "123 Main St 🏠$Tokyo 🗾$Japan 🇯🇵$" ,
45+ },
46+ {
47+ name : "cyrillic characters" ,
48+ lines : []string {"Красная площадь" , "Москва 101000" , "Россия" },
49+ expected : "Красная площадь$Москва 101000$Россия$" ,
50+ },
51+ {
52+ name : "chinese characters" ,
53+ lines : []string {"北京市东城区" , "天安门广场" , "中国" },
54+ expected : "北京市东城区$天安门广场$中国$" ,
55+ },
56+ {
57+ name : "arabic characters" ,
58+ lines : []string {"شارع الملك فهد" , "الرياض" , "المملكة العربية السعودية" },
59+ expected : "شارع الملك فهد$الرياض$المملكة العربية السعودية$" ,
60+ },
61+ {
62+ name : "mixed scripts with special chars" ,
63+ lines : []string {"Café René ☕" , "Zürich $1000\\ month" , "Schweiz 🇨🇭" },
64+ expected : "Café René ☕$Zürich \\ 241000\\ 5Cmonth$Schweiz 🇨🇭$" ,
65+ },
66+ {
67+ name : "mathematical symbols" ,
68+ lines : []string {"∑ ∫ ∂" , "π ≈ 3.14159" , "∞ ≠ 0" },
69+ expected : "∑ ∫ ∂$π ≈ 3.14159$∞ ≠ 0$" ,
70+ },
71+ }
72+
73+ for _ , tc := range testCases {
74+ t .Run (tc .name , func (t * testing.T ) {
75+ addr := NewPostalAddress (tc .lines )
76+ escaped := addr .Escape ()
77+ assert .Equal (t , tc .expected , escaped , "UTF-8 characters should be preserved in escaped output" )
78+
79+ // Round-trip test
80+ parsed , err := ParsePostalAddress (escaped )
81+ assert .NoError (t , err )
82+ assert .Equal (t , tc .lines , parsed .Lines (), "UTF-8 characters should survive round-trip" )
83+ })
84+ }
85+ }
0 commit comments