Subject: | name() and names() methods do not work as documented |
In the documentation for Unicode::Char I read:
#####
"$u->name()"
Returns the Unicode Canonical Name of the character.;
my $name = $u->name(chr(0x263A)); # WHITE SMILING FACE
"$u->names()"
Same as above but in list context.
my (@names) = $u->name("perl"); # ('LATIN SMALL LETTER P',
# 'LATIN SMALL LETTER E',
# 'LATIN SMALL LETTER R',
# 'LATIN SMALL LETTER L')
#####
I am in the process of studying a ticket in the Perl 5 core distribution pertaining to Unicode-Char: https://github.com/Perl/perl5/issues/17766
Since there is no github.com repository for this distribution (yet), I created one locally beginning with the tarball for 0.02. As I customarily do when preparing a patch, I ran the test suite through Devel::Cover to see where test coverage was lacking. That drew my attention to the names() method. I therefore wrote a test file (attached) setting expectations on the basis of the documentation cited above. When I ran the test file, however, I saw that the name() and names() methods appear to be misidentifying lower case letters.
#####
$ prove -vb t/04-names.t
t/04-names.t ..
1..9
ok 1 - Got P
ok 2 - Got e
ok 3 - Got r
ok 4 - Got l
ok 5 - name() method works as expected: P
not ok 6 - name() method works as expected: e
# Failed test 'name() method works as expected: e'
# at t/04-names.t line 21.
# got: '0329 LATIN SMALL LETTER E WITH VERTICAL LINE BELOW'
# expected: 'LATIN SMALL LETTER E'
not ok 7 - name() method works as expected: r
# Failed test 'name() method works as expected: r'
# at t/04-names.t line 22.
# got: '0303 LATIN SMALL LETTER R WITH TILDE'
# expected: 'LATIN SMALL LETTER R'
not ok 8 - name() method works as expected: l
# Failed test 'name() method works as expected: l'
# at t/04-names.t line 23.
# got: '0303 LATIN SMALL LETTER L WITH TILDE'
# expected: 'LATIN SMALL LETTER L'
not ok 9 - names() method works as expected in list context
# Failed test 'names() method works as expected in list context'
# at t/04-names.t line 26.
# Structures begin differing at:
# $got->[1] = '0329 LATIN SMALL LETTER E WITH VERTICAL LINE BELOW'
# $expected->[1] = 'LATIN SMALL LETTER E'
$VAR1 = [
'LATIN CAPITAL LETTER P',
'0329 LATIN SMALL LETTER E WITH VERTICAL LINE BELOW',
'0303 LATIN SMALL LETTER R WITH TILDE',
'0303 LATIN SMALL LETTER L WITH TILDE'
];
# Looks like you failed 4 tests of 9.
Dubious, test returned 4 (wstat 1024, 0x400)
Failed 4/9 subtests
Test Summary Report
-------------------
t/04-names.t (Wstat: 1024 Tests: 9 Failed: 4)
Failed tests: 6-9
Non-zero exit status: 4
Files=1, Tests=9, 0 wallclock secs ( 0.00 usr 0.01 sys + 0.13 cusr 0.01 csys = 0.15 CPU)
Result: FAIL
#####
$ perl -v | head -2 | tail -1
This is perl 5, version 30, subversion 0 (v5.30.0) built for x86_64-linux
But also got same results on perl-5.18.4.
Can you investigate?
Thank you very much.
Jim Keenan
Subject: | 04-names.t |
use strict;
use warnings;
use Test::More tests => 9;
use Data::Dumper; $Data::Dumper::Indent=1;
use Unicode::Char;
my $v = Unicode::Char->new;
is($v->n('latin capital letter p'),"P", "Got P");
is($v->n('latin small letter e'), "e", "Got e");
is($v->n('latin small letter r'), "r", "Got r");
is($v->n('latin small letter l'), "l", "Got l");
my @expect = (
'LATIN CAPITAL LETTER P',
'LATIN SMALL LETTER E',
'LATIN SMALL LETTER R',
'LATIN SMALL LETTER L',
);
is($v->name('P'), $expect[0], "name() method works as expected: P");
is($v->name('e'), $expect[1], "name() method works as expected: e");
is($v->name('r'), $expect[2], "name() method works as expected: r");
is($v->name('l'), $expect[3], "name() method works as expected: l");
my (@names) = $v->names("Perl");
is_deeply(\@names, \@expect, "names() method works as expected in list context")
or print Dumper [ @names ];