Changeset 455

Show
Ignore:
Timestamp:
04/02/07 23:54:13 (1 year ago)
Author:
mikey
Message:

fixed bug with annotations that contain only a param value

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/reflection/annotations/parser/state/stubAnnotationParamNameState.php

    r454 r455  
    6767                if (strlen($this->name) == 0) { 
    6868                    throw new ReflectionException('Annotation parameter name has to start with a letter or underscore, but starts with ='); 
     69                } elseif (preg_match('/^[a-zA-Z_]{1}[a-zA-Z_0-9]*$/', $this->name) == false) { 
     70                    throw new ReflectionException('Annotation parameter name may contain letters, underscores and numbers, but contains an invalid character.'); 
    6971                } 
    7072                 
     
    8284                 
    8385            default: 
    84                 if (strlen($this->name) == 0 && preg_match('/^[a-zA-Z_]$/', $token) == false) { 
    85                     throw new ReflectionException('Annotation parameter name has to start with a letter or underscore, but starts with ' . $token); 
    86                 } elseif (preg_match('/^[a-zA-Z_0-9]$/', $token) == false) { 
    87                     throw new ReflectionException('Annotation parameter name may contain letters, underscores and numbers, but contains ' . $token); 
    88                 } 
    89                  
    9086                $this->name .= $token; 
    9187        } 
  • trunk/src/test/php/net/stubbles/reflection/annotations/parser/state/stubAnnotationParamNameStateTestCase.php

    r454 r455  
    6060     * test processing the equal sign 
    6161     */ 
    62     public function testProcessEqualSign() 
     62    public function testProcessEqualSignOnStart() 
    6363    { 
    64         $this->mockAnnotationParser->expectOnce('registerAnnotationParam', array('a')); 
     64        $this->mockAnnotationParser->expectNever('registerAnnotationParam'); 
     65        $this->mockAnnotationParser->expectNever('changeState'); 
     66        $this->expectException('ReflectionException'); 
     67        $this->paramNameState->process('='); 
     68    } 
     69     
     70    /** 
     71     * test processing the equal sign 
     72     */ 
     73    public function testProcessEqualSignAfterCorrectParamName() 
     74    { 
     75        $this->mockAnnotationParser->expectOnce('registerAnnotationParam', array('abc_123')); 
    6576        $this->mockAnnotationParser->expectOnce('changeState', array(stubAnnotationState::PARAM_VALUE)); 
    66         $this->paramNameState->process('a'); 
     77        $this->paramNameState->process('abc_123'); 
    6778        $this->paramNameState->process('='); 
    68          
    69         $this->paramNameState->selected(); 
     79    } 
     80     
     81    /** 
     82     * test processing the equal sign 
     83     */ 
     84    public function testProcessEqualSignAfterInCorrectParamName() 
     85    { 
     86        $this->mockAnnotationParser->expectNever('registerAnnotationParam'); 
     87        $this->mockAnnotationParser->expectNever('changeState'); 
    7088        $this->expectException('ReflectionException'); 
     89        $this->paramNameState->process('1a'); 
    7190        $this->paramNameState->process('='); 
    7291    } 
     
    84103        $this->paramNameState->process(')'); 
    85104    } 
    86      
    87     /** 
    88      * test processing an illegal character on start of the annotation parameter name 
    89      */ 
    90     public function testProcessIllegalCharacterOnStart() 
    91     { 
    92         $this->expectException('ReflectionException'); 
    93         $this->paramNameState->process('1'); 
    94     } 
    95      
     105 
    96106    /** 
    97107     * test processing other characters 
     
    103113        $this->paramNameState->process('_'); 
    104114        $this->assertEqual($this->paramNameState->getName(), 'a1_'); 
    105          
    106         $this->expectException('ReflectionException'); 
    107         $this->paramNameState->process(']'); 
    108115    } 
    109116}