| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use Test::More; |
| 4 |
use Date::Language; |
| 5 |
|
| 6 |
# RT#113419 / GH#19: Language modules must return Unicode strings (UTF-8 flagged), |
| 7 |
# not raw byte strings in legacy encodings. |
| 8 |
# |
| 9 |
# Legacy encoding modules (Chinese_GB, Russian, Russian_koi8r, Russian_cp1251) |
| 10 |
# intentionally return byte strings and are excluded from this check. |
| 11 |
|
| 12 |
my @unicode_langs = qw( |
| 13 |
Afar |
| 14 |
Amharic |
| 15 |
Arabic |
| 16 |
Austrian |
| 17 |
Brazilian |
| 18 |
Bulgarian |
| 19 |
Chinese |
| 20 |
Czech |
| 21 |
Danish |
| 22 |
Dutch |
| 23 |
English |
| 24 |
Finnish |
| 25 |
French |
| 26 |
Gedeo |
| 27 |
German |
| 28 |
Greek |
| 29 |
Hungarian |
| 30 |
Icelandic |
| 31 |
Italian |
| 32 |
Norwegian |
| 33 |
Occitan |
| 34 |
Oromo |
| 35 |
Romanian |
| 36 |
Sidama |
| 37 |
Somali |
| 38 |
Spanish |
| 39 |
Swedish |
| 40 |
Tigrinya |
| 41 |
TigrinyaEritrean |
| 42 |
TigrinyaEthiopian |
| 43 |
Turkish |
| 44 |
); |
| 45 |
|
| 46 |
# Tue Sep 7 13:02:42 1999 GMT |
| 47 |
my $time = 936709362; |
| 48 |
|
| 49 |
for my $lang (@unicode_langs) { |
| 50 |
my $l = Date::Language->new($lang); |
| 51 |
|
| 52 |
for my $fmt (qw(%A %a %B %b)) { |
| 53 |
my $str = $l->time2str($fmt, $time, 'GMT'); |
| 54 |
|
| 55 |
# Pure-ASCII strings don't get the UTF-8 flag; skip them. |
| 56 |
next unless $str =~ /[^\x00-\x7f]/; |
| 57 |
|
| 58 |
ok( |
| 59 |
utf8::is_utf8($str), |
| 60 |
"$lang $fmt: non-ASCII result has UTF-8 flag set" |
| 61 |
); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
done_testing; |