Example #1
0
 public function invoke($test)
 {
     //echo get_class($this) . ': ' . $test->description ."\n";
     if (!isset($test->contentModelFlags)) {
         $test->contentModelFlags = array('PCDATA');
     }
     if (!isset($test->ignoreErrorOrder)) {
         $test->ignoreErrorOrder = false;
     }
     // Get expected result array (and maybe error count).
     $expect = array();
     $expectedErrorCount = 0;
     // This is only used when ignoreErrorOrder = true.
     foreach ($test->output as $tok) {
         // If we're ignoring error order and this is a parse error, just count.
         if ($test->ignoreErrorOrder && $tok === 'ParseError') {
             $expectedErrorCount++;
         } else {
             // Normalize character tokens from the test
             if ($expect && $tok[0] === 'Character' && $expect[count($expect) - 1][0] === 'Character') {
                 $expect[count($expect) - 1][1] .= $tok[1];
             } else {
                 $expect[] = $tok;
             }
         }
     }
     // Run test for each content model flag.
     foreach ($test->contentModelFlags as $flag) {
         $output = $this->tokenize($test, $flag);
         $result = array();
         $resultErrorCount = 0;
         // This is only used when ignoreErrorOrder = true.
         foreach ($output as $tok) {
             // If we're ignoring error order and this is a parse error, just count.
             if ($test->ignoreErrorOrder && $tok === 'ParseError') {
                 $resultErrorCount++;
             } else {
                 $result[] = $tok;
             }
         }
         $this->assertIdentical($expect, $result, 'In test "' . str_replace('%', '%%', $test->description) . '" with content model ' . $flag . ': %s');
         if ($test->ignoreErrorOrder) {
             $this->assertIdentical($expectedErrorCount, $resultErrorCount, 'Wrong error count in test "' . str_replace('%', '%%', $test->description) . '" with content model ' . $flag . ': %s');
         }
         if ($expect != $result || $test->ignoreErrorOrder && $expectedErrorCount !== $resultErrorCount) {
             echo "Input: ";
             str_dump($test->input);
             echo "\nExpected: \n";
             echo $this->tokenDump($expect);
             echo "\nActual: \n";
             echo $this->tokenDump($result);
             echo "\n";
         }
     }
 }
Example #2
0
<?php

/* Prototype  : int strnatcasecmp(string s1, string s2)
 * Description: Returns the result of case-insensitive string comparison using 'natural' algorithm 
 * Source code: ext/standard/string.c
 * Alias to functions: 
 */
function str_dump($one, $two)
{
    var_dump(strnatcasecmp($one, $two));
}
echo "*** Testing strnatcasecmp() : basic functionality ***\n";
// Calling strnatcasecmp() with all possible arguments
str_dump('A', 'a');
str_dump('a10', 'A20');
str_dump('A1b', 'a');
str_dump('x2-y7', 'x8-y8');
str_dump('1.010', '1.001');
str_dump(' ab', ' aB');
str_dump('acc ', 'acc');
str_dump(11.5, 10.5);
str_dump(10.5, 105.0);
str_dump('Rfc822.txt', 'rfc2086.txt');
str_dump('Rfc822.txt', 'rfc822.TXT');
str_dump('pIc 6', 'pic   7');
str_dump(0xfff, 0xfff);
?>
===DONE===
/* Preparation */
class a
{
    function __toString()
    {
        return "Hello WORLD";
    }
}
class b
{
    function __toString()
    {
        return "HELLO world";
    }
}
$a = new a();
$b = new b();
function str_dump($a, $b)
{
    var_dump(strnatcasecmp($a, $b));
}
echo "*** Testing strnatcasecmp() : variation ***\n";
str_dump('0', false);
str_dump('fooBar', '');
str_dump('', -1);
str_dump("Helloworld", "Helloworld");
str_dump("", "");
str_dump($a, $b);
?>
===DONE===