This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perldelta - move split change to other perlfunc changes and add issue link
[perl5.git] / t / op / utf8magic.t
CommitLineData
b1f58cbd
RGS
1#!perl
2
3BEGIN {
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 10plan tests => 6;
b1f58cbd 11
76f73021 12use strict;
76f73021 13
14my $str = "\x{99f1}\x{99dd}"; # "camel" in Japanese kanji
15$str =~ /(.)/;
16
17ok utf8::is_utf8($1), "is_utf8(unistr)";
18scalar "$1"; # invoke SvGETMAGIC
19ok utf8::is_utf8($1), "is_utf8(unistr)";
20
21utf8::encode($str); # off the utf8 flag
22$str =~ /(.)/;
23
24ok !utf8::is_utf8($1), "is_utf8(bytes)";
25scalar "$1"; # invoke SvGETMAGIC
26ok !utf8::is_utf8($1), "is_utf8(bytes)";
892f9127
FC
27
28sub TIESCALAR { bless [pop] }
29sub FETCH { $_[0][0] }
30sub STORE { $::stored = pop }
31
32tie my $str2, "", "a";
33$str2 = "b";
34utf8::encode $str2;
35is $::stored, "a", 'utf8::encode respects get-magic on POK scalars';
77fc86ef 36
7abb7a18 37tie $str2, "", byte_utf8a_to_utf8n("\xc4\x80");
77fc86ef
FC
38utf8::decode $str2;
39is $::stored, "\x{100}", 'utf8::decode respects set-magic';