xref: /openbsd/gnu/usr.bin/perl/t/op/utf8magic.t (revision 9f11ffb7)
1#!perl
2
3BEGIN {
4    chdir 't' if -d 't';
5    require './test.pl';
6    set_up_inc('../lib');
7    require './charset_tools.pl';
8}
9
10plan tests => 6;
11
12use strict;
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)";
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';
36
37tie $str2, "", byte_utf8a_to_utf8n("\xc4\x80");
38utf8::decode $str2;
39is $::stored, "\x{100}", 'utf8::decode respects set-magic';
40