summaryrefslogtreecommitdiff
path: root/t/uni
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2008-01-12 21:57:06 +0000
committerNicholas Clark <nick@ccl4.org>2008-01-12 21:57:06 +0000
commitd06445298904613950b0410a2f3b1125ab58c7b5 (patch)
tree92e2d7a0ef4e7d624ece57876c27798319fb2f07 /t/uni
parentea9222e0361fc718c049fb5b7d00308ef9b0978d (diff)
downloadperl-d06445298904613950b0410a2f3b1125ab58c7b5.tar.gz
Fix bug whereby length on a tied scalar that returned a UTF-8 value
would not be correct the first time. (And for the more pathological case, would be incorrect if the UTF-8-ness of the returned value changed.) p4raw-id: //depot/perl@32968
Diffstat (limited to 't/uni')
-rw-r--r--t/uni/tie.t49
1 files changed, 49 insertions, 0 deletions
diff --git a/t/uni/tie.t b/t/uni/tie.t
new file mode 100644
index 0000000000..fa9f268bbf
--- /dev/null
+++ b/t/uni/tie.t
@@ -0,0 +1,49 @@
+#!perl -w
+
+BEGIN {
+ if ($ENV{'PERL_CORE'}){
+ chdir 't';
+ @INC = '../lib';
+ }
+}
+
+use Test::More tests => 9;
+use strict;
+
+{
+ package UTF8Toggle;
+
+ sub TIESCALAR {
+ my $class = shift;
+ my $value = shift;
+ my $state = shift||0;
+ return bless [$value, $state], $class;
+ }
+
+ sub FETCH {
+ my $self = shift;
+ $self->[1] = ! $self->[1];
+ if ($self->[1]) {
+ utf8::downgrade($self->[0]);
+ } else {
+ utf8::upgrade($self->[0]);
+ }
+ $self->[0];
+ }
+}
+
+foreach my $t ("ASCII", "B\366se") {
+ my $length = length $t;
+
+ my $u;
+ tie $u, 'UTF8Toggle', $t;
+ is (length $u, $length, "length of '$t'");
+ is (length $u, $length, "length of '$t'");
+ is (length $u, $length, "length of '$t'");
+ is (length $u, $length, "length of '$t'");
+}
+
+{
+ local $TODO = "Need more tests!";
+ fail();
+}