Skip to content

Commit

Permalink
Add some chop tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Apr 23, 2015
1 parent 575e61a commit c4328db
Showing 1 changed file with 43 additions and 10 deletions.
53 changes: 43 additions & 10 deletions S32-str/chop.t
Expand Up @@ -3,25 +3,58 @@ use Test;

# L<S32::Str/Str/"=item chop">

plan 6;
plan 32;

#
# Tests already covered by the specs
#

my $str = "foo";
is(chop($str), "fo", "o removed");
is($str, "foo", "original string unchanged");
is chop($str), "fo", "o removed" ;
is $str, "foo", "chop() original string unchanged" ;
is chop($str,1), "fo", "o removed" ;
is $str, "foo", "chop() original string unchanged (1)" ;
is chop($str,2), "f", "oo removed" ;
is $str, "foo", "chop() original string unchanged (2)" ;
is chop($str,3), "", "foo removed" ;
is $str, "foo", "chop() original string unchanged (3)" ;
is chop($str,4), "", "foo removed" ;
is $str, "foo", "chop() original string unchanged (4)" ;

is($str.chop, "fo", "o removed");
is($str, "foo", "original string unchanged");
is $str.chop, "fo", "o removed" ;
is $str, "foo", ".chop original string unchanged" ;
is $str.chop(1), "fo", "o removed" ;
is $str, "foo", ".chop original string unchanged (1)" ;
is $str.chop(2), "f", "oo removed" ;
is $str, "foo", ".chop original string unchanged (2)" ;
is $str.chop(3), "", "foo removed" ;
is $str, "foo", ".chop original string unchanged (3)" ;
is $str.chop(4), "", "foo removed" ;
is $str, "foo", ".chop original string unchanged (4)" ;

is(chop("bar"), "ba", "chop on string literal");
is(chop(""), "", "chop on empty string literal");
my Int $int = 42;
is chop($int), "4", 'chop on Int';
is $int, 42, 'chop() original int unchanged';
is chop($int,1), "4", 'chop on Int';
is $int, 42, 'chop() original int unchanged (1)';

# TODO: catch warning, what should be the return value ?
# my $undef_scalar;
# chop($undef_scalar)
is chop("bar"), "ba", "chop() on string literal";
is "bar".chop, "ba", ".chop on string literal";
is chop(""), "", "chop on empty string literal";
is chop("bar","2"), "b", "check coercion of number of characters";

throws_like 'chop(Str)',
X::AdHoc, # temporary, until we have a typed exception
message => "Invocant requires a 'Str' instance, but a type object was passed. Did you forget a .new?";
throws_like 'chop(Str,10)',
X::AdHoc, # temporary, until we have a typed exception
message => "Invocant requires a 'Str' instance, but a type object was passed. Did you forget a .new?";
throws_like 'Str.chop',
X::AdHoc, # temporary, until we have a typed exception
message => "Invocant requires a 'Str' instance, but a type object was passed. Did you forget a .new?";
throws_like 'Str.chop(10)',
X::AdHoc, # temporary, until we have a typed exception
message => "Invocant requires a 'Str' instance, but a type object was passed. Did you forget a .new?";


# See L<"http://use.perl.org/~autrijus/journal/25351">:
Expand Down

0 comments on commit c4328db

Please sign in to comment.