#!./perl
BEGIN {
chdir
't'
if
-d
't'
;
require
'./test.pl'
;
}
skip_all_if_miniperl(
"no dynamic loading on miniperl, no File::Spec (used by charnames)"
);
plan(
tests
=> 147);
{
my
@spaces
=(
ord
(
"\t"
),
ord
(
"\n"
),
ord
(
"\f"
),
ord
(
"\r"
),
ord
(
" "
),
ord
(
"\N{NEL}"
),
ord
(
"\N{NO-BREAK SPACE}"
),
0x1680,
0x2000..0x200A,
0x2028,
0x2029,
0x202F,
0x205F,
0x3000
);
foreach
my
$cp
(
@spaces
) {
my
$msg
=
sprintf
"Space: U+%04x"
,
$cp
;
my
$space
=
chr
(
$cp
);
my
$str
=
"A:$space:B\x{FFFD}"
;
chop
$str
;
my
@res
=
split
(/\s+/,
$str
);
my
$cnt
=
split
(/\s+/,
$str
);
ok(
@res
== 2 &&
join
(
'-'
,
@res
) eq
"A:-:B"
,
"$msg - /\\s+/"
);
is(
$cnt
,
scalar
(
@res
),
"$msg - /\\s+/ (count)"
);
my
$s2
=
"$space$space:A:$space$space:B\x{FFFD}"
;
chop
$s2
;
my
@r2
=
split
(
' '
,
$s2
);
my
$c2
=
split
(
' '
,
$s2
);
ok(
@r2
== 2 &&
join
(
'-'
,
@r2
) eq
":A:-:B"
,
"$msg - ' '"
);
is(
$c2
,
scalar
(
@r2
),
"$msg - ' ' (count)"
);
my
@r3
=
split
(/\s+/,
$s2
);
my
$c3
=
split
(/\s+/,
$s2
);
ok(
@r3
== 3 &&
join
(
'-'
,
@r3
) eq
"-:A:-:B"
,
"$msg - /\\s+/ No.2"
);
is(
$c3
,
scalar
(
@r3
),
"$msg - /\\s+/ No.2 (count)"
);
}
{
warning_is(
sub
{
$p
=
chr
(0x100);
for
(
"."
,
"ab\x{101}def"
) {
@q
=
split
/
$p
/
}
},
undef
,
'no warnings when part of split cant match non-utf8'
);
}
}
{
my
$string
=
"\x{100}\x{101}\x{102}"
;
$_
=
join
(
':'
,
split
(//,
$string
, 2));
is(
$_
,
"\x{100}:\x{101}\x{102}"
,
"Split into specified number of fields with empty pattern"
);
@ary
=
split
(//,
$string
, 2);
$cnt
=
split
(//,
$string
, 2);
is(
$cnt
,
scalar
(
@ary
),
"Check element count from previous test"
);
}