B
    v9az#  ã               @   sx   d Z ddlmZ ddlZddlmZ ddlmZmZ ddl	m
Z
 G dd„ dƒZG d	d
„ d
ejƒZedkrtejdd dS )zTest hyperparser, coverage 98%.é    )ÚHyperParserN)Úrequires)ÚTkÚText)ÚEditorWindowc               @   s    e Zd Zdd„ ZejZejZdS )ÚDummyEditwinc             C   s"   || _ d| _d| _d| _d| _d S )Né   z>>>)é2   iô  iè  )ÚtextZindentwidthZtabwidthÚprompt_last_lineZnum_context_lines)Úselfr
   © r   ú&/usr/lib/python3.7/test_hyperparser.pyÚ__init__
   s
    zDummyEditwin.__init__N)Ú__name__Ú
__module__Ú__qualname__r   r   Z_build_char_in_string_funcZis_char_in_stringr   r   r   r   r   	   s   r   c               @   sx   e Zd ZdZedd„ ƒZedd„ ƒZdd„ Zdd	„ Zd
d„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚHyperParserTestu#  """This is a module docstring"""
# this line is a comment
x = "this is a string"
y = 'this is also a string'
l = [i for i in range(10)]
m = [py*py for # comment
       py in l]
x.__len__
z = ((r'asdf')+('a')))
[x for x in
for = False
clichÃ© = "this is a string with unicode, what a clichÃ©"c             C   s6   t dƒ tƒ | _| j ¡  t| jƒ| _t| jƒ| _d S )NZgui)r   r   ÚrootZwithdrawr   r
   r   Úeditwin)Úclsr   r   r   Ú
setUpClass%   s
    
zHyperParserTest.setUpClassc             C   s   | ` | `| j ¡  | `d S )N)r
   r   r   Zdestroy)r   r   r   r   ÚtearDownClass-   s    
zHyperParserTest.tearDownClassc             C   s   | j  d| j¡ d S )NÚinsert)r
   r   Úcode)r   r   r   r   ÚsetUp3   s    zHyperParserTest.setUpc             C   s   | j  dd¡ d| j_d S )Nz1.0Úendz>>>)r
   Údeleter   r   )r   r   r   r   ÚtearDown6   s    zHyperParserTest.tearDownc             C   s   t | j|ƒS )z>
        Return a parser object with index at 'index'
        )r   r   )r   Úindexr   r   r   Ú
get_parser:   s    zHyperParserTest.get_parserc          	   C   s–   |   t¡ }| j ddd¡ |  d¡}W dQ R X |  dt|jƒ¡ d| j_	|  d¡}|  
|j| j dd¡¡ | j d| j dd¡d	 ¡ |  d
¡}dS )z6
        test corner cases in the init method
        Zconsolez1.0z1.endz1.5NÚprecedesÚ r   é   z54.5)ÚassertRaisesÚ
ValueErrorr
   Ztag_addr    ÚassertInÚstrÚ	exceptionr   r   ÚassertEqualZrawtextÚgetr   )r   ÚveÚpr   r   r   Ú	test_init@   s    
zHyperParserTest.test_initc             C   s¤   | j }|dƒ}|  | ¡ ¡ |dƒ}|  | ¡ ¡ |dƒ}|  | ¡ ¡ |dƒ}|  | ¡ ¡ |dƒ}|  | ¡ ¡ |dƒ}|  | ¡ ¡ |dƒ}|  | ¡ ¡ d S )Nz1.0z1.4z2.3z3.3z3.7z4.6z12.54)r    ÚassertFalseZis_in_stringÚ
assertTrue)r   r*   r,   r   r   r   Útest_is_in_stringT   s    z!HyperParserTest.test_is_in_stringc             C   sŽ   | j }|dƒ}|  | ¡ ¡ |dƒ}|  | ¡ ¡ |dƒ}|  | ¡ ¡ |dƒ}|  | ¡ ¡ |dƒ}|  | ¡ ¡ |dƒ}|  | ¡ ¡ d S )Nz1.0z1.1z2.5z3.4z3.6z4.14)r    r/   Z
is_in_coder.   )r   r*   r,   r   r   r   Útest_is_in_codef   s    zHyperParserTest.test_is_in_codec             C   sà   | j }dd„ }dd„ }|dƒ}|  ||ƒ¡ |  ||ƒ¡ |dƒ}|  ||ƒd¡ |  ||ƒ||ƒ¡ |dƒ}|  ||ƒd	¡ |  ||ƒ||ƒ¡ |d
ƒ}|  ||ƒd¡ |  ||ƒ¡ |dƒ}|  ||ƒ¡ |  ||ƒ¡ d S )Nc             S   s   | j ddS )NF)Ú	mustclose)Úget_surrounding_brackets)Úparserr   r   r   Úwithout_mustclosey   s    zGHyperParserTest.test_get_surrounding_bracket.<locals>.without_mustclosec             S   s   | j ddS )NT)r2   )r3   )r4   r   r   r   Úwith_mustclose~   s    zDHyperParserTest.test_get_surrounding_bracket.<locals>.with_mustclosez3.2z5.6)z5.4z5.25z5.23)z5.21z5.24z6.15)z6.4z6.endz9.end)r    ZassertIsNoneZassertTupleEqual)r   r*   r5   r6   r,   r   r   r   Útest_get_surrounding_bracketv   s$    z,HyperParserTest.test_get_surrounding_bracketc          	   C   s²  | j }|dƒ}|  | ¡ d¡ |dƒ}|  t¡}| ¡  W d Q R X |  dt|jƒ¡ |dƒ}|  | ¡ d¡ |dƒ}|  | ¡ d¡ |d	ƒ}|  | ¡ d
¡ |dƒ}|  | ¡ d¡ |dƒ}|  | ¡ d¡ |dƒ}|  | ¡ d¡ |dƒ}|  t¡}| ¡  W d Q R X |  dt|jƒ¡ |dƒ}|  | ¡ d
¡ |dƒ}|  | ¡ d
¡ |dƒ}|  | ¡ d
¡ |dƒ}|  | ¡ d
¡ |dƒ}|  | ¡ d¡ |dƒ}|  | ¡ d¡ d S )Nz4.2zy z4.7zis inside a codez5.25z	range(10)z6.7Úpyz6.8r"   z7.9z8.endz	x.__len__z9.13zr'asdf'z9.17z10.0z10.6z10.11z11.3z11.11ÚFalsez12.6u   clichÃ©)r    r)   Zget_expressionr$   r%   r&   r'   r(   )r   r*   r,   r+   r   r   r   Útest_get_expression—   sF    z#HyperParserTest.test_get_expressionc             C   s¸  dd„ }|   |dƒ¡ |  |dƒ¡ |  |dƒ¡ |  |dƒ¡ |  |dƒ¡ |  |dƒ¡ |  |d	ƒ¡ |  |d
ƒ¡ |   |dƒ¡ |   |dƒ¡ |   |dƒ¡ |  |dƒ¡ |  |dƒ¡ |  |dƒ¡ |   |dƒ¡ |   |dƒ¡ |   |dƒ¡ |  t ddd¡tdƒ¡ |  t ddd¡tdƒ¡ |  t ddd¡tdƒ¡ |   |dƒ¡ |   |dƒ¡ |   |dƒ¡ |   |dƒ¡ |   |dƒ¡ |   |d ƒ¡ |   |d!ƒ¡ |   |d"ƒ¡ d S )#Nc             S   sJ   t  | dt| ƒ¡}|t| ƒkr"dS |dkr.dS d |t| ƒ¡}t|ƒ‚d S )Nr   TFz'Unexpected result: {} (expected 0 or {})r   Ú_eat_identifierÚlenÚformatÚ	Exception)Ú	candidateÚresultZerr_msgr   r   r   Úis_valid_idÌ   s    z8HyperParserTest.test_eat_identifier.<locals>.is_valid_idZ2notidZvalid_idZ	_valid_idZ	valid_id_Z
_2valid_idÚTruer9   ÚNoneÚforÚimportÚreturnZclicheu   clichÃ©u   aÙ¢Z2au   Ù¢au   aÂ²z+ varr   é   Úvarz+varr#   z.varú+ú ú:ú?ú^ú\ú"z
"a string")r.   r/   r)   r   r;   r<   )r   rA   r   r   r   Útest_eat_identifierË   s:    z#HyperParserTest.test_eat_identifierc             C   s*  t j}xtddƒD ]}|  |d| d|ƒ|¡ |  |d| d|ƒ|¡ |  |dd|d   d|ƒ|¡ |  |dd|d   d|ƒ|¡ |  |dd|d   d|ƒ|¡ |  |d|d  d d|ƒ|¡ |  |d| d|ƒd¡ |  |dd|d   d|ƒd¡ |  |dd|d   d|ƒd¡ qW d S )Né   é   Úar   õ   Ã©Ú2rI   )r   r;   Úranger)   )r   Zeat_idÚlengthr   r   r   Ú#test_eat_identifier_various_lengths  s         z3HyperParserTest.test_eat_identifier_various_lengthsN)r   r   r   r   Úclassmethodr   r   r   r   r    r-   r0   r1   r7   r:   rP   rX   r   r   r   r   r      s   !49r   Ú__main__é   )Ú	verbosity)Ú__doc__Zidlelib.hyperparserr   ZunittestZtest.supportr   Ztkinterr   r   Zidlelib.editorr   r   ZTestCaser   r   Úmainr   r   r   r   Ú<module>   s      