This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
make do "a\0b" fail silently instead of throwing (RT #129928)
[perl5.git] / t / op / utf8magic.t
1 #!perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     require './test.pl';
6     set_up_inc('../lib');
7     require './charset_tools.pl';
8 }
9
10 plan tests => 6;
11
12 use strict;
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)";
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';
36
37 tie $str2, "", byte_utf8a_to_utf8n("\xc4\x80");
38 utf8::decode $str2;
39 is $::stored, "\x{100}", 'utf8::decode respects set-magic';