<commit_before><?php

function setup_autoload() {
    // quick setup for autoloading
    $path = str_replace('/', DIRECTORY_SEPARATOR, __DIR__ . '/../');
    $path = realpath($path);
    set_include_path(get_include_path() . PATH_SEPARATOR . $path);

    spl_autoload_register(function ($class) {
        $file = __DIR__ . '/../src/' . str_replace("\\", DIRECTORY_SEPARATOR, $class) . '.php';
        if(file_exists($file)) {
            require_once($file);
        }
    });
}

function find_tests() {
    // find the tests
    $path = str_replace('/', DIRECTORY_SEPARATOR, __DIR__ . '/');
    $path = realpath($path);
    return glob($path . DIRECTORY_SEPARATOR . '*.jade');
}

function build_list($test_list) {
    $group_list = array();
    foreach ($test_list as $test) {
        $name = basename($test, '.jade');
        $parts = preg_split('/[.-]/', $name);

        if (!isset($group_list[$parts[0]])) {
            $group_list[$parts[0]] = array();
        }
        $group_list[$parts[0]][] = array('link' => $test, 'name' => $name);
    }

    return $group_list;
}

function get_php_code($file) {
    $jade = new \Jade\Jade(array(
        'prettyprint' => true
    ));
    return $jade->render($file);
}

function compile_php($file) {
    $jade = new Jade\Jade(array(
        'prettyprint' => true
    ));
    return $jade->compile(file_get_contents($file . '.jade'));
}

function init_tests() {
    mb_internal_encoding('utf-8');
    error_reporting(E_ALL);
    setup_autoload();
}

function get_generated_html($contents) {
    if(ini_get('allow_url_include') | 0) {
        error_reporting(E_ALL & ~E_NOTICE);
        ob_start();
        include "data://text/plain;base64," . base64_encode($contents);
        $contents = ob_get_contents();
        ob_end_clean();
        error_reporting(E_ALL);
    } else {
        $file = tempnam(sys_get_temp_dir(), 'jade');
        file_put_contents($file, $contents);
        $contents = `php -d error_reporting="E_ALL & ~E_NOTICE" {$file}`;
        unlink($file);
    }
    return $contents;
}

function get_test_result($name, $verbose = false, $moreVerbose = false) {
    $path = __DIR__ . DIRECTORY_SEPARATOR . $name;
    $expectedHtml = @file_get_contents($path . '.html');
    if($expectedHtml === FALSE) {
        if($verbose) {
            echo "! sample for test '$name' not found.\n";
        }
        return;
    }

    if($verbose) {
        echo "* rendering test '$name'\n";
    }
    try {
        $new = show_php($path . '.jade');
    } catch(Exception $err) {
        if($verbose) {
            echo "! FATAL: php exception: ".str_replace("\n", "\n\t", $err)."\n";
        }
        $new = null;
    }

    if($new !== null) {
        $actualHtml = get_generated_html($new);

        $from = array("\n", "\r", "\t", " ", '"', "<!DOCTYPEhtml>");
        $to = array('', '', '', '', "'", '');
        $minifiedExpectedHtml = str_replace($from, $to, $expectedHtml);
        $minifiedActualHtml = str_replace($from, $to, $actualHtml);
        $result = array($name, $minifiedExpectedHtml, $minifiedActualHtml);

        if(strcmp($minifiedExpectedHtml, $minifiedActualHtml)) {
            if($verbose) {
                echo "  Expected: $expectedHtml\n";
                echo "  Actual  : $actualHtml\n\n";
            }
            if($moreVerbose) {
                echo "  PHP     : " . compile_php($name);
            }
            return array(false, $result);
        }

        return array(true, $result);
    }
}

function get_tests_results($verbose = false) {
    global $argv;

    if($moreVerbose = in_array('--verbose', $argv)) {
        array_splice($argv, array_search('--verbose', $argv), 1);
    }

    if(! (ini_get('allow_url_include') | 0)) {
        echo "To accelerate the test execution, set in php.ini :\nallow_url_include = On\n\n";
    }

    $nav_list = build_list(find_tests());

    $success = 0;
    $failures = 0;
    $results = array();

    foreach($nav_list as $type => $arr) {
        foreach($arr as $e) {
            $name = $e['name'];

            if($name == 'index' || (
                isset($argv[1]) &&
                false === stripos($argv[0], 'phpunit') &&
                $name != $argv[1] &&
                $argv[1] != '.'
            )) {
                continue;
            }<commit_msg>Strict comparaisons<commit_after><?php

function setup_autoload() {
    // quick setup for autoloading
    $path = str_replace('/', DIRECTORY_SEPARATOR, __DIR__ . '/../');
    $path = realpath($path);
    set_include_path(get_include_path() . PATH_SEPARATOR . $path);

    spl_autoload_register(function ($class) {
        $file = __DIR__ . '/../src/' . str_replace("\\", DIRECTORY_SEPARATOR, $class) . '.php';
        if(file_exists($file)) {
            require_once($file);
        }
    });
}

function find_tests() {
    // find the tests
    $path = str_replace('/', DIRECTORY_SEPARATOR, __DIR__ . '/');
    $path = realpath($path);
    return glob($path . DIRECTORY_SEPARATOR . '*.jade');
}

function build_list($test_list) {
    $group_list = array();
    foreach ($test_list as $test) {
        $name = basename($test, '.jade');
        $parts = preg_split('/[.-]/', $name);

        if (!isset($group_list[$parts[0]])) {
            $group_list[$parts[0]] = array();
        }
        $group_list[$parts[0]][] = array('link' => $test, 'name' => $name);
    }

    return $group_list;
}

function get_php_code($file) {
    $jade = new \Jade\Jade(array(
        'prettyprint' => true
    ));
    return $jade->render($file);
}

function compile_php($file) {
    $jade = new Jade\Jade(array(
        'prettyprint' => true
    ));
    return $jade->compile(file_get_contents($file . '.jade'));
}

function init_tests() {
    mb_internal_encoding('utf-8');
    error_reporting(E_ALL);
    setup_autoload();
}

function get_generated_html($contents) {
    if(intval(ini_get('allow_url_include')) !== 0) {
        error_reporting(E_ALL & ~E_NOTICE);
        ob_start();
        include "data://text/plain;base64," . base64_encode($contents);
        $contents = ob_get_contents();
        ob_end_clean();
        error_reporting(E_ALL);
    } else {
        $file = tempnam(sys_get_temp_dir(), 'jade');
        file_put_contents($file, $contents);
        $contents = `php -d error_reporting="E_ALL & ~E_NOTICE" {$file}`;
        unlink($file);
    }
    return $contents;
}

function get_test_result($name, $verbose = false, $moreVerbose = false) {
    $path = __DIR__ . DIRECTORY_SEPARATOR . $name;
    $expectedHtml = @file_get_contents($path . '.html');
    if($expectedHtml === FALSE) {
        if($verbose) {
            echo "! sample for test '$name' not found.\n";
        }
        return;
    }

    if($verbose) {
        echo "* rendering test '$name'\n";
    }
    try {
        $new = show_php($path . '.jade');
    } catch(Exception $err) {
        if($verbose) {
            echo "! FATAL: php exception: ".str_replace("\n", "\n\t", $err)."\n";
        }
        $new = null;
    }

    if($new !== null) {
        $actualHtml = get_generated_html($new);

        $from = array("\n", "\r", "\t", " ", '"', "<!DOCTYPEhtml>");
        $to = array('', '', '', '', "'", '');
        $minifiedExpectedHtml = str_replace($from, $to, $expectedHtml);
        $minifiedActualHtml = str_replace($from, $to, $actualHtml);
        $result = array($name, $minifiedExpectedHtml, $minifiedActualHtml);

        if(strcmp($minifiedExpectedHtml, $minifiedActualHtml)) {
            if($verbose) {
                echo "  Expected: $expectedHtml\n";
                echo "  Actual  : $actualHtml\n\n";
            }
            if($moreVerbose) {
                echo "  PHP     : " . compile_php($name);
            }
            return array(false, $result);
        }

        return array(true, $result);
    }
}

function get_tests_results($verbose = false) {
    global $argv;

    if($moreVerbose = in_array('--verbose', $argv)) {
        array_splice($argv, array_search('--verbose', $argv), 1);
    }

    if(! (ini_get('allow_url_include') | 0)) {
        echo "To accelerate the test execution, set in php.ini :\nallow_url_include = On\n\n";
    }

    $nav_list = build_list(find_tests());

    $success = 0;
    $failures = 0;
    $results = array();

    foreach($nav_list as $type => $arr) {
        foreach($arr as $e) {
            $name = $e['name'];

            if($name == 'index' || (
                isset($argv[1]) &&
                false === stripos($argv[0], 'phpunit') &&
                $name !== $argv[1] &&
                $argv[1] !== '.'
            )) {
                continue;
            }
{'fraction_non_alphanumeric': 0.1789351851851852, 'fraction_numerical': 0.003935185185185185, 'mean_word_length': 2.278072837632777, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7016385', 'n_tokens_mistral': 2920, 'n_tokens_neox': 2826, 'n_words': 521}