<commit_before><?php

declare(strict_types=1);

namespace WRS;

use PHPUnit\Framework\TestCase;

class ConfigTest extends TestCase
{
    const KEY = "test";
    const VALUE_STRING = "value";
    const VALUE_INT = 42;

    public function providerStringToIntValid() {
        $data = array(
            "zero" => ["0", 0],
            "zero minus" => ["-0", 0],
            "five minus" => ["-5", -5],
            "five" => ["5", 5],
            "int max 32 bits" => [ "2147483647",  2147483647],
            "int min 32 bits" => ["-2147483648", -2147483648],
        );
        if (PHP_INT_SIZE === 8) {
            $data = array_merge($data, array(
                "int max 64 bits" => [ "9223372036854775807",  9223372036854775807],
                "int min 64 bits" => ["-9223372036854775808", -9223372036854775808],
            ));
        }
        return $data;
    }

    /**
     * @dataProvider providerStringToIntValid
     */
    public function testStringToIntSuccess(string $input, int $expected) {
        $value = Config::StringToInt($input);
        $this->assertSame($expected, $value);
    }

    public function providerStringToIntInvalid() {
        $data = array(
            "zero" => ["+0", 1],
            "text" => ["text", 1],
            "mixed" => ["36mix", 1],
            "non-trimmed" => [" \t 6    \t", 1],
        );
        return $data;
    }

    /**
     * @dataProvider      providerStringToIntInvalid
     * @expectedException Exception
     */
    public function testStringToIntFail(string $input, int $expected) {
        $value = Config::StringToInt($input);
        $this->assertSame($expected, $value);
    }

    public function testHasKey() {
        $config = new Config(new NullStorage());
        $this->assertFalse($config->has_key(self::KEY), "key should not exist");
        $config->set_integer(self::KEY, self::VALUE_INT);<commit_msg>more robust exception checking<commit_after><?php

declare(strict_types=1);

namespace WRS;

use PHPUnit\Framework\TestCase;

class ConfigTest extends TestCase
{
    const KEY = "test";
    const VALUE_STRING = "value";
    const VALUE_INT = 42;

    public function providerStringToIntValid() {
        $data = array(
            "zero" => ["0", 0],
            "zero minus" => ["-0", 0],
            "five minus" => ["-5", -5],
            "five" => ["5", 5],
            "int max 32 bits" => [ "2147483647",  2147483647],
            "int min 32 bits" => ["-2147483648", -2147483648],
        );
        if (PHP_INT_SIZE === 8) {
            $data = array_merge($data, array(
                "int max 64 bits" => [ "9223372036854775807",  9223372036854775807],
                "int min 64 bits" => ["-9223372036854775808", -9223372036854775808],
            ));
        }
        return $data;
    }

    /**
     * @dataProvider providerStringToIntValid
     */
    public function testStringToIntSuccess(string $input, int $expected) {
        $value = Config::StringToInt($input);
        $this->assertSame($expected, $value);
    }

    public function providerStringToIntInvalid() {
        $data = array(
            "zero" => ["+0", 1],
            "text" => ["text", 1],
            "mixed" => ["36mix", 1],
            "non-trimmed" => [" \t 6    \t", 1],
        );
        return $data;
    }

    /**
     * @dataProvider             providerStringToIntInvalid
     * @expectedException        Exception
     * @expectedExceptionMessage Invalid integer
     */
    public function testStringToIntFail(string $input, int $expected) {
        $value = Config::StringToInt($input);
        $this->assertSame($expected, $value);
    }

    public function testHasKey() {
        $config = new Config(new NullStorage());
        $this->assertFalse($config->has_key(self::KEY), "key should not exist");
        $config->set_integer(self::KEY, self::VALUE_INT);
{'fraction_non_alphanumeric': 0.15292897874546396, 'fraction_numerical': 0.07465007776049767, 'mean_word_length': 2.1761316872427985, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, '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': '5482149', 'n_tokens_mistral': 1362, 'n_tokens_neox': 1181, 'n_words': 267}