toString() public static method

$diff - the diff array $separator - the separator between lines; this optional parameter defaults to "\n"
public static toString ( $diff, $separator = " " )
Beispiel #1
0
<?php

require_once "diff_class.php";
$microstart = explode(' ', microtime());
$start_time = $microstart[0] + $microstart[1];
echo Diff::toString(Diff::compareFiles('old_char_346.xml', 'char_346.xml', false));
$microstop = explode(' ', microtime());
$stop_time = $microstop[0] + $microstop[1];
echo "Expired time: " . ($stop_time - $start_time) . "<br>";
echo "Memory load: " . memory_get_usage() . " bytes";
Beispiel #2
0
function get_test_result($name, $verbose = false, $moreVerbose = false)
{
    $mergeSpace = IGNORE_INDENT && strpos($name, 'indent.') === false;
    $path = TEMPLATES_DIRECTORY . DIRECTORY_SEPARATOR . $name;
    $expectedHtml = @file_get_contents($path . '.html');
    if ($expectedHtml === false) {
        if ($verbose) {
            echo "! sample for test '{$name}' not found.\n";
        }
        return array(false, array($name, null, "! sample for test '{$name}' not found.\n"));
    }
    if ($verbose) {
        echo "* rendering test '{$name}'\n";
    }
    try {
        $new = get_php_code($path . '.jade');
    } catch (Exception $err) {
        if ($verbose) {
            echo "! FATAL: php exception: " . str_replace("\n", "\n\t", $err) . "\n";
        }
        return array(false, array($name, null, "! FATAL: php exception: " . str_replace("\n", "\n\t", $err) . "\n"));
    }
    if (is_null($new)) {
        return array(false, array($name, null, "! FATAL: " . $path . ".jade returns null\n"));
    }
    $actualHtml = get_generated_html($new);
    $from = array("'", "\r", "<!DOCTYPEhtml>");
    $to = array('"', '', '');
    if ($mergeSpace) {
        array_push($from, "\n", "\t", " ");
        array_push($to, '', '', '');
    }
    $expectedHtml = preg_replace_callback('`class\\s*=\\s*(["\'])([^"\']+)\\1`', 'orderWords', $expectedHtml);
    $actualHtml = preg_replace_callback('`class\\s*=\\s*(["\'])([^"\']+)\\1`', 'orderWords', $actualHtml);
    if ($mergeSpace) {
        $expectedHtml = preg_replace('`(?<=[\'"])\\s(?=>)|(?<=[a-zA-Z0-9:])\\s(?=(>|\\s[a-zA-Z0-9:]))`', '', $expectedHtml);
        $actualHtml = preg_replace('`(?<=[\'"])\\s(?=>)|(?<=[a-zA-Z0-9:])\\s(?=(>|\\s[a-zA-Z0-9:]))`', '', $actualHtml);
    }
    $minifiedExpectedHtml = str_replace($from, $to, trim($expectedHtml));
    $minifiedActualHtml = str_replace($from, $to, trim($actualHtml));
    $result = array($name, $minifiedExpectedHtml, $minifiedActualHtml);
    if (strcmp($minifiedExpectedHtml, $minifiedActualHtml)) {
        if ($verbose) {
            include_once __DIR__ . '/diff.php';
            $actualHtml = preg_replace('`(\\r\\n|\\r|\\n)([\\t ]*(\\r\\n|\\r|\\n))+`', "\n", $actualHtml);
            $expectedHtml = preg_replace('`(\\r\\n|\\r|\\n)([\\t ]*(\\r\\n|\\r|\\n))+`', "\n", $expectedHtml);
            echo Diff::toString(Diff::compare($expectedHtml, $actualHtml)) . "\n";
            /*
            echo "  Expected: $expectedHtml\n";
            echo "  Actual  : $actualHtml\n\n";
            */
        }
        if ($moreVerbose) {
            echo "  PHP     : " . compile_php($name);
        }
        return array(false, $result);
    }
    return array(true, $result);
}
Beispiel #3
0
                                 echo 'program could not check the code whether correct or not' . PHP_EOL;
                             }
                             echo "-----------------Diff show me the differ : ------------------\n";
                             $originalOPTB_WOCFile = ORIGIN_FILE_PATH . $path_parts['filename'] . '-objectcode.txt';
                             if (file_exists($originalOPTB_WOCFile)) {
                                 $diffOPTB_WOC = Diff::compareFiles($originalOPTB_WOCFile, $OPTB_WOCtxtFile);
                                 echo Diff::toString($diffOPTB_WOC);
                                 create_file(RESULT_PATH . $OUTPUT_LOG_PREFIX . "diff-OPTB_WOC.html", Diff::toHTML($diffOPTB_WOC));
                                 echo "\n";
                             } else {
                                 echo $originalOPTB_WOCFile . "\n" . 'do not exist' . "\n";
                             }
                             $orignalObjectPFile = ORIGIN_FILE_PATH . $path_parts['filename'] . '-objectprogram.txt';
                             if (file_exists($orignalObjectPFile)) {
                                 $diffObjectP = Diff::compareFiles($orignalObjectPFile, $obectProgramTxtFile);
                                 echo Diff::toString($diffObjectP);
                                 create_file(RESULT_PATH . $OUTPUT_LOG_PREFIX . "diff-ObjectProgram.html", Diff::toHTML($diffObjectP));
                                 echo "\n";
                             } else {
                                 echo $orignalObjectPFile . "\n" . 'do not exist' . "\n";
                             }
                             echo "-------------------------Diff end ----------------------------\n";
                             compare_array_in_html_js(RESULT_PATH . $OUTPUT_LOG_PREFIX . "compare_html_js.html", $OPTB_WOC, $orignalCode, "Compare Array", false);
                         }
                         ## end ## print out OPTB
                     }
                 }
             }
         }
     }
 }