Commit | Line | Data |
---|---|---|
b1f58cbd RGS |
1 | #!perl |
2 | ||
3 | BEGIN { | |
4 | chdir 't' if -d 't'; | |
5 | @INC = '../lib'; | |
7abb7a18 | 6 | require './test.pl'; require './charset_tools.pl'; |
b1f58cbd RGS |
7 | } |
8 | ||
77fc86ef | 9 | plan tests => 6; |
b1f58cbd | 10 | |
76f73021 | 11 | use strict; |
76f73021 GF |
12 | |
13 | my $str = "\x{99f1}\x{99dd}"; # "camel" in Japanese kanji | |
14 | $str =~ /(.)/; | |
15 | ||
16 | ok utf8::is_utf8($1), "is_utf8(unistr)"; | |
17 | scalar "$1"; # invoke SvGETMAGIC | |
18 | ok utf8::is_utf8($1), "is_utf8(unistr)"; | |
19 | ||
20 | utf8::encode($str); # off the utf8 flag | |
21 | $str =~ /(.)/; | |
22 | ||
23 | ok !utf8::is_utf8($1), "is_utf8(bytes)"; | |
24 | scalar "$1"; # invoke SvGETMAGIC | |
25 | ok !utf8::is_utf8($1), "is_utf8(bytes)"; | |
892f9127 FC |
26 | |
27 | sub TIESCALAR { bless [pop] } | |
28 | sub FETCH { $_[0][0] } | |
29 | sub STORE { $::stored = pop } | |
30 | ||
31 | tie my $str2, "", "a"; | |
32 | $str2 = "b"; | |
33 | utf8::encode $str2; | |
34 | is $::stored, "a", 'utf8::encode respects get-magic on POK scalars'; | |
77fc86ef | 35 | |
7abb7a18 | 36 | tie $str2, "", byte_utf8a_to_utf8n("\xc4\x80"); |
77fc86ef FC |
37 | utf8::decode $str2; |
38 | is $::stored, "\x{100}", 'utf8::decode respects set-magic'; |