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