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