OS X 上的 Perl Unicode 测试在 Debian 上失败 [英] Perl Unicode test on OS X fails on Debian

查看:38
本文介绍了OS X 上的 Perl Unicode 测试在 Debian 上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下测试:

use Test::More;
use Lingua::EN::NameCase 'nc';
use utf8;
my $output = Test::Builder->new->todo_output;
binmode $output, ':encoding(UTF-8)';
$output = Test::Builder->new->failure_output;
binmode $output, ':encoding(UTF-8)';

my $name = 'Lintão';
is nc($name), $name, 'nc() should not change a properly namecased name';
diag nc($name);

done_testing;

在使用 Perl 5.10.1 的 Mac OS X 上,我得到以下输出:

On Mac OS X with Perl 5.10.1, I get the following output:

nc.t ..
ok 1 - nc() should not change a properly namecased name
1..1
# Lintão
ok
All tests successful.
Files=1, Tests=1,  0 wallclock secs ( 0.02 usr  0.01 sys +  0.04 cusr  0.00 csys =  0.07 CPU)
Result: PASS

不幸的是,在 Debian Squeezebox 上使用 5.10.1 Perl 进行的相同测试产生了以下输出:

Unfortunately, the same test on Debian Squeezebox, with 5.10.1 Perl produces this output:

nc.t ..
not ok 1 - nc() should not change a properly namecased name

#   Failed test 'nc() should not change a properly namecased name'
#   at nc.t line 10.
#          got: 'LintãO'
#     expected: 'Lintão'
# LintãO
1..1
# Looks like you failed 1 test of 1.
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/1 subtests

Test Summary Report
-------------------
nc.t (Wstat: 256 Tests: 1 Failed: 1)
  Failed test:  1
  Non-zero exit status: 1
Files=1, Tests=1,  0 wallclock secs ( 0.01 usr  0.00 sys +  0.03 cusr  0.00 csys =  0.04 CPU)
Result: FAIL

nc() 子程序中的违规行似乎是这样的:

The offending line in the nc() subroutine appears to be this:

s{ \b (\w)   }{\u$1}gox ;           # Uppercase first letter of every word.

不知何故,Debian 上相同版本的 Perl 出现了单词边界错误.谁能帮我进一步调试?

So somehow, the same version of Perl on Debian is getting the word boundary wrong. Can anyone help me debug further?

推荐答案

Linux 机器上的语言环境不考虑 ã 一个单词字符 (Lingua::EN::NameCase 具有 use locale; 因此它使用当前的 LC_CTYPE 设置进行字符分类).使用范围从 5.8.1 到 5.18.1 的 perlbrewed perls 我在带有 en_GB.UTF-8 语言环境的 Ubuntu 12.04 LTS 上持续获得此输出:

The locale on your Linux box doesn't consider ã a word character (Lingua::EN::NameCase has use locale; so it uses the current LC_CTYPE setting for character classification). With perlbrewed perls ranging from 5.8.1 to 5.18.1 I get this output consitently on Ubuntu 12.04 LTS with en_GB.UTF-8 locale:

$ perl -Mutf8 -le 'print 0+("ã" =~ /\w/); use locale; print 0+("ã" =~ /\w/)'
1
0

这篇关于OS X 上的 Perl Unicode 测试在 Debian 上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆