OSDN Git Service

testFunc_array_joinbranch_leaf()
authorhenoheno <henoheno>
Sat, 9 Jun 2007 03:16:08 +0000 (12:16 +0900)
committerhenoheno <henoheno>
Sat, 9 Jun 2007 03:16:08 +0000 (12:16 +0900)
spam/SpamTest.php
spam/spam.php

index e73721c..f7c2e05 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-// $Id: SpamTest.php,v 1.12 2007/05/11 15:25:36 henoheno Exp $
+// $Id: SpamTest.php,v 1.13 2007/06/09 03:16:08 henoheno Exp $
 // Copyright (C) 2007 heno
 //
 // Design test case for spam.php (called from runner.php)
@@ -301,32 +301,32 @@ EOF;
                $this->assertEquals('', port_normalize('',   $scheme));
 
                // 1st argument: Known port
-               $this->assertEquals('',    port_normalize(-1,   $scheme));
-               $this->assertEquals(0,     port_normalize(0,    $scheme));
-               $this->assertEquals(1,     port_normalize(1,    $scheme));
-               $this->assertEquals('',    port_normalize(  21, 'ftp'));
-               $this->assertEquals('',    port_normalize(  22, 'ssh'));
-               $this->assertEquals('',    port_normalize(  23, 'telnet'));
-               $this->assertEquals('',    port_normalize(  25, 'smtp'));
-               $this->assertEquals('',    port_normalize(  69, 'tftp'));
-               $this->assertEquals('',    port_normalize(  70, 'gopher'));
-               $this->assertEquals('',    port_normalize(  79, 'finger'));
-               $this->assertEquals('',    port_normalize(  80, 'http'));
-               $this->assertEquals('',    port_normalize( 110, 'pop3'));
-               $this->assertEquals('',    port_normalize( 115, 'sftp'));
-               $this->assertEquals('',    port_normalize( 119, 'nntp'));
-               $this->assertEquals('',    port_normalize( 143, 'imap'));
-               $this->assertEquals('',    port_normalize( 194, 'irc'));
-               $this->assertEquals('',    port_normalize( 210, 'wais'));
-               $this->assertEquals('',    port_normalize( 443, 'https'));
-               $this->assertEquals('',    port_normalize( 563, 'nntps'));
-               $this->assertEquals('',    port_normalize( 873, 'rsync'));
-               $this->assertEquals('',    port_normalize( 990, 'ftps'));
-               $this->assertEquals('',    port_normalize( 992, 'telnets'));
-               $this->assertEquals('',    port_normalize( 993, 'imaps'));
-               $this->assertEquals('',    port_normalize( 994, 'ircs'));
-               $this->assertEquals('',    port_normalize( 995, 'pop3s'));
-               $this->assertEquals('',    port_normalize(3306, 'mysql'));
+               $this->assertEquals('',    port_normalize(   -1, $scheme));
+               $this->assertEquals(0,     port_normalize(    0, $scheme));
+               $this->assertEquals(1,     port_normalize(    1, $scheme));
+               $this->assertEquals('',    port_normalize(   21, 'ftp'));
+               $this->assertEquals('',    port_normalize(   22, 'ssh'));
+               $this->assertEquals('',    port_normalize(   23, 'telnet'));
+               $this->assertEquals('',    port_normalize(   25, 'smtp'));
+               $this->assertEquals('',    port_normalize(   69, 'tftp'));
+               $this->assertEquals('',    port_normalize(   70, 'gopher'));
+               $this->assertEquals('',    port_normalize(   79, 'finger'));
+               $this->assertEquals('',    port_normalize(   80, 'http'));
+               $this->assertEquals('',    port_normalize(  110, 'pop3'));
+               $this->assertEquals('',    port_normalize(  115, 'sftp'));
+               $this->assertEquals('',    port_normalize(  119, 'nntp'));
+               $this->assertEquals('',    port_normalize(  143, 'imap'));
+               $this->assertEquals('',    port_normalize(  194, 'irc'));
+               $this->assertEquals('',    port_normalize(  210, 'wais'));
+               $this->assertEquals('',    port_normalize(  443, 'https'));
+               $this->assertEquals('',    port_normalize(  563, 'nntps'));
+               $this->assertEquals('',    port_normalize(  873, 'rsync'));
+               $this->assertEquals('',    port_normalize(  990, 'ftps'));
+               $this->assertEquals('',    port_normalize(  992, 'telnets'));
+               $this->assertEquals('',    port_normalize(  993, 'imaps'));
+               $this->assertEquals('',    port_normalize(  994, 'ircs'));
+               $this->assertEquals('',    port_normalize(  995, 'pop3s'));
+               $this->assertEquals('',    port_normalize( 3306, 'mysql'));
                $this->assertEquals(8080,  port_normalize( 8080, $scheme));
                $this->assertEquals(65535, port_normalize(65535, $scheme));
                $this->assertEquals(65536, port_normalize(65536, $scheme)); // Seems not invalid in RFC
@@ -530,6 +530,63 @@ EOF;
                $array = get_blocklist('goodhost');
                $this->assertTrue(isset($array['IANA-examples']));
        }
+
+
+       function testFunc_array_joinbranch_leaf()
+       {
+               // 1st argument: Null
+               foreach($this->setup_string_null() as $value){
+                       $array = $value;
+                       $result = array_joinbranch_leaf($array);
+                       $this->assertEquals(array(), $result);
+                       $this->assertEquals($value, $array);
+               }
+
+               // Null
+               $array = array(array());
+               $result = array_joinbranch_leaf($array);
+               $this->assertEquals(array(), $result);
+               $this->assertEquals(array(array()), $array);
+
+               $a = array('F' => array('B' => array('C' => array('d' => array('' => 'foobar')))));
+               $b = array('R' => array('S' => array('T' => array('U' => 'hoge' ))));
+
+               // Single case
+               $array = $a;
+               $result = array_joinbranch_leaf($array);
+               $this->assertEquals(array('F.B.C.d.' => 5       ), $result);
+               $this->assertEquals(array('F.B.C.d.' => 'foobar'), $array);
+
+               // Single, delim = '', limit
+               $array = $a;
+               $result = array_joinbranch_leaf($array, '', 2);
+               $this->assertEquals(array('FBC' => 3), $result);
+               $this->assertEquals(array('FBC' => array('d' => array('' => 'foobar'))), $array);
+
+               // Single, delim = '#', reverse
+               $array = $a;
+               $result = array_joinbranch_leaf($array, '#', 0, TRUE);
+               $this->assertEquals(array('#d#C#B#F' => 5       ), $result);
+               $this->assertEquals(array('#d#C#B#F' => 'foobar'), $array);
+
+               // Multiple case
+               $array = array('I' => $a, '@' => $b);
+               $result = array_joinbranch_leaf($array);
+               $this->assertEquals(
+                       array(
+                               '@.R.S.T.U'  => 5,
+                               'I.F.B.C.d.' => 6
+                       ),
+                       $result
+               );
+               $this->assertEquals(
+                       array(
+                               '@.R.S.T.U'  => 'hoge',
+                               'I.F.B.C.d.' => 'foobar'
+                       ),
+                       $array
+               );
+       }
 }
 
 ?>
index 5576228..00028bc 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-// $Id: spam.php,v 1.170 2007/06/09 02:22:13 henoheno Exp $
+// $Id: spam.php,v 1.171 2007/06/09 03:16:08 henoheno Exp $
 // Copyright (C) 2006-2007 PukiWiki Developers Team
 // License: GPL v2 or (at your option) any later version
 //
@@ -1526,11 +1526,12 @@ function summarize_detail_newtral($progress = array())
        return $result;
 }
 
-
+// array('F' => array('B' => array('C' => array('d' => array('' => 'foobar')))))
+// to
+// array('F.B.C.d.' => 'foobar')
 function array_joinbranch_leaf(& $array, $delim = '.', $limit = 0, $reverse = FALSE)
 {
        $result = array();
-
        if (! is_array($array)) return $result; // Nothing to do
 
        $limit  = max(0, intval($limit));
@@ -1562,16 +1563,6 @@ function array_joinbranch_leaf(& $array, $delim = '.', $limit = 0, $reverse = FA
 
        return $result;
 }
-//$a = array(array()); //=> array()
-//$a = array('F' => array('B' => array('C' => array('d' => array('' => '6')))));
-//$b = array('R' => array('S' => array('T' => array('U' => array('' => '7')))));
-//$a = array('I' => $a, '@' => $b);
-//$a = array('F' => array(5), 0 => array('H'));
-//echo "<br>";
-//var_dump(array_joinbranch_leaf($a, '#', 0, 0));
-//var_export($a);
-//echo "<br>";
-//echo "<br>";
 
 
 // array('A' => array('B' => 'C')) to