| 1 | #!./perl
|
|---|
| 2 |
|
|---|
| 3 | BEGIN {
|
|---|
| 4 | chdir 't' if -d 't';
|
|---|
| 5 | @INC = '../lib';
|
|---|
| 6 | require './test.pl';
|
|---|
| 7 | }
|
|---|
| 8 |
|
|---|
| 9 | plan tests => 55;
|
|---|
| 10 |
|
|---|
| 11 | $FS = ':';
|
|---|
| 12 |
|
|---|
| 13 | $_ = 'a:b:c';
|
|---|
| 14 |
|
|---|
| 15 | ($a,$b,$c) = split($FS,$_);
|
|---|
| 16 |
|
|---|
| 17 | is(join(';',$a,$b,$c), 'a;b;c');
|
|---|
| 18 |
|
|---|
| 19 | @ary = split(/:b:/);
|
|---|
| 20 | is(join("$_",@ary), 'aa:b:cc');
|
|---|
| 21 |
|
|---|
| 22 | $_ = "abc\n";
|
|---|
| 23 | my @xyz = (@ary = split(//));
|
|---|
| 24 | is(join(".",@ary), "a.b.c.\n");
|
|---|
| 25 |
|
|---|
| 26 | $_ = "a:b:c::::";
|
|---|
| 27 | @ary = split(/:/);
|
|---|
| 28 | is(join(".",@ary), "a.b.c");
|
|---|
| 29 |
|
|---|
| 30 | $_ = join(':',split(' '," a b\tc \t d "));
|
|---|
| 31 | is($_, 'a:b:c:d');
|
|---|
| 32 |
|
|---|
| 33 | $_ = join(':',split(/ */,"foo bar bie\tdoll"));
|
|---|
| 34 | is($_ , "f:o:o:b:a:r:b:i:e:\t:d:o:l:l");
|
|---|
| 35 |
|
|---|
| 36 | $_ = join(':', 'foo', split(/ /,'a b c'), 'bar');
|
|---|
| 37 | is($_, "foo:a:b::c:bar");
|
|---|
| 38 |
|
|---|
| 39 | # Can we say how many fields to split to?
|
|---|
| 40 | $_ = join(':', split(' ','1 2 3 4 5 6', 3));
|
|---|
| 41 | is($_, '1:2:3 4 5 6');
|
|---|
| 42 |
|
|---|
| 43 | # Can we do it as a variable?
|
|---|
| 44 | $x = 4;
|
|---|
| 45 | $_ = join(':', split(' ','1 2 3 4 5 6', $x));
|
|---|
| 46 | is($_, '1:2:3:4 5 6');
|
|---|
| 47 |
|
|---|
| 48 | # Does the 999 suppress null field chopping?
|
|---|
| 49 | $_ = join(':', split(/:/,'1:2:3:4:5:6:::', 999));
|
|---|
| 50 | is($_ , '1:2:3:4:5:6:::');
|
|---|
| 51 |
|
|---|
| 52 | # Does assignment to a list imply split to one more field than that?
|
|---|
| 53 | $foo = runperl( switches => ['-Dt'], stderr => 1, prog => '($a,$b)=split;' );
|
|---|
| 54 | ok($foo =~ /DEBUGGING/ || $foo =~ /const\n?\Q(IV(3))\E/);
|
|---|
| 55 |
|
|---|
| 56 | # Can we say how many fields to split to when assigning to a list?
|
|---|
| 57 | ($a,$b) = split(' ','1 2 3 4 5 6', 2);
|
|---|
| 58 | $_ = join(':',$a,$b);
|
|---|
| 59 | is($_, '1:2 3 4 5 6');
|
|---|
| 60 |
|
|---|
| 61 | # do subpatterns generate additional fields (without trailing nulls)?
|
|---|
| 62 | $_ = join '|', split(/,|(-)/, "1-10,20,,,");
|
|---|
| 63 | is($_, "1|-|10||20");
|
|---|
| 64 |
|
|---|
| 65 | # do subpatterns generate additional fields (with a limit)?
|
|---|
| 66 | $_ = join '|', split(/,|(-)/, "1-10,20,,,", 10);
|
|---|
| 67 | is($_, "1|-|10||20||||||");
|
|---|
| 68 |
|
|---|
| 69 | # is the 'two undefs' bug fixed?
|
|---|
| 70 | (undef, $a, undef, $b) = qw(1 2 3 4);
|
|---|
| 71 | is("$a|$b", "2|4");
|
|---|
| 72 |
|
|---|
| 73 | # .. even for locals?
|
|---|
| 74 | {
|
|---|
| 75 | local(undef, $a, undef, $b) = qw(1 2 3 4);
|
|---|
| 76 | is("$a|$b", "2|4");
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | # check splitting of null string
|
|---|
| 80 | $_ = join('|', split(/x/, '',-1), 'Z');
|
|---|
| 81 | is($_, "Z");
|
|---|
| 82 |
|
|---|
| 83 | $_ = join('|', split(/x/, '', 1), 'Z');
|
|---|
| 84 | is($_, "Z");
|
|---|
| 85 |
|
|---|
| 86 | $_ = join('|', split(/(p+)/,'',-1), 'Z');
|
|---|
| 87 | is($_, "Z");
|
|---|
| 88 |
|
|---|
|
|---|