DocblockGrammar.php

<?php

namespace Tlf\Lexer\Test;


class DocblockGrammar extends Tester {

    /**
     * @test bug where an attribute on a line with only whitespace after the attribute causes the program to stall
     */
    public function testBuildAstWithAttributesBug(){
        $lines = [
            '@one ',
            '@two okay',
        ];
        $db_grammar = new \Tlf\Lexer\DocblockGrammar();
        $ast = $db_grammar->buildAstWithAttributes($lines);
        $this->compare(
            array (
              'type' => 'docblock',
              'description' => '',
              'attribute' => 
              array (
                0 => 
                array (
                  'type' => 'attribute',
                  'name' => 'one',
                  'description' => '',
                ),
                1 => 
                array (
                  'type' => 'attribute',
                  'name' => 'two',
                  'description' => 'okay',
                ),
              ),
            ),
            $ast->getTree()
        );
        
    }

    public function testBuildAstWithAttributes(){
        $lines = [
            '@one good',
            '@two okay',
        ];
        $db_grammar = new \Tlf\Lexer\DocblockGrammar();
        $ast = $db_grammar->buildAstWithAttributes($lines);
        $this->compare(
            array (
              'type' => 'docblock',
              'description' => '',
              'attribute' => 
              array (
                0 => 
                array (
                  'type' => 'attribute',
                  'name' => 'one',
                  'description' => 'good',
                ),
                1 => 
                array (
                  'type' => 'attribute',
                  'name' => 'two',
                  'description' => 'okay',
                ),
              ),
            ),
            $ast->getTree()
        );
        
    }

    /**
     * Test a bunch of directives
     */ 
    public function testDocblockDirectives(){
        $docGram = new \Tlf\Lexer\DocblockGrammar();
        $grammars = [
            $docGram,
        ];
        // $docGram->buildDirectives();

        $directive_tests = require($this->file('code/Docblock/tests.php'));

        $this->runDirectiveTests($grammars, $directive_tests);
    }

}