<commit_before><?php

namespace Silktide\Reposition\Tests\QueryBuilder;

use Silktide\Reposition\QueryBuilder\TokenParser;
use Silktide\Reposition\Exception\TokenDefinitionException;
use Silktide\Reposition\Exception\TokenParseException;

class TokenParserTest extends \PHPUnit_Framework_TestCase {

    /**
     * @dataProvider invalidDefinitionProvider
     *
     * @param array $definition
     * @param string $errorPartial
     */
    public function testInvalidDefinitions(array $definition, $errorPartial = "")
    {
        $parser = new TokenParser();
        try {
            $parser->addDefinition("test", $definition);
            $this->fail("Should not be able to add an invalid definition");
        } catch (TokenDefinitionException $e) {
            if (!empty($errorPartial)) {
                $this->assertContains($errorPartial, $e->getMessage());
            }
        }
    }

    public function invalidDefinitionProvider()
    {
        return [
            [ // empty list
                []
            ],
            [ // not a list of defintions
                ["one", "two", "three"]
            ],
            [ // empty definition
                [[]]
            ],
            [ // unknown constraint
                [["blah" => "blah"]]
            ],
            [ // invalid type
                [["optional" => "blah"]],
                "optional"
            ],
            [ // invalid multiple
                [["multiple" => "blah"]],
                "multiple"
            ],
            [ // invalid type
                [["type" => 1]],<commit_msg>fix token parser test - string values for "optional" are allowed<commit_after><?php

namespace Silktide\Reposition\Tests\QueryBuilder;

use Silktide\Reposition\QueryBuilder\TokenParser;
use Silktide\Reposition\Exception\TokenDefinitionException;
use Silktide\Reposition\Exception\TokenParseException;

class TokenParserTest extends \PHPUnit_Framework_TestCase {

    /**
     * @dataProvider invalidDefinitionProvider
     *
     * @param array $definition
     * @param string $errorPartial
     */
    public function testInvalidDefinitions(array $definition, $errorPartial = "")
    {
        $parser = new TokenParser();
        try {
            $parser->addDefinition("test", $definition);
            $this->fail("Should not be able to add an invalid definition");
        } catch (TokenDefinitionException $e) {
            if (!empty($errorPartial)) {
                $this->assertContains($errorPartial, $e->getMessage());
            }
        }
    }

    public function invalidDefinitionProvider()
    {
        return [
            [ // empty list
                []
            ],
            [ // not a list of defintions
                ["one", "two", "three"]
            ],
            [ // empty definition
                [[]]
            ],
            [ // unknown constraint
                [["blah" => "blah"]]
            ],
            [ // invalid optional
                [["optional" => 123]],
                "optional"
            ],
            [ // invalid multiple
                [["multiple" => "blah"]],
                "multiple"
            ],
            [ // invalid type
                [["type" => 1]],
{'fraction_non_alphanumeric': 0.12122146822948797, 'fraction_numerical': 0.0015422578655151142, 'mean_word_length': 1.5985576923076923, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4723863', 'n_tokens_mistral': 819, 'n_tokens_neox': 783, 'n_words': 172}