o
    JAfz#  ã                   @   s|   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r<ejdd dS 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é   ú>>>)é2   iô  iè  )ÚtextZindentwidthZtabwidthÚprompt_last_lineZnum_context_lines)Úselfr   © r   ú9/usr/lib/python3.10/idlelib/idle_test/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destroyr   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 )Nú1.0Úendr	   )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  ƒ n1 sw   Y  |  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consoler   z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 )Nr   z1.4z2.3z3.3z3.7z4.6z12.54)r$   ÚassertFalseZis_in_stringÚ
assertTrue©r   r.   r0   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 )Nr   z1.1z2.5z3.4z3.6z4.14)r$   r3   Z
is_in_coder2   r4   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   ó   | j ddS )NF©Z	mustclose©Zget_surrounding_brackets©Úparserr   r   r   Úwithout_mustclosey   ó   zGHyperParserTest.test_get_surrounding_bracket.<locals>.without_mustclosec                 S   r7   )NTr8   r9   r:   r   r   r   Úwith_mustclose~   r=   zDHyperParserTest.test_get_surrounding_bracket.<locals>.with_mustclosez3.2z5.6)z5.4ú5.25z5.23)z5.21z5.24z6.15)z6.4z6.endz9.end)r$   ZassertIsNoneZassertTupleEqual)r   r.   r<   r>   r0   r   r   r   Útest_get_surrounding_bracketv   s$   z,HyperParserTest.test_get_surrounding_bracketc                 C   sÚ  | j }|dƒ}|  | ¡ d¡ |dƒ}|  t¡}| ¡  W d   ƒ n1 s'w   Y  |  dt|jƒ¡ |dƒ}|  | ¡ d¡ |dƒ}|  | ¡ d¡ |d	ƒ}|  | ¡ d
¡ |dƒ}|  | ¡ d¡ |dƒ}|  | ¡ d¡ |dƒ}|  | ¡ d¡ |dƒ}|  t¡}| ¡  W d   ƒ n1 s•w   Y  |  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 coder?   z	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.6õ   clichÃ©)r$   r-   Zget_expressionr(   r)   r*   r+   r,   )r   r.   r0   r/   r   r   r   Útest_get_expression—   sJ   
ÿ
ÿ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   sF   t  | dt| ƒ¡}|t| ƒkrdS |dkrdS d |t| ƒ¡}t|ƒ‚)Nr   TFz'Unexpected result: {} (expected 0 or {})r   Ú_eat_identifierÚlenÚformatÚ	Exception)Ú	candidateÚresultÚ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ÚTruerB   ÚNoneÚforÚimportÚreturnZclicherC   u   aÙ¢Z2au   Ù¢au   aÂ²z+ varr   é   Úvarz+varr'   z.varú+ú ú:ú?ú^ú\ú"z
"a string")r2   r3   r-   r   rE   rF   )r   rL   r   r   r   Útest_eat_identifierË   s:   z#HyperParserTest.test_eat_identifierc                 C   s"  t j}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d S )Né   é   Úar   õ   Ã©Ú2rT   )r   rE   Ú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$   r1   r5   r6   r@   rD   r[   rc   r   r   r   r   r      s"    ÿ

!49r   Ú__main__é   )Ú	verbosity)Ú__doc__Zidlelib.hyperparserr   ZunittestZtest.supportr   Útkinterr   r   Zidlelib.editorr   r   ZTestCaser   r   Úmainr   r   r   r   Ú<module>   s     ÿ