This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make utf8::encode respect magic
[perl5.git] / t / op / utf8magic.t
... / ...
CommitLineData
1#!perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6 require './test.pl';
7}
8
9plan tests => 5;
10
11use strict;
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)";
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';