⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 12_hashwarn.t

📁 source of perl for linux application,
💻 T
字号:
#!./perlBEGIN {    if ($ENV{PERL_CORE}) {	chdir 't' if -d 't';	@INC = '../lib';    }}use Test::More;plan( tests => 12 );use strict;use warnings;use Hash::Util::FieldHash qw( :all);use vars qw{ @warnings };BEGIN {    $SIG{'__WARN__'} = sub { push @warnings, @_ };    $| = 1;}my $fail_odd      = 'Odd number of elements in hash assignment at ';my $fail_odd_anon = 'Odd number of elements in anonymous hash at ';my $fail_ref      = 'Reference found where even-sized list expected at ';my $fail_not_hr   = 'Not a HASH reference at ';{    @warnings = ();    fieldhash my %hash;    %hash = (1..3);    cmp_ok(scalar(@warnings),'==',1,'odd count');    cmp_ok(substr($warnings[0],0,length($fail_odd)),'eq',$fail_odd,'odd  msg');    @warnings = ();    %hash = 1;    cmp_ok(scalar(@warnings),'==',1,'scalar count');    cmp_ok(substr($warnings[0],0,length($fail_odd)),'eq',$fail_odd,'scalar msg');    @warnings = ();    %hash = { 1..3 };    cmp_ok(scalar(@warnings),'==',2,'odd hashref count');    cmp_ok(substr($warnings[0],0,length($fail_odd_anon)),'eq',$fail_odd_anon,'odd hashref msg 1');    cmp_ok(substr($warnings[1],0,length($fail_ref)),'eq',$fail_ref,'odd hashref msg 2');    @warnings = ();    %hash = [ 1..3 ];    cmp_ok(scalar(@warnings),'==',1,'arrayref count');    cmp_ok(substr($warnings[0],0,length($fail_ref)),'eq',$fail_ref,'arrayref msg');    @warnings = ();    %hash = sub { print "fenice" };    cmp_ok(scalar(@warnings),'==',1,'coderef count');    cmp_ok(substr($warnings[0],0,length($fail_odd)),'eq',$fail_odd,'coderef msg');    @warnings = ();    $_ = { 1..10 };    cmp_ok(scalar(@warnings),'==',0,'hashref assign');}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -