<commit_before><?php

namespace spec\PHPeg\Generator;

use PHPeg\Combinator\Grammar;
use PHPeg\Generator\ToCombinatorVisitor;
use PHPeg\Grammar\BinaryRuleFactory;
use PHPeg\Grammar\GrammarRuleFactory;
use PHPeg\Grammar\Parser;
use PHPeg\Grammar\ParserFactory;
use PHPeg\Grammar\TerminalRuleFactory;
use PHPeg\Grammar\UnaryRuleFactory;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

class ParserGeneratorSpec extends ObjectBehavior
{
    function let()
    {
        $this->beConstructedWith(new ParserFactory(
            new TerminalRuleFactory(),
            new UnaryRuleFactory(),
            new BinaryRuleFactory(),
            new GrammarRuleFactory()
        ));
    }

    function it_should_generate_a_parser()
    {
        $this->createParser(__DIR__ . '/PHPeg.peg')->shouldHaveType('PHPeg\ParserInterface');
    }

    function it_should_generate_a_parser_that_parses_its_own_definition()
    {
        $contents = file_get_contents(__DIR__ . '/PHPeg.peg');

        $this->createParser(__DIR__ . '/PHPeg.peg')->parse($contents)->shouldHaveType('PHPeg\Grammar\Tree\GrammarNode');
    }

    function it_should_generate_a_parser_that_when_parsing_its_own_definition_results_in_the_same_parser()
    {
        $contents = file_get_contents(__DIR__ . '/PHPeg.peg');<commit_msg>Skip the parser parser check for benchmarking<commit_after><?php

namespace spec\PHPeg\Generator;

use PHPeg\Combinator\Grammar;
use PHPeg\Generator\ToCombinatorVisitor;
use PHPeg\Grammar\BinaryRuleFactory;
use PHPeg\Grammar\GrammarRuleFactory;
use PHPeg\Grammar\Parser;
use PHPeg\Grammar\ParserFactory;
use PHPeg\Grammar\TerminalRuleFactory;
use PHPeg\Grammar\UnaryRuleFactory;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

class ParserGeneratorSpec extends ObjectBehavior
{
    function let()
    {
        $this->beConstructedWith(new ParserFactory(
            new TerminalRuleFactory(),
            new UnaryRuleFactory(),
            new BinaryRuleFactory(),
            new GrammarRuleFactory()
        ));
    }

    function it_should_generate_a_parser()
    {
        $this->createParser(__DIR__ . '/PHPeg.peg')->shouldHaveType('PHPeg\ParserInterface');
    }

    function it_should_generate_a_parser_that_parses_its_own_definition()
    {
        $contents = file_get_contents(__DIR__ . '/PHPeg.peg');

        $this->createParser(__DIR__ . '/PHPeg.peg')->parse($contents)->shouldHaveType('PHPeg\Grammar\Tree\GrammarNode');
    }

    function it_should_generate_a_parser_that_when_parsing_its_own_definition_results_in_the_same_parser()
    {
        return;

        $contents = file_get_contents(__DIR__ . '/PHPeg.peg');
{'fraction_non_alphanumeric': 0.10216483099126472, 'fraction_numerical': 0.0, 'mean_word_length': 3.9418386491557222, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '4813996', 'n_tokens_mistral': 840, 'n_tokens_neox': 827, 'n_words': 116}