1use strict; 2use warnings; 3 4use Test::More tests => 10; 5 6BEGIN { 7 use_ok('Text::Trim'); 8} 9 10my $text = my $orig = "\t foo\t \t\n"; 11is(trim($text), 'foo', 'trim in scalar context'); 12is($text, $orig, ".. didn't affect original"); 13 14trim($text); 15is($text, 'foo', 'trim in place changes original'); 16 17{ 18 local $_ = $orig; 19 my $trimmed = trim; 20 is($trimmed, 'foo', '$scalar = trim() works on $_'); 21 is($_, , $orig, ".. didn't affect original"); 22 23 trim; 24 is($_, , 'foo', "trim() alters \$_") 25} 26 27my @before = ( 28 " foo ", 29 "\tbar\t", 30 "\nbaz\n", 31); 32my @expected = qw( foo bar baz ); 33my @trimmed = trim @before; 34is_deeply(\@trimmed, \@expected, 'trim on a list in list content'); 35trim @before; 36is_deeply(\@before, \@expected, 'trim on a list in place'); 37 38my $expected = "@expected"; 39my $trimmed = trim @before; 40is($trimmed, $expected, 'trim on a list in scalar context'); 41 42__END__ 43 44vim: ft=perl ts=8 sts=4 sw=4 sr et 45