Revert most of the conversion to Test::Fatal so we can redo it
[gitmo/Moose.git] / t / 070_native_traits / 070_trait_string.t
index d3029b7..c6b9c63 100644 (file)
@@ -96,14 +96,14 @@ sub run_tests {
         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 ) }
@@ -118,10 +118,10 @@ sub run_tests {
             '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'
@@ -131,7 +131,7 @@ sub run_tests {
         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) }
@@ -139,13 +139,18 @@ sub run_tests {
             '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'
@@ -157,6 +162,17 @@ sub run_tests {
             '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';
@@ -176,11 +192,21 @@ sub run_tests {
             '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';
@@ -214,13 +240,24 @@ sub run_tests {
             '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';