<commit_before><?php

namespace Phug\Test;

use Phug\Lexer;
use Phug\Lexer\Scanner\TextLineScanner;
use Phug\Lexer\State;
use Phug\Lexer\Token\AttributeEndToken;
use Phug\Lexer\Token\AttributeStartToken;
use Phug\Lexer\Token\AttributeToken;
use Phug\Lexer\Token\BlockToken;
use Phug\Lexer\Token\ExpressionToken;
use Phug\Lexer\Token\IndentToken;
use Phug\Lexer\Token\NewLineToken;
use Phug\Lexer\Token\OutdentToken;
use Phug\Lexer\Token\TagToken;
use Phug\Lexer\Token\TextToken;

/**
 * @coversDefaultClass \Phug\Lexer
 */
class LexerTest extends AbstractLexerTest
{
    /**
     * @covers ::__construct
     * @covers ::getScanners
     */
    public function testGetScanners()
    {
        $lexer = new Lexer([
            'scanners' => [
                'indent' => TextLineScanner::class,
            ],
        ]);
        $indent = $lexer->getScanners()['indent'];

        self::assertSame(TextLineScanner::class, $indent);
    }

    /**
     * @covers            ::getState
     * @expectedException \RuntimeException
     */
    public function testGetStateException()
    {
        $this->expectMessageToBeThrown(
            'Failed to get state: No lexing process active. '.
            'Use the `lex()`-method'
        );

        $lexer = new Lexer();
        $lexer->getState();
    }

    /**
     * @covers ::lex
     * @covers ::getState
     */
    public function testGetState()
    {
        include_once __DIR__.'/MockScanner.php';

        $mock = new MockScanner();
        $lexer = new Lexer([
            'scanners' => [
                'tag' => $mock,
            ],
        ]);
        $mock->setLexer($lexer);

        foreach ($lexer->lex('p') as $token) {
        }

        self::assertInstanceOf(State::class, $mock->getState());
    }

    /**
     * @covers ::filterScanner
     * @covers ::addScanner
     */
    public function testAddScanner()
    {
        include_once __DIR__.'/MockScanner.php';

        $lexer = new Lexer();
        $self = $lexer->addScanner('foo', MockScanner::class);
        $scanners = $lexer->getScanners();

        self::assertSame(MockScanner::class, end($scanners));
        self::assertSame($lexer, $self);

        $lexer = new Lexer();
        $self = $lexer->addScanner('foo', MockScanner::class, true);
        $scanners = $lexer->getScanners();
        foreach ($scanners as $scanner) {
            break;
        }

        self::assertSame(MockScanner::class, $scanner);
        self::assertSame($lexer, $self);
    }

    /**
     * @covers            ::filterScanner
     * @expectedException \InvalidArgumentException
     */
    public function testFilterScanner()
    {
        $this->expectMessageToBeThrown(
            'Scanner NotAValidClassName is not a valid '.
            'Phug\\Lexer\\ScannerInterface '.
            'instance or extended class'
        );

        $lexer = new Lexer();
        $lexer->addScanner('foo', 'NotAValidClassName');
        foreach ($lexer->lex('p') as $token) {
        }
    }

    /**
     * @covers            ::lex
     * @expectedException \InvalidArgumentException
     */
    public function testBadStateClassName()
    {
        $this->expectMessageToBeThrown(
            'state_class_name needs to be a valid '.
            'Phug\\Lexer\\State sub class'
        );

        $lexer = new Lexer([
            'state_class_name' => 'NotAValidClassName',
        ]);
        foreach ($lexer->lex('p') as $token) {
        }
    }

    /**
     * @covers  ::lex
     */
    public function testIfPathIsPassedToTokenSourceLocationsCorrectly()
    {
<commit_msg>Apply fixes from StyleCI<commit_after><?php

namespace Phug\Test;

use Phug\Lexer;
use Phug\Lexer\Scanner\TextLineScanner;
use Phug\Lexer\State;
use Phug\Lexer\Token\AttributeEndToken;
use Phug\Lexer\Token\AttributeStartToken;
use Phug\Lexer\Token\AttributeToken;
use Phug\Lexer\Token\BlockToken;
use Phug\Lexer\Token\ExpressionToken;
use Phug\Lexer\Token\IndentToken;
use Phug\Lexer\Token\NewLineToken;
use Phug\Lexer\Token\OutdentToken;
use Phug\Lexer\Token\TagToken;
use Phug\Lexer\Token\TextToken;

/**
 * @coversDefaultClass \Phug\Lexer
 */
class LexerTest extends AbstractLexerTest
{
    /**
     * @covers ::__construct
     * @covers ::getScanners
     */
    public function testGetScanners()
    {
        $lexer = new Lexer([
            'scanners' => [
                'indent' => TextLineScanner::class,
            ],
        ]);
        $indent = $lexer->getScanners()['indent'];

        self::assertSame(TextLineScanner::class, $indent);
    }

    /**
     * @covers            ::getState
     * @expectedException \RuntimeException
     */
    public function testGetStateException()
    {
        $this->expectMessageToBeThrown(
            'Failed to get state: No lexing process active. '.
            'Use the `lex()`-method'
        );

        $lexer = new Lexer();
        $lexer->getState();
    }

    /**
     * @covers ::lex
     * @covers ::getState
     */
    public function testGetState()
    {
        include_once __DIR__.'/MockScanner.php';

        $mock = new MockScanner();
        $lexer = new Lexer([
            'scanners' => [
                'tag' => $mock,
            ],
        ]);
        $mock->setLexer($lexer);

        foreach ($lexer->lex('p') as $token) {
        }

        self::assertInstanceOf(State::class, $mock->getState());
    }

    /**
     * @covers ::filterScanner
     * @covers ::addScanner
     */
    public function testAddScanner()
    {
        include_once __DIR__.'/MockScanner.php';

        $lexer = new Lexer();
        $self = $lexer->addScanner('foo', MockScanner::class);
        $scanners = $lexer->getScanners();

        self::assertSame(MockScanner::class, end($scanners));
        self::assertSame($lexer, $self);

        $lexer = new Lexer();
        $self = $lexer->addScanner('foo', MockScanner::class, true);
        $scanners = $lexer->getScanners();
        foreach ($scanners as $scanner) {
            break;
        }

        self::assertSame(MockScanner::class, $scanner);
        self::assertSame($lexer, $self);
    }

    /**
     * @covers            ::filterScanner
     * @expectedException \InvalidArgumentException
     */
    public function testFilterScanner()
    {
        $this->expectMessageToBeThrown(
            'Scanner NotAValidClassName is not a valid '.
            'Phug\\Lexer\\ScannerInterface '.
            'instance or extended class'
        );

        $lexer = new Lexer();
        $lexer->addScanner('foo', 'NotAValidClassName');
        foreach ($lexer->lex('p') as $token) {
        }
    }

    /**
     * @covers            ::lex
     * @expectedException \InvalidArgumentException
     */
    public function testBadStateClassName()
    {
        $this->expectMessageToBeThrown(
            'state_class_name needs to be a valid '.
            'Phug\\Lexer\\State sub class'
        );

        $lexer = new Lexer([
            'state_class_name' => 'NotAValidClassName',
        ]);
        foreach ($lexer->lex('p') as $token) {
        }
    }

    /**
     * @covers  ::lex
     */
    public function testIfPathIsPassedToTokenSourceLocationsCorrectly()
    {
{'fraction_non_alphanumeric': 0.13908205841446453, 'fraction_numerical': 0.0, 'mean_word_length': 2.1089494163424125, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, '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': '2194246', 'n_tokens_mistral': 2301, 'n_tokens_neox': 2219, 'n_words': 399}