1#!perl 2 3BEGIN { 4 chdir 't' if -d 't'; 5 @INC = '../lib'; 6 require './test.pl'; 7} 8 9plan tests => 6; 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'; 35 36tie $str2, "", "\xc4\x80"; 37utf8::decode $str2; 38is $::stored, "\x{100}", 'utf8::decode respects set-magic'; 39