This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
more -ansi -pedantic cleanliness
[perl5.git] / t / uni / overload.t
CommitLineData
92331800
NC
1#!perl -w
2
3BEGIN {
4 if ($ENV{'PERL_CORE'}){
5 chdir 't';
6 @INC = '../lib';
7 }
8}
9
10use Test::More tests => 8;
11
12package UTF8Field;
13use strict;
14
15use overload '""' => 'stringify';
16
17sub new {
18 my $class = shift;
19 return bless [shift, 0], $class;
20}
21
22sub stringify {
23 my $self = shift;
24 $self->[1] = ! $self->[1];
25 if ($self->[1]) {
26 utf8::downgrade($self->[0]);
27 } else {
28 utf8::upgrade($self->[0]);
29 }
30 $self->[0];
31}
32
33package main;
34
35# Bug 34297
36foreach my $t ("ASCII", "B\366se") {
37 my $length = length $t;
38
39 my $u = UTF8Field->new($t);
40 is (length $u, $length, "length of '$t'");
41 is (length $u, $length, "length of '$t'");
42 is (length $u, $length, "length of '$t'");
43 is (length $u, $length, "length of '$t'");
44}