<commit_before><?php

require_once '_inc.php';

require_once 'CSSmin.php';

function test_CSSmin()
{
    $files = glob(dirname(__FILE__) . '/_test_files/yuic/*.css');

    // @todo determine why these crash. memroy exhaustion?
    $skip = array(
        //'dataurl-base64-doublequotes.css',
        //'dataurl-base64-noquotes.css',
        //'dataurl-base64-singlequotes.css',
    );

    foreach ($files as $file) {
        if (!empty($skip) && in_array(basename($file), $skip)) {
            echo "INFO: CSSmin: skipping " . basename($file) . "\n";
            continue;
        }

        $cssmin = new CSSmin();

        $src = file_get_contents($file);
        $minExpected = trim(file_get_contents($file . '.min'));
        $minOutput = trim($cssmin->run($src));
        
        $passed = assertTrue($minExpected == $minOutput, 'CSSmin : ' . basename($file));
        if (! $passed && __FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
            echo "\n---Output: " .countBytes($minOutput). " bytes\n\n{$minOutput}\n\n";
            echo "---Expected: " .countBytes($minExpected). " bytes\n\n{$minExpected}\n\n";
            echo "---Source: " .countBytes($src). " bytes\n\n{$src}\n\n\n";
        }
        

    }
}

test_CSSmin();<commit_msg>minor unit test tweaks<commit_after><?php

require_once '_inc.php';

require_once 'CSSmin.php';

function test_CSSmin()
{
    $files = glob(dirname(__FILE__) . '/_test_files/yuic/*.css');

    // some tests may exhaust memory/stack due to string size/PCRE
    $skip = array(
        //'dataurl-base64-doublequotes.css',
        //'dataurl-base64-noquotes.css',
        //'dataurl-base64-singlequotes.css',
    );

    foreach ($files as $file) {
        if (! empty($skip) && in_array(basename($file), $skip)) {
            echo "INFO: CSSmin: skipping " . basename($file) . "\n";
            continue;
        }

        $cssmin = new CSSmin();

        $src = file_get_contents($file);
        $minExpected = trim(file_get_contents($file . '.min'));
        $minOutput = trim($cssmin->run($src));
        
        $passed = assertTrue($minExpected == $minOutput, 'CSSmin : ' . basename($file));
        if (! $passed && __FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
            echo "\n---Output: " .countBytes($minOutput). " bytes\n\n{$minOutput}\n\n";
            echo "---Expected: " .countBytes($minExpected). " bytes\n\n{$minExpected}\n\n";
            echo "---Source: " .countBytes($src). " bytes\n\n{$src}\n\n\n";
        }
    }
}

test_CSSmin();
{'fraction_non_alphanumeric': 0.18992862807295796, 'fraction_numerical': 0.004758128469468675, 'mean_word_length': 2.4002695417789757, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4015392', 'n_tokens_mistral': 852, 'n_tokens_neox': 826, 'n_words': 142}