diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 2003-06-14 09:28:01 +0000 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2003-06-14 09:28:01 +0000 |
commit | 6e37fd2a54b1a286397ea047abb89aad1f47cd8d (patch) | |
tree | 13236decbb86bb6f5bfff65d2091dac9b335e85a /lib/utf8.t | |
parent | 8800c35a0a1b4f206c0a9ba7f62bf82cc177d98e (diff) | |
download | perl-6e37fd2a54b1a286397ea047abb89aad1f47cd8d.tar.gz |
Exercise the utf8:: "internal" functions.
p4raw-id: //depot/perl@19778
Diffstat (limited to 'lib/utf8.t')
-rw-r--r-- | lib/utf8.t | 79 |
1 files changed, 78 insertions, 1 deletions
diff --git a/lib/utf8.t b/lib/utf8.t index 223bb1d825..33cd5966af 100644 --- a/lib/utf8.t +++ b/lib/utf8.t @@ -37,7 +37,7 @@ no utf8; # Ironic, no? # # -plan tests => 99; +plan tests => 143; { # bug id 20001009.001 @@ -332,3 +332,80 @@ SKIP: { eval qq{is(q \xc3\xbc test \xc3\xbc, qq\xc2\xb7 test \xc2\xb7, "utf8 quote delimiters [perl #16823]");}; } + +# Test the "internals". + +{ + my $a = "A"; + my $b = chr(0x0FF); + my $c = chr(0x100); + + ok( utf8::valid($a), "utf8::valid basic"); + ok( utf8::valid($b), "utf8::valid beyond"); + ok( utf8::valid($c), "utf8::valid unicode"); + + ok(!utf8::is_utf8($a), "!utf8::is_utf8 basic"); + ok(!utf8::is_utf8($b), "!utf8::is_utf8 beyond"); + ok( utf8::is_utf8($c), "utf8::is_utf8 unicode"); + + is(utf8::upgrade($a), 1, "utf8::upgrade basic"); + is(utf8::upgrade($b), 2, "utf8::upgrade beyond"); + is(utf8::upgrade($c), 2, "utf8::upgrade unicode"); + + is($a, "A", "basic"); + is($b, "\xFF", "beyond"); + is($c, "\x{100}", "unicode"); + + ok( utf8::valid($a), "utf8::valid basic"); + ok( utf8::valid($b), "utf8::valid beyond"); + ok( utf8::valid($c), "utf8::valid unicode"); + + ok( utf8::is_utf8($a), "utf8::is_utf8 basic"); + ok( utf8::is_utf8($b), "utf8::is_utf8 beyond"); + ok( utf8::is_utf8($c), "utf8::is_utf8 unicode"); + + is(utf8::downgrade($a), 1, "utf8::downgrade basic"); + is(utf8::downgrade($b), 1, "utf8::downgrade beyond"); + + is($a, "A", "basic"); + is($b, "\xFF", "beyond"); + + ok( utf8::valid($a), "utf8::valid basic"); + ok( utf8::valid($b), "utf8::valid beyond"); + + ok(!utf8::is_utf8($a), "!utf8::is_utf8 basic"); + ok(!utf8::is_utf8($b), "!utf8::is_utf8 beyond"); + + utf8::encode($a); + utf8::encode($b); + utf8::encode($c); + + is($a, "A", "basic"); + is(length($b), 2, "beyond length"); + is(length($c), 2, "unicode length"); + + ok(utf8::valid($a), "utf8::valid basic"); + ok(utf8::valid($b), "utf8::valid beyond"); + ok(utf8::valid($c), "utf8::valid unicode"); + + # encode() clears the UTF-8 flag (unlike upgrade()). + ok(!utf8::is_utf8($a), "!utf8::is_utf8 basic"); + ok(!utf8::is_utf8($b), "!utf8::is_utf8 beyond"); + ok(!utf8::is_utf8($c), "!utf8::is_utf8 unicode"); + + utf8::decode($a); + utf8::decode($b); + utf8::decode($c); + + is($a, "A", "basic"); + is($b, "\xFF", "beyond"); + is($c, "\x{100}", "unicode"); + + ok(utf8::valid($a), "!utf8::valid basic"); + ok(utf8::valid($b), "!utf8::valid beyond"); + ok(utf8::valid($c), " utf8::valid unicode"); + + ok(!utf8::is_utf8($a), "!utf8::is_utf8 basic"); + ok( utf8::is_utf8($b), " utf8::is_utf8 beyond"); # $b stays in UTF-8. + ok( utf8::is_utf8($c), " utf8::is_utf8 unicode"); +} |