<commit_before><?php
/*
 * This file is part of the {{ }} package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 */

namespace tests\GetOptionKit;
use GetOptionKit\ContinuousOptionParser;
use GetOptionKit\OptionCollection;

class ContinuousOptionParserTest extends \PHPUnit_Framework_TestCase 
{

    public function testOptionCollection() 
    {
        $specs = new OptionCollection;
        $specVerbose = $specs->add('v|verbose');
        $specColor = $specs->add('c|color');
        $specDebug = $specs->add('d|debug');
    }


    /* test parser without options */
    public function testParseSubCommandOptions()
    {
        $appspecs = new OptionCollection;
        $appspecs->add('v|verbose');
        $appspecs->add('c|color');
        $appspecs->add('d|debug');

        $cmdspecs = new OptionCollection;
        $cmdspecs->add('as:');
        $cmdspecs->add('b');
        $cmdspecs->add('c');

        $parser = new ContinuousOptionParser( $appspecs );

        $subcommands = array('subcommand1','subcommand2','subcommand3');
        $subcommand_specs = array(
            'subcommand1' => clone $cmdspecs,
            'subcommand2' => clone $cmdspecs,
            'subcommand3' => clone $cmdspecs,
        );
        $subcommand_options = array();

        $argv = explode(' ','program -v -c subcommand1 --as 99 arg1 arg2 arg3 -- zz xx vv');
        // $argv = explode(' ','program subcommand1 -a 1 subcommand2 -a 2 subcommand3 -a 3 arg1 arg2 arg3');
        $app_options = $parser->parse( $argv );
        $arguments = array();
        while (! $parser->isEnd()) {
            if (@$subcommands[0] && $parser->getCurrentArgument() == $subcommands[0] ) {
                $parser->advance();
                $subcommand = array_shift( $subcommands );
                $parser->setSpecs( $subcommand_specs[$subcommand] );
                $subcommand_options[ $subcommand ] = $parser->continueParse();
            } else {
                $arguments[] = $parser->advance();
            }
        }
        
        $this->assertEquals( 'arg1', $arguments[0] );
        $this->assertEquals( 'arg2', $arguments[1] );
        $this->assertEquals( 'arg3', $arguments[2] );
        $this->assertEquals( 99, $subcommand_options['subcommand1']->as );
    }
<commit_msg>Add more test case to ContinuousOptionParserTest<commit_after><?php
/*
 * This file is part of the {{ }} package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 */

namespace tests\GetOptionKit;
use GetOptionKit\ContinuousOptionParser;
use GetOptionKit\OptionCollection;

class ContinuousOptionParserTest extends \PHPUnit_Framework_TestCase 
{

    public function testOptionCollection() 
    {
        $specs = new OptionCollection;
        $specVerbose = $specs->add('v|verbose');
        $specColor = $specs->add('c|color');
        $specDebug = $specs->add('d|debug');
    }



    public function argumentProvider()
    {
        return [
            [
                ['program','subcommand1', 'arg1', 'arg2', 'arg3', 'subcommand2', '-b', 1, 'subcommand3', '-b', 2],
                [
                    'args' => ['arg1', 'arg2', 'arg3']
                ],
            ],
            [
                ['program','-v', '-c', 'subcommand1', '--as', 99, 'arg1', 'arg2', 'arg3'],
                [
                    'app' => ['verbose' => true ],
                    'args' => ['arg1', 'arg2', 'arg3']
                ],
            ],
            [
                ['program','-v', '-c', 'subcommand1', '--as', 99, 'arg1', 'arg2', 'arg3', '--','zz','xx','vv'],
                [
                    'app' => ['verbose' => true],
                    'args' => ['arg1', 'arg2', 'arg3']
                ],
            ],
        ];
    }



    /**
     * @dataProvider argumentProvider
     */
    public function testParseSubCommandOptions($argv, $expected)
    {
        $appspecs = new OptionCollection;
        $appspecs->add('v|verbose');
        $appspecs->add('c|color');
        $appspecs->add('d|debug');

        $cmdspecs = new OptionCollection;
        $cmdspecs->add('as:');
        $cmdspecs->add('b:');
        $cmdspecs->add('c:');

        $parser = new ContinuousOptionParser( $appspecs );

        $subcommands = array('subcommand1','subcommand2','subcommand3');
        $subcommand_specs = array(
            'subcommand1' => clone $cmdspecs,
            'subcommand2' => clone $cmdspecs,
            'subcommand3' => clone $cmdspecs,
        );
        $subcommand_options = array();

        // $argv = explode(' ','program -v -c subcommand1 --as 99 arg1 arg2 arg3 -- zz xx vv');
        // $argv = explode(' ','program subcommand1 -a 1 subcommand2 -a 2 subcommand3 -a 3 arg1 arg2 arg3');
        $app_options = $parser->parse( $argv );
        $arguments = array();
        while (! $parser->isEnd()) {
            if (!empty($subcommands) && $parser->getCurrentArgument() == $subcommands[0]) {
                $parser->advance();
                $subcommand = array_shift($subcommands);
                $parser->setSpecs($subcommand_specs[$subcommand]);
                $subcommand_options[$subcommand] = $parser->continueParse();
            } else {
                $arguments[] = $parser->advance();
            }
        }
        $this->assertSame($expected['args'], $arguments);
        if (isset($expected['app'])) {
            foreach ($expected['app'] as $k => $v) {
                $this->assertEquals($v, $app_options->get($k));
            }
        }

        // $this->assertEquals(99, $subcommand_options['subcommand1']->as);
    }

{'fraction_non_alphanumeric': 0.16415845009513924, 'fraction_numerical': 0.014876318975955717, 'mean_word_length': 2.1389793702497286, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 65, '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': '2539915', 'n_tokens_mistral': 1749, 'n_tokens_neox': 1694, 'n_words': 359}