From: Jarkko Hietaniemi Date: Tue, 3 Jul 2001 22:45:41 +0000 (+0000) Subject: Add tests for charscript(). X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a196fbfd2938a6fe215a07e9209acfe497d87208;p=p5sagit%2Fp5-mst-13.2.git Add tests for charscript(). p4raw-id: //depot/perl@11129 --- diff --git a/lib/Unicode/UCD.pm b/lib/Unicode/UCD.pm index f4a3a64..81a9aed 100644 --- a/lib/Unicode/UCD.pm +++ b/lib/Unicode/UCD.pm @@ -122,7 +122,8 @@ sub charinfo { upper lower title )} = split(/;/, $line, -1); if ($prop{code} eq $hexk) { - $prop{block} = charblock($code); + $prop{block} = charblock($code); + $prop{script} = charscript($code); return %prop; } } @@ -138,7 +139,7 @@ sub _search { # Binary search in a [[lo,hi,prop],[...],...] table. my $mid = int(($lo+$hi) / 2); if ($table->[$mid]->[0] < $code) { - if ($table->[$mid]->[1] >= $code) { + if (defined $table->[$mid]->[1] && $table->[$mid]->[1] >= $code) { return $table->[$mid]->[2]; } else { _search($table, $mid + 1, $hi, $code); diff --git a/lib/Unicode/UCD.t b/lib/Unicode/UCD.t index 731ac8f..42c9a90 100644 --- a/lib/Unicode/UCD.t +++ b/lib/Unicode/UCD.t @@ -3,7 +3,7 @@ use Unicode::UCD 3.1.0; use Test; use strict; -BEGIN { plan tests => 81 }; +BEGIN { plan tests => 87 }; use Unicode::UCD 'charinfo'; @@ -27,6 +27,7 @@ ok($charinfo{upper}, ''); ok($charinfo{lower}, '0061'); ok($charinfo{title}, ''); ok($charinfo{block}, 'Basic Latin'); +ok($charinfo{script}, 'LATIN'); %charinfo = charinfo(0x100); @@ -46,6 +47,9 @@ ok($charinfo{upper}, ''); ok($charinfo{lower}, '0101'); ok($charinfo{title}, ''); ok($charinfo{block}, 'Latin Extended-A'); +ok($charinfo{script}, 'LATIN'); + +# 0x0590 is in the Hebrew block but unused. %charinfo = charinfo(0x590); @@ -65,6 +69,9 @@ ok($charinfo{upper}, undef); ok($charinfo{lower}, undef); ok($charinfo{title}, undef); ok($charinfo{block}, undef); +ok($charinfo{script}, undef); + +# 0x05d0 is in the Hebrew block and used. %charinfo = charinfo(0x5d0); @@ -84,10 +91,14 @@ ok($charinfo{upper}, ''); ok($charinfo{lower}, ''); ok($charinfo{title}, ''); ok($charinfo{block}, 'Hebrew'); +ok($charinfo{script}, 'HEBREW'); -use Unicode::UCD 'charblock'; +use Unicode::UCD qw(charblock charscript); + +# 0x0590 is in the Hebrew block but unused. ok(charblock(0x590), 'Hebrew'); +ok(charscript(0x590), undef); %charinfo = charinfo(0xbe); @@ -107,4 +118,4 @@ ok($charinfo{upper}, ''); ok($charinfo{lower}, ''); ok($charinfo{title}, ''); ok($charinfo{block}, 'Latin-1 Supplement'); - +ok($charinfo{script}, undef);