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