U
    ª€lj)  ã                   @   sb   d Z ddlmZ ddlmZmZmZmZ G dd„ dejƒZ	G dd„ dejƒZ
G dd	„ d	ejƒZd
S )z!
Tests for L{twisted.web._abnf}.
é    )Úunittest)Ú_decintÚ_hexintÚ_ishexdigitsÚ_istokenc                   @   s,   e Zd ZdZddœdd„Zddœdd„ZdS )ÚIsTokenTestsz:
    Test the L{twisted.web._abnf._istoken} function.
    N©Úreturnc                 C   s   dD ]}|   t|ƒ¡ qd S )N)s   GETs   Cache-Controló   &)Ú
assertTruer   ©ÚselfÚb© r   ú>/tmp/pip-unpacked-wheel-aghyhbke/twisted/web/test/test_abnf.pyÚtest_ok   s    zIsTokenTests.test_okc                 C   s   dD ]}|   t|ƒ¡ qd S )N)ó    ó    s   a b)ZassertFalser   r   r   r   r   Útest_bad   s    zIsTokenTests.test_bad)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r      s   r   c                   @   sV   e Zd ZdZddœdd„Zddœdd„Zddœdd	„Zddœd
d„Zddœdd„ZdS )ÚDecintTestsz9
    Test the L{twisted.web._abnf._decint} function.
    Nr   c                 C   sD   |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ dS )	zF
        Given a decimal digits, L{_decint} return an L{int}.
        é   ó   1é
   ó   10i(#  s   9000s   0009000N©ÚassertEqualr   ©r   r   r   r   Ú
test_valid'   s    zDecintTests.test_validc                 C   s4   |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ dS )zL
        L{_decint} decodes integers embedded in linear whitespace.
        é{   s    123s   123		s    	 123   	  Nr   r    r   r   r   Útest_validWhitespace0   s    z DecintTests.test_validWhitespacec                 C   s   |   ttd¡ dS )zL
        L{_decint} rejects a number with a leading C{+} character.
        s   +1N©ÚassertRaisesÚ
ValueErrorr   r    r   r   r   Útest_invalidPlus8   s    zDecintTests.test_invalidPlusc                 C   s   |   ttd¡ dS )zL
        L{_decint} rejects a number with a leading C{-} character.
        s   -1Nr$   r    r   r   r   Útest_invalidMinus>   s    zDecintTests.test_invalidMinusc                 C   s.   |   ttd¡ |   ttd¡ |   ttd¡ dS )zP
        L{_decint} rejects a number embedded in non-linear whitespace.
        s   1s   1s   1Nr$   r    r   r   r   Útest_invalidWhitespaceD   s    z"DecintTests.test_invalidWhitespace)	r   r   r   r   r!   r#   r'   r(   r)   r   r   r   r   r   "   s   	r   c                   @   sL   e Zd ZdZdZddœdd„Zddœdd„Zddœd	d
„Zddœdd„ZdS )ÚHexHelperTestszU
    Test the L{twisted.web._abnf._hexint} and L{_ishexdigits} helper functions.
    )r   s   0x1234s   fedss   -123+123Nr   c                 C   s   dD ]}|   dt|ƒ¡ qdS )zr
        L{_ishexdigits()} returns L{True} for nonempy bytestrings containing
        hexadecimal digits.
        )r   s   abcdefs   AB1234s   feds	   123467890TN)ÚassertIsr   ©r   Úsr   r   r   Ú
test_isHexT   s    zHexHelperTests.test_isHexc                 C   s4   |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ dS )zK
        L{_hexint()} returns the integer equivalent of the input.
        r   ó   aé   r   i#Ñ¼
s   abCD123N)r   r   r    r   r   r   Útest_decodes\   s    zHexHelperTests.test_decodesc                 C   s    | j D ]}|  dt|ƒ¡ qdS )z�
        L{_ishexdigits()} returns L{False} for bytestrings that don't contain
        hexadecimal digits, including the empty string.
        FN)Ú
badStringsr+   r   r,   r   r   r   Útest_isNotHexd   s    
zHexHelperTests.test_isNotHexc                 C   s   | j D ]}|  tt|¡ qdS )zb
        L{_hexint()} raises L{ValueError} for bytestrings that can't
        be decoded.
        N)r2   r%   r&   r   r,   r   r   r   Útest_decodeNotHexl   s    
z HexHelperTests.test_decodeNotHex)	r   r   r   r   r2   r.   r1   r3   r4   r   r   r   r   r*   M   s   r*   N)r   Ztwisted.trialr   Ztwisted.web._abnfr   r   r   r   ZSynchronousTestCaser   r   r*   r   r   r   r   Ú<module>   s
   +