qr/Cannot call length with any arguments/,
'length throws an error when an argument is passed';
- $obj->inc;
+ is( $obj->inc, 'b', 'inc returns new value' );
is( $obj->_string, 'b', 'a becomes b after inc' );
throws_ok { $obj->inc(42) }
qr/Cannot call inc with any arguments/,
'inc throws an error when an argument is passed';
- $obj->append('foo');
+ is( $obj->append('foo'), 'bfoo', 'append returns new value' );
is( $obj->_string, 'bfoo', 'appended to the string' );
throws_ok { $obj->append( 'foo', 2 ) }
'append_curried throws an error when two arguments are passed';
$obj->_string("has nl$/");
- $obj->chomp;
+ is( $obj->chomp, 1, 'chomp returns number of characters removed' );
is( $obj->_string, 'has nl', 'chomped string' );
- $obj->chomp;
+ is( $obj->chomp, 0, 'chomp returns number of characters removed' );
is(
$obj->_string, 'has nl',
'chomp is a no-op when string has no line ending'
qr/Cannot call chomp with any arguments/,
'chomp throws an error when an argument is passed';
- $obj->chop;
+ is( $obj->chop, 'l', 'chop returns character removed' );
is( $obj->_string, 'has n', 'chopped string' );
throws_ok { $obj->chop(42) }
'chop throws an error when an argument is passed';
$obj->_string('x');
- $obj->prepend('bar');
+ is( $obj->prepend('bar'), 'barx', 'prepend returns new value' );
is( $obj->_string, 'barx', 'prepended to string' );
$obj->prepend_curried;
is( $obj->_string, '-barx', 'prepend_curried prepended to string' );
- $obj->replace( qr/([ao])/, sub { uc($1) } );
+ is(
+ $obj->replace( qr/([ao])/, sub { uc($1) } ),
+ '-bArx',
+ 'replace returns new value'
+ );
+
is(
$obj->_string, '-bArx',
'substitution using coderef for replacement'
'substitution using string as replacement'
);
+ $obj->_string('foo');
+ $obj->replace( qr/oo/, q{} );
+
+ is( $obj->_string, 'f',
+ 'replace accepts an empty string as second argument' );
+
+ $obj->replace( q{}, 'a' );
+
+ is( $obj->_string, 'af',
+ 'replace accepts an empty string as first argument' );
+
throws_ok { $obj->replace( {}, 'x' ) }
qr/The first argument passed to replace must be a string or regexp reference/,
'replace throws an error when the first argument is not a string or regexp';
'match -barx against /[aq]/ returns matches'
);
+ is_deeply(
+ [ $obj->match(qr/([az]).*([fy])/) ], [ 'a', 'f' ],
+ 'match -barx against /[aq]/ returns matches'
+ );
+
ok(
scalar $obj->match('b'),
'match with string as argument returns true'
);
+ ok(
+ scalar $obj->match(q{}),
+ 'match with empty string as argument returns true'
+ );
+
throws_ok { $obj->match }
qr/Cannot call match without at least 1 argument/,
'match throws an error when no arguments are passed';
'substr as getter with two arguments'
);
- $obj->substr( 1, 3, 'ong' );
+ is(
+ $obj->substr( 1, 3, 'ong' ),
+ 'ome',
+ 'substr as setter returns replaced string'
+ );
is(
$obj->_string, 'song long string',
'substr as setter with three arguments'
);
+ $obj->substr( 1, 3, '' );
+
+ is(
+ $obj->_string, 's long string',
+ 'substr as setter with three arguments, replacment is empty string'
+ );
+
throws_ok { $obj->substr }
qr/Cannot call substr without at least 1 argument/,
'substr throws an error when no argumemts are passed';
'substr throws an error when first argument is not an integer';
throws_ok { $obj->substr( 1, {} ) }
- qr/The second argument passed to substr must be a positive integer/,
- 'substr throws an error when second argument is not a positive integer';
+ qr/The second argument passed to substr must be an integer/,
+ 'substr throws an error when second argument is not an integer';
throws_ok { $obj->substr( 1, 2, {} ) }
qr/The third argument passed to substr must be a string/,