<commit_before><?php
/**
 * Go! AOP framework
 *
 * @copyright Copyright 2013, <NAME> <<EMAIL>>
 *
 * This source file is subject to the license that is bundled
 * with this source code in the file LICENSE.
 */


namespace Go\Aop\Pointcut;

/**
 * Class PointcutParserTest defines common check for valid grammar parsing
 */
use Dissect\Lexer\Lexer;

class PointcutParserTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var null|Lexer
     */
    protected $lexer = null;

    /**
     * @var null|PointcutParser
     */
    protected $parser = null;

    /**
     * {@inheritdoc}
     */
    protected function setUp()
    {
        parent::setUp();
        $this->lexer  = new PointcutLexer();
        $container    = $this->getMock('Go\Core\AspectContainer');
        $annotReader  = $this->getMock('Go\Instrument\RawAnnotationReader');
        $this->parser = new PointcutParser(new PointcutGrammar($container, $annotReader));
    }

    /**
     * Tests parsing
     *
     * @dataProvider validPointcutDefinitions
     */
    public function testParsingExpression($pointcutExpression)
    {
        $stream = $this->lexer->lex($pointcutExpression);
        $result = $this->parser->parse($stream);
        $this->assertNotNull($result);
    }

    public function validPointcutDefinitions()
    {
        return array(
            // Execution pointcuts
            array('execution(public Example->method(*))'),
            array('execution(public Example->method|method1|method2(*))'),
            array('execution(final public Example\Aspect\*->method*(*))'),
            array('execution(protected|public **::*someStatic*Method*(*))'),

            array('@annotation(First\Second\Annotation\Class)'),

            // This will match property that has First\Second\Annotation\Class annotation
            array('@access(First\Second\Annotation\Class)'),

            // This will match anything in the class Specific\Class (both properties and methods)
            array('class(Specific\Class)'),

            // This will match all the methods in all classes of Go\Aspects\Blog\Package.
            array('within(Go\Aspects\Blog\Package\*)'),
            // This will match all the methods in all classes of Go\Aspects\Blog\Package and its sub packages.
            array('within(Go\Aspects\Blog\Package\**)'),
            // This will match all the methods in the DemoClass.
            array('within(Go\Aspects\Blog\Package\DemoClass)'),
            // This will match all the methods which are in classes which implement DemoInterface.
            array('within(DemoInterface+)'),

            // Access pointcuts
            array('access(* Example\Aspect\*->property*)'),
            array('access(protected Test\Class*->someProtected*Property)'),

            // Logic pointcuts
            array('!within(DemoInterface\Test+)'),
            array('within(DemoInterface+) && within(Some\Namespace\**)'),
            array('within(DemoInterface+) || within(Some\Namespace\**)'),

            // Parenthesis
            array('within(DemoInterface+) && ( within(**) || within(*) )'),<commit_msg>Add a smoke test for the new pointcut syntax<commit_after><?php
/**
 * Go! AOP framework
 *
 * @copyright Copyright 2013, <NAME> <<EMAIL>>
 *
 * This source file is subject to the license that is bundled
 * with this source code in the file LICENSE.
 */


namespace Go\Aop\Pointcut;

/**
 * Class PointcutParserTest defines common check for valid grammar parsing
 */
use Dissect\Lexer\Lexer;

class PointcutParserTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var null|Lexer
     */
    protected $lexer = null;

    /**
     * @var null|PointcutParser
     */
    protected $parser = null;

    /**
     * {@inheritdoc}
     */
    protected function setUp()
    {
        parent::setUp();
        $this->lexer  = new PointcutLexer();
        $container    = $this->getMock('Go\Core\AspectContainer');
        $annotReader  = $this->getMock('Go\Instrument\RawAnnotationReader');
        $this->parser = new PointcutParser(new PointcutGrammar($container, $annotReader));
    }

    /**
     * Tests parsing
     *
     * @dataProvider validPointcutDefinitions
     */
    public function testParsingExpression($pointcutExpression)
    {
        $stream = $this->lexer->lex($pointcutExpression);
        $result = $this->parser->parse($stream);
        $this->assertNotNull($result);
    }

    public function validPointcutDefinitions()
    {
        return array(
            // Execution pointcuts
            array('execution(public Example->method(*))'),
            array('execution(public Example->method|method1|method2(*))'),
            array('execution(final public Example\Aspect\*->method*(*))'),
            array('execution(protected|public **::*someStatic*Method*(*))'),

            array('@annotation(First\Second\Annotation\Class)'),

            // This will match property that has First\Second\Annotation\Class annotation
            array('@access(First\Second\Annotation\Class)'),

            // This will match anything in the class Specific\Class (both properties and methods)
            array('class(Specific\Class)'),

            // This will match all the methods in all classes of Go\Aspects\Blog\Package.
            array('within(Go\Aspects\Blog\Package\*)'),
            // This will match all the methods in all classes of Go\Aspects\Blog\Package and its sub packages.
            array('within(Go\Aspects\Blog\Package\**)'),
            // This will match all the methods in the DemoClass.
            array('within(Go\Aspects\Blog\Package\DemoClass)'),
            // This will match all the methods which are in classes which implement DemoInterface.
            array('within(DemoInterface+)'),
            // This will match all the methods in the class with specific annotation.
            array('@within(First\Second\Annotation\Class)'),

            // Access pointcuts
            array('access(* Example\Aspect\*->property*)'),
            array('access(protected Test\Class*->someProtected*Property)'),

            // Logic pointcuts
            array('!within(DemoInterface\Test+)'),
            array('within(DemoInterface+) && within(Some\Namespace\**)'),
            array('within(DemoInterface+) || within(Some\Namespace\**)'),

            // Parenthesis
            array('within(DemoInterface+) && ( within(**) || within(*) )'),
{'fraction_non_alphanumeric': 0.13591022443890274, 'fraction_numerical': 0.0018703241895261845, 'mean_word_length': 2.5551246537396124, 'pattern_counts': {'":': 0, '<': 11, '<?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': '6950872', 'n_tokens_mistral': 1790, 'n_tokens_neox': 1661, 'n_words': 405}