-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved trim() and added tests for -Ofun
There actually was an error in my trim(), and doing /^\s+(.*)\s+$/$1/ is not right either. Tests prove it :)
- Loading branch information
Showing
2 changed files
with
43 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
=head1 NAME | ||
t/trim.t - Net::Statsd::Server test suite | ||
=head1 DESCRIPTION | ||
Tests the trim function | ||
=cut | ||
|
||
use strict; | ||
use warnings; | ||
use Test::More; | ||
|
||
use Net::Statsd::Server; | ||
|
||
my @tests = ( | ||
[ ' abc ' => 'abc' ], | ||
[ ' def' => 'def' ], | ||
[ 'ghi ' => 'ghi' ], | ||
[ ' abc def ghi ' => 'abc def ghi' ], | ||
[ ' ' => '' ], | ||
[ ' ' => '' ], | ||
[ '' => '' ], | ||
[ undef, undef ], | ||
); | ||
|
||
plan tests => @tests * 2; | ||
|
||
for (@tests) { | ||
my ($str, $expected) = @{ $_ }; | ||
my $copy_of_str = $str; | ||
my $res = Net::Statsd::Server::trim($str); | ||
is($str, $copy_of_str, "trim() doesn't touch the original string"); | ||
is($res, $expected, "trim('$str') actually returns '$expected'"); | ||
} | ||
|
||
# END |