
    ;ez#                         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          Z G d	 d
ej                  Zedk    r ej        d           dS dS )zTest hyperparser, coverage 98%.    )HyperParserN)requires)TkText)EditorWindowc                   0    e Zd Zd Zej        Zej        ZdS )DummyEditwinc                 L    || _         d| _        d| _        d| _        d| _        d S )N   >>>)2   i  i  )textindentwidthtabwidthprompt_last_linenum_context_lines)selfr   s     9/usr/lib/python3.11/idlelib/idle_test/test_hyperparser.py__init__zDummyEditwin.__init__
   s.    	 %!.    N)__name__
__module____qualname__r   r   _build_char_in_string_funcis_char_in_string r   r   r	   r	   	   s3        / / / ".!H$6r   r	   c                   z    e Zd ZdZed             Zed             Zd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd Z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                     t          d           t                      | _        | j                                         t	          | j                  | _        t          | j                  | _        d S )Ngui)r   r   rootwithdrawr   r   r	   editwinclss    r   
setUpClasszHyperParserTest.setUpClass%   sP    44>>"38,,r   c                 D    | ` | `| j                                         | `d S )N)r   r#   r!   destroyr$   s    r   tearDownClasszHyperParserTest.tearDownClass-   s(    HckHHHr   c                 F    | j                             d| j                   d S )Ninsert)r   r+   coder   s    r   setUpzHyperParserTest.setUp3   s"    	49-----r   c                 T    | j                             dd           d| j        _        d S )N1.0endr   )r   deleter#   r   r-   s    r   tearDownzHyperParserTest.tearDown6   s*    	&&&(-%%%r   c                 ,    t          | j        |          S )z>
        Return a parser object with index at 'index'
        )r   r#   )r   indexs     r   
get_parserzHyperParserTest.get_parser:   s     4<///r   c                 ^   |                      t                    5 }| j                            ddd           |                     d          }ddd           n# 1 swxY w Y   |                     dt          |j                             d| j        _	        |                     d          }| 
                    |j        | j                            dd                     | j                            d| j                            dd          d	z             |                     d
          }dS )z6
        test corner cases in the init method
        consoler0   z1.endz1.5Nprecedes r1      z54.5)assertRaises
ValueErrorr   tag_addr6   assertInstr	exceptionr#   r   assertEqualrawtextgetr+   )r   veps      r   	test_initzHyperParserTest.test_init@   s@    z** 	'bIi888&&A	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	j#bl"3"3444 )+% OOE""DIMM%$?$?@@@ 			eU ; ;A =>>>OOF##s   2AA Ac                    | j         } |d          }|                     |                                            |d          }|                     |                                            |d          }|                     |                                            |d          }|                     |                                            |d          }|                     |                                            |d          }|                     |                                            |d          }|                     |                                           d S )Nr0   z1.4z2.3z3.3z3.7z4.6z12.54)r6   assertFalseis_in_string
assertTruer   rD   rF   s      r   test_is_in_stringz!HyperParserTest.test_is_in_stringT   s4   oCJJ))***CJJ(()))CJJ))***CJJ))***CJJ(()))CJJ(()))CLL(()))))r   c                 l   | j         } |d          }|                     |                                            |d          }|                     |                                            |d          }|                     |                                            |d          }|                     |                                            |d          }|                     |                                            |d          }|                     |                                           d S )Nr0   z1.1z2.5z3.4z3.6z4.14)r6   rK   
is_in_coderI   rL   s      r   test_is_in_codezHyperParserTest.test_is_in_codef   s   oCJJ'''CJJ(((CJJ(((CJJ'''CJJ(((CKK(((((r   c                    | j         }d }d } |d          }|                      ||                     |                      ||                      |d          }|                      ||          d           |                      ||           ||                      |d          }|                      ||          d           |                      ||           ||                      |d          }|                      ||          d	           |                      ||                      |d
          }|                      ||                     |                      ||                     d S )Nc                 .    |                      d          S )NF	mustcloseget_surrounding_bracketsparsers    r   without_mustclosezGHyperParserTest.test_get_surrounding_bracket.<locals>.without_mustclosey   s     22U2CCCr   c                 .    |                      d          S )NTrS   rU   rW   s    r   with_mustclosezDHyperParserTest.test_get_surrounding_bracket.<locals>.with_mustclose~   s     22T2BBBr   z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)r6   assertIsNoneassertTupleEqual)r   rD   rY   r[   rF   s        r   test_get_surrounding_bracketz,HyperParserTest.test_get_surrounding_bracketv   s   o	D 	D 	D
	C 	C 	C
 CJJ..++,,,++A..///CJJ//22ODDD//22NN14E4EFFFCKK//224DEEE//22NN14E4EFFFCKK//224DEEE..++,,,CLL..++,,,++A../////r   c                 &   | j         } |d          }|                     |                                d            |d          }|                     t                    5 }|                                 d d d            n# 1 swxY w Y   |                     dt          |j                              |d          }|                     |                                d            |d          }|                     |                                d            |d	          }|                     |                                d
            |d          }|                     |                                d            |d          }|                     |                                d            |d          }|                     |                                d            |d          }|                     t                    5 }|                                 d d d            n# 1 swxY 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é)r6   rB   get_expressionr<   r=   r?   r@   rA   )r   rD   rF   rE   s       r   test_get_expressionz#HyperParserTest.test_get_expression   s   oCJJ))++T222CJJz** 	b	 	 	 	 	 	 	 	 	 	 	 	 	 	 	(#bl*;*;<<<CKK))++[999CJJ))++T222CJJ))++R000CJJ))++T222CLL))++[999CKK))++Y777CKKz** 	b	 	 	 	 	 	 	 	 	 	 	 	 	 	 	(#bl*;*;<<<CKK))++R000CKK))++R000CLL))++R000CKK))++R000CLL))++W555CKK))++Y77777s$    BBBH,,H03H0c                 2   d }|                       |d                     |                      |d                     |                      |d                     |                      |d                     |                      |d                     |                      |d                     |                      |d                     |                      |d	                     |                       |d
                     |                       |d                     |                       |d                     |                      |d                     |                      |d                     |                      |d                     |                       |d                     |                       |d                     |                       |d                     |                     t          j        ddd          t          d                     |                     t          j        ddd          t          d                     |                     t          j        ddd          t          d                     |                       |d                     |                       |d                     |                       |d                     |                       |d                     |                       |d                     |                       |d                     |                       |d                      |                       |d!                     d S )"Nc                     t          j        | 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_msgs      r   is_valid_idz8HyperParserTest.test_eat_identifier.<locals>.is_valid_id   sp     0As9~~NNFY''t1uCJJC	NN   (((r   2notidvalid_id	_valid_id	valid_id_
_2valid_idTruerb   Noneforimportreturnclicherc   u   a٢2au   ٢au   a²z+ varr      varz+varr;   z.var+ :?^\"z
"a string")rI   rK   rB   r   rh   ri   )r   ro   s     r   test_eat_identifierz#HyperParserTest.test_eat_identifier   s   
	) 
	) 
	) 	X../// 	J//000K00111K00111L11222 	F++,,,G,,---F++,,, 	U++,,,X..///X../// 	H--...I..///E**+++ 	T**+++U++,,,U++,,, 	4WaCCSZZPPP4VQBBCJJOOO4VQBBCJJOOO 	S))***S))***S))***S))***S))***T**+++S))***\2233333r   c           	         t           j        }t          dd          D ]k}|                      |d|z  d|          |           |                      |d|z  d|          |           |                      |dd|dz
  z  z   d|          |           |                      |dd|dz
  z  z   d|          |           |                      |dd|dz
  z  z   d|          |           |                      |d|dz
  z  dz   d|          |           |                      |d|z  d|          d           |                      |dd|dz
  z  z   d|          d           |                      |dd|dz
  z  z   d|          d           md S )N      ar      é2r~   )r   rh   rangerB   )r   eat_idlengths      r   #test_eat_identifier_various_lengthsz3HyperParserTest.test_eat_identifier_various_lengths  s   ,Arll 		N 		NFVVC&L!V<<fEEEVVD6M1f==vFFFVVC#!*<$<aHH&QQQVVD3&1*+=$=q&II6RRRVVD3&1*+=$=q&II6RRRVVDFQJ$7#$=q&II6RRRVVC&L!V<<a@@@VVC#!*<$<aHH!LLLVVC$&1**=$=q&II1MMMM		N 		Nr   N)r   r   r   r,   classmethodr&   r)   r.   r3   r6   rG   rM   rP   r_   re   r   r   r   r   r   r   r      s        H 	 - - [-   [
. . .. . .0 0 0$ $ $(* * *$) ) ) 0 0 0B28 28 28h74 74 74rN N N N Nr   r   __main__   )	verbosity)__doc__idlelib.hyperparserr   unittesttest.supportr   tkinterr   r   idlelib.editorr   r	   TestCaser   r   mainr   r   r   <module>r      s    ! ! + + + + + +  ! ! ! ! ! !         ' ' ' ' ' '	7 	7 	7 	7 	7 	7 	7 	7{N {N {N {N {Nh' {N {N {N| zHMA r   