<commit_before><?php

namespace Minime\Annotations;

class AnnotationsBagTest extends \PHPUnit_Framework_TestCase
{

    private $Bag;

    private $rules;

    public function setUp()
    {
        $this->rules = new ParserRules;

        $this->Bag = new AnnotationsBag(
            [
                'get' => true,
                'post' => false,
                'put' => false,
                'default' => null,
                'val.max' => 16,
                'val.min' => 6,
                'val.regex' => "/[A-z0-9\_\-]+/",
                'config.container' => 'Some\Collection',
                'config.export' => ['json', 'csv']
            ],
            $this->rules
        );
    }

    /**
     * @test
     * @expectedException PHPUnit_Framework_Error
     */
    public function constructMustTakeAParserRule()
    {
        new AnnotationsBag(['post' => 20]);
    }

    /**
     * @test
     * @expectedException PHPUnit_Framework_Error
     */
    public function constructAcceptsOnlyArrays()
    {
        new AnnotationsBag('', $this->rules);
    }

    /**
     * @test
     */
    public function constructRemoveUncorrectIndex()
    {
        $res = new AnnotationsBag([0 => true, 'post' => 20], $this->rules);
        $this->assertSame($res->export(), ['post' => 20]);
    }

    /**
     * @test
     */
    public function nullForUnsetAnnotation()
    {
        $this->assertSame(false, $this->Bag->get('post'));
        $this->assertSame(null, $this->Bag->get('bar'));
    }

    /**
     * @test
     */
    public function testArrayAccessBag()
    {
        $bag = new AnnotationsBag([], $this->rules);
        $this->assetEquals(0, count($bag));
        $bag['fruit'] = 'orange';
        $this->assetEquals(1, count($bag));
        $this->assertSame('orange', $bag->get('fruit'));
        $this->assertSame('orange', $bag['fruit']);
        unset($bag['fruit']);
        $this->assetEquals(0, count($bag));
    }

    /**
     * @test
     */
    public function grep()
    {
        $this->assertCount(3, $this->Bag->grep('val'));
        $this->assertCount(2, $this->Bag->grep('config'));

        // grep that always matches nothing
        $this->assertCount(0, $this->Bag->grep('^$')->export());

        // chained grep
        $this->assertSame(['val.max' => 16], $this->Bag->grep('max$')->export());
        $this->assertSame(['config.export' => ['json', 'csv']], $this->Bag->grep('export$')->export());
    }

    /**
     * @test
     */
    public function grepNamespace()
    {
        $this->Bag = new AnnotationsBag(
            [
                'path.to.the.treasure' => 'cheers!',<commit_msg>added more Arrayaccess tests<commit_after><?php

namespace Minime\Annotations;

class AnnotationsBagTest extends \PHPUnit_Framework_TestCase
{

    private $Bag;

    private $rules;

    public function setUp()
    {
        $this->rules = new ParserRules;

        $this->Bag = new AnnotationsBag(
            [
                'get' => true,
                'post' => false,
                'put' => false,
                'default' => null,
                'val.max' => 16,
                'val.min' => 6,
                'val.regex' => "/[A-z0-9\_\-]+/",
                'config.container' => 'Some\Collection',
                'config.export' => ['json', 'csv']
            ],
            $this->rules
        );
    }

    /**
     * @test
     * @expectedException PHPUnit_Framework_Error
     */
    public function constructMustTakeAParserRule()
    {
        new AnnotationsBag(['post' => 20]);
    }

    /**
     * @test
     * @expectedException PHPUnit_Framework_Error
     */
    public function constructAcceptsOnlyArrays()
    {
        new AnnotationsBag('', $this->rules);
    }

    /**
     * @test
     */
    public function constructRemoveUncorrectIndex()
    {
        $res = new AnnotationsBag([0 => true, 'post' => 20], $this->rules);
        $this->assertSame($res->export(), ['post' => 20]);
    }

    /**
     * @test
     */
    public function nullForUnsetAnnotation()
    {
        $this->assertSame(false, $this->Bag->get('post'));
        $this->assertSame(null, $this->Bag->get('bar'));
    }

    public function testArrayAccessBag()
    {
        $bag = new AnnotationsBag([], $this->rules);
        $this->assetEquals(0, count($bag));
        $bag['fruit'] = 'orange';
        $this->assetEquals(1, count($bag));
        $this->assertSame('orange', $bag->get('fruit'));
        $this->assertSame('orange', $bag['fruit']);
        unset($bag['fruit']);
        $this->assetEquals(0, count($bag));
        $this->assertNull($bag['fruit']);
    }

    /**
     * @test
     * @expectedException InvalidArgumentException
     */
    public function testArrayAccessInvalidSetterBag()
    {
        $bag = new AnnotationsBag([], $this->rules);
        $bag[0] = 'orange';
    }
 
    /**
     * @test
     * @expectedException InvalidArgumentException
     */
    public function testArrayAccessInvalidGetterBag()
    {
        $bag = new AnnotationsBag([], $this->rules);
        $res = $bag[0];
    }

    /**
     * @test
     */
    public function grep()
    {
        $this->assertCount(3, $this->Bag->grep('val'));
        $this->assertCount(2, $this->Bag->grep('config'));

        // grep that always matches nothing
        $this->assertCount(0, $this->Bag->grep('^$')->export());

        // chained grep
        $this->assertSame(['val.max' => 16], $this->Bag->grep('max$')->export());
        $this->assertSame(['config.export' => ['json', 'csv']], $this->Bag->grep('export$')->export());
    }

    /**
     * @test
     */
    public function grepNamespace()
    {
        $this->Bag = new AnnotationsBag(
            [
                'path.to.the.treasure' => 'cheers!',
{'fraction_non_alphanumeric': 0.1841055006073226, 'fraction_numerical': 0.007287870900572618, 'mean_word_length': 1.9513568868407578, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 116, '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': '2490684', 'n_tokens_mistral': 1809, 'n_tokens_neox': 1715, 'n_words': 294}