
    z%iK                         	 d dl mZ d dlZd dlmZ  G d dej
                        Z G d dej
                        Zedk(  r ej                  d	
       yy)    )pyparseN)
namedtuplec                       e Zd Zd Zd Zy)ParseMapTestc                 T   dD ci c]  }t        |      t        |       }}t        j                  |      }| j                  |t        d         t        d             | j                  |t        d         t        d             | j                  |d   t        d             y c c}w )Nz 	
	axi  )ordr   ParseMapassertEqual)selfc	keepwhitemappings       R/home/uftp/.pyenv/versions/3.12.0/lib/python3.12/idlelib/idle_test/test_pyparse.pytest_parsemapzParseMapTest.test_parsemap
   s    -67SVSV^7	7""9-T+SY7S*CH5C1	 8s   B%c                     t        j                  dd      }| j                  dj                  t         j                        d       y )N   z	 a([{b}])b"c'd
zxxx(((x)))x"x'x
)r   Parserr   	translatetrans)r   parsers     r   
test_transzParseMapTest.test_trans   s5    1%.88G-	/    N)__name__
__module____qualname__r   r    r   r   r   r      s    2/r   r   c                       e 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 Zd Zd Zd Zy)PyParseTestc                 <    t        j                  dd      | _        y )Nr   )indentwidthtabwidth)r   r   r   clss    r   
setUpClasszPyParseTest.setUpClass   s    ^^A>
r   c                     | ` y N)r   r%   s    r   tearDownClasszPyParseTest.tearDownClass   s    Jr   c                     | j                  | j                  j                  d       | j                  | j                  j                  d       y )Nr   )r   r   r#   r$   )r   s    r   	test_initzPyParseTest.test_init"   s6    00!4--q1r   c                 l   | j                   }| j                  }|j                  }| j                  t              5   |d       d d d        d}|D ]K  }| j                  |      5   ||        ||j                  |        ||j                  d       d d d        M y # 1 sw Y   \xY w# 1 sw Y   dxY w)Nr	   ) a
stringr   )r   r   set_codeassertRaisesAssertionErrorsubTestcodestudy_level)r   eqpsetcodetestsr1   s         r   test_set_codezPyParseTest.test_set_code&   s    KK** ~. 	CL	  	%FV, %1666"1==!$% %	%	 	% %s   	B$/B*B'*B3	c                 
   | j                   }| j                  }|j                  }|j                  }d } |d        | ||      d        |d        | ||      d        |d       d\  }| j	                  t
              5   |        d d d        | j	                  t
              5   |d       d d d        | j                   |d 	              | ||              | |fd
	              | |fd	      |        | |fd	      d         |d        | ||              | |fd	              | |fd	      |        | |fd	             y # 1 sw Y   xY w# 1 sw Y   xY w)Nc                      y)NFr   indexs    r   char_in_string_falsezDPyParseTest.test_find_good_parse_start.<locals>.char_in_string_false=   s    r   zdef spam():
r   zclass spam(  
k"""This is a module docstring"""
class C:
    def __init__(self, a,
                 b=True):
        pass
)!   *   Fc                      y)NTr   r?   s    r   <lambda>z8PyParseTest.test_find_good_parse_start.<locals>.<lambda>[   s    r   )is_char_in_stringc                     | kD  S r)   r   r@   poss    r   rF   z8PyParseTest.test_find_good_parse_start.<locals>.<lambda>c        r   c                     | k\  S r)   r   rI   s    r   rF   z8PyParseTest.test_find_good_parse_start.<locals>.<lambda>f       # r   c                     | k  S r)   r   rI   s    r   rF   z8PyParseTest.test_find_good_parse_start.<locals>.<lambda>i   rK   r   zZ"""This is a module docstring"""
class C:
    def __init__(self, a, b=True):
        pass
c                     | kD  S r)   r   rI   s    r   rF   z8PyParseTest.test_find_good_parse_start.<locals>.<lambda>s   rK   r   c                     | k\  S r)   r   rI   s    r   rF   z8PyParseTest.test_find_good_parse_start.<locals>.<lambda>t   rM   r   c                     | k  S r)   r   rI   s    r   rF   z8PyParseTest.test_find_good_parse_start.<locals>.<lambda>w   rK   r   )r   r   r2   find_good_parse_startr3   	TypeErrorassertIsNone)r   r8   r9   r:   startrA   pos0rJ   s          @r   test_find_good_parse_startz&PyParseTest.test_find_good_parse_start8   s   KK**''5 	 
5%&* 	&'
5%&* 	 ! 	 	c y) 	G	y) 	%L	
 	%2DEF 	5%&, 	5#<=sC 	5#=>E 	5#<=tD 	 ! 	
 	5%&,
5#<=sC
5#=>E 	5#<=sCG	 		 	s   E-*	E9-E69Fc                 v   d}d}| j                   }|j                  |       | j                  t              5  |j	                  d       d d d        |j	                  d       | j                  |j                  |       |j	                  |       | j                  |j                  ||d         y # 1 sw Y   gxY w)NrB   rD      r   )r   r2   r3   r4   set_lor   r6   )r   r6   rJ   r9   s       r   test_set_lozPyParseTest.test_set_loy   s    ! 	 KK	

4 ~. 	HHQK	 	
& 	
cd,	 	s   B//B8c                    | j                   }| j                  }|j                  }|j                  }t	        d      \  }}}}}	t        dg d      }
 |
ddg|       |
dddg|       |
dddg|       |
d	ddg|       |
d
ddg|       |
dddg|       |
dddg|       |
dddg|       |
dddg|       |
dddg|       |
dg d|       |
dddg|       |
dddg|	       |
dddg|       |
dddg|       |
dg d|       |
dg d|	       |
dg d|	       |
dddg|       |
dddg|	       |
dddg|      f}|D ]  }| j                  |j                        5   ||j                          |         ||j                  d        ||j                  |j                          ||j                  |j                         d d d         | j                   |              y # 1 sw Y   xY w)NrY   TestInfo)r1   	goodlinescontinuationr.   r   z$"""This is a complete docstring."""
   z$'''This is a complete docstring.'''
z""""This is a continued docstring.
z"'''This is a continued docstring.
z""""Closing quote does not match."
z"""Bracket in docstring [
z#'''Incomplete two line docstring.

   z"This is a complete string."
z"This is an incomplete string.
z'This is more incomplete.

)r   r`   ra   z# Comment\
z"("""Complete string in bracket"""
z("""Open string in bracket
a = (1 + 2) - 5 *\
0
   def function1(self, a,
                 b):
)r   r`      
   def function1(self, a,\

   def function1(self, a,
())
)(
{)(]
r0   )r   r   r2   _study1ranger   r5   r1   r7   r^   r_   rT   )r   r8   r9   r:   studyNONE	BACKSLASHFIRSTNEXTBRACKETr]   r;   tests                r   test_study1zPyParseTest.test_study1   s;   KK**		27(/y%wj +; < R!d#<q!fdK<q!fdK:QFEJ:QFEJ:QFEJ2QFEB<q!fdK51vtD7!QF4iF_q!fd3:QFGL3aVUC,q!fi@J&6	7K4iIWq!fd+VaVW-X1vt,7<  	6DT[[1 6$1==!$1;;/1>>4#4#456 6	6 	%'"6 6s   A'G!!G*	c                    | j                   }| j                  }|j                  }|j                  }t	        d      \  }}}}}	t        dddg      }
 |
d|       |
d|       |
d|       |
d|       |
d	|	      f}|D ]Q  }| j                  |j                  
      5   ||j                          | |       |j                         d d d        S y # 1 sw Y   ^xY w)NrY   r]   r1   r_   r.   z%"""This is a continuation docstring.
z-'''This is a multiline-continued docstring.

rb   re   r0   )	r   r   r2   get_continuation_typerk   r   r5   r1   r_   )r   r8   r9   r:   gettyperm   rn   ro   rp   rq   r]   r;   rr   s                r   test_get_continuation_typez&PyParseTest.test_get_continuation_type   s    KK**))27(/y%wj8^*DER=uEFM,i86@  	1DT[[1 1$79d//01 1	11 1s   +CC	c                    | j                   }| j                  }|j                  }|j                  }t	        dg 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 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d+       |d,dd-d.d d/       |d0dd%d1d d       |d2dddd d      f}|D ]  }| j                  |j                  3      5   ||j                          |         ||j                  d4        ||j                  |j                          ||j                  |j                          ||j                  |j                          ||j                  |j                          ||j                  |j                          d d d         | j#                   |              y # 1 sw Y   xY w)5Nr]   )r1   rU   endlastchopenbracket
bracketingr.   r   r   r   z0'''This is a multiline continuation docstring.

0   ')r~   r   r`   )r   r   z # Comment\
   )r~   r`   r`   )r   r   z #Comment\
rb      *)r~   r   r`   )   r   rc   r`   :)r`   r      r`   ).   r   re      ,r   )r   r   rf      z3
   def function1(self, a,  # End of line comment.
3   )r   r   )r   ra   )r   r`   z7  a = ["first item",
  # Comment line
    "next item",
7      )r~   )r   r`   )   ra   )r   r`   )   ra   )&   r`   )rD   ra   )5   r`   rg   r   ))r~   r   ra   r   rd   r   rh   rd   ()r~   r   r   ri   rY   ]r~   r   r   ra   r`   r   r   z:\a
z\a
r0   ra   )r   r   r2   _study2r   r5   r1   r7   
stmt_startrU   stmt_endry   rz   lastopenbracketposr{   stmt_bracketingr|   rT   )r   r8   r9   r:   rl   r]   r;   rr   s           r   test_study2zPyParseTest.test_study2   ss   KK**		j +H I RAr43IC'@B%B&?A _2tY0 ,C'@B JC'AC 6C%68 4C%68 LC%HJ QC %IJ W3&FHVQ3+CDX3&NP Xq!UD)<T1aT95I%N  		7DT[[1 7$1==!$1<<,1::txx(188T[[)1'')9)9:1$$doo67 7		7 	%'"7 7s   B>G55G?	c                 :   | j                   }| j                  }|j                  }|j                  }t	        dddg      } |dd       |dd       |dd       |d	d
       |dd       |dd       |dd       |dd      f} |d       | j                  t              5   |        d d d        |D ]Q  }| j                  |j                        5   ||j                          | |       |j                         d d d        S y # 1 sw Y   `xY w# 1 sw Y   jxY w)Nr]   r1   linesz[x for x in a]
r`   z[x
for x in a
ra   z[x\
for x in a\
z[x
for x in a
]
rd   z%
"""Docstring comment L1"""
L2
L3
L4
z%
"""Docstring comment L1
L2"""
L3
L4
z&
"""Docstring comment L1\
L2\
L3\
L4\
r   z+

"""Docstring comment L1\
L2\
L3\
L4\
"""
rY   r.   r0   )
r   r   r2   get_num_lines_in_stmtr   r3   
IndexErrorr5   r1   r   )r   r8   r9   r:   getlinesr]   r;   rr   s           r   test_get_num_lines_in_stmtz&PyParseTest.test_get_num_lines_in_stmt  s$   KK****j8W*=>'+'++Q/*A.A1EA1EFJMqQ	 	z* 	J	  	+DT[[1 +$8:tzz*+ +	+	 	+ +s   D+DDD	c                    | j                   }| j                  }|j                  }|j                  }t	        dddg      } |dd       |dd       |dd       |d	d
       |dd
       |dd
       |dd       |dd       |dd       |dd       |dd      f} |d       | j                  t              5   |        d d d        |D ],  } ||j                          | |       |j                         . y # 1 sw Y   ;xY w)Nr]   r1   spaceszdef function1(self, a,
   z
    def function1(self, a,
   z
	def function1(self, a,
z
    def function1(
   z
	def function1(
z
    def function1(  
z2[
"first item",
  # Comment line
    "next item",
r   z4[
  "first item",
  # Comment line
    "next item",
ra   z1["first item",
  # Comment line
    "next item",
r`   z(
r   z(a
zdef function1(self, a, b):
)	r   r   r2   compute_bracket_indentr   r3   r4   r1   r   )r   r8   r9   r:   indentr]   r;   rr   s           r   test_compute_bracket_indentz'PyParseTest.test_compute_bracket_indent1  s   KK**))j8X*>?/45r:3R8-q1+Q//3MqQOQRSKQOUAVQ" 	./~. 	H	  	&DDKK vx%	&	 	s   6C88Dc                    | j                   }| j                  }|j                  }|j                  }d}|D ]J  }| j	                  |      5   ||       | j                  t              5   |        d d d        d d d        L 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      f}|D ]Q  }	| j	                  |	j                        5   ||	j                          | |       |	j                         d d d        S y # 1 sw Y   xY w# 1 sw Y   8xY w# 1 sw Y   wxY w)N)zdef function1(self, a, b\
z    """ (\
za = #\
r0   r]   )r1   r   rb   r   za = 1 + 2 - 5 *\
z    a = 1 + 2 - 5 *\
r   z  a = "spam"\
r   z  a = \
"a"\
z  a = #\
"a"\
rY   za == \
ra   za != \
z\
z    \
z	\
za\
rd   z{}\
z(1 + 2) - 5 *\
)
r   r   r2   compute_backslash_indentr5   r3   r4   r   r1   r   )
r   r8   r9   r:   r   errorsr1   r]   r;   rr   s
             r   test_compute_backslash_indentz)PyParseTest.test_compute_backslash_indentQ  s   KK**++  	FV, &&~6 H 	 j*>?115/33Q7,a0-q1.2+q)+q)&!$*a((A&'1%(A&-q1   	*DT[[1 *$68T[[)* *	*)  .* *s0   
E#(E0E#!+E0E E##E-	0E9	c           
         | j                   }| j                  }|j                  }|j                  }t	        dddg      } |dd       |dd       |dd       |dd	       |d
d	       |dd	       |dd	      f}|D ]Q  }| j                  |j                        5   ||j                          | |       |j                         d d d        S y # 1 sw Y   ^xY w)Nr]   r1   r   r.   	def a():
z
	def a():
r   z    def a():
z    z    def a(
z	
    def a(
z	
    # Comment.
r0   )r   r   r2   get_base_indent_stringr   r5   r1   r   )r   r8   r9   r:   
baseindentr]   r;   rr   s           r   test_get_base_indent_stringz'PyParseTest.test_get_base_indent_stringx  s    KK**--
j8X*>?"b!,+.$/*F3.&1,f50&9  	.DT[[1 .$:<-. .	.. .s   +CC	c                    | j                   }| j                  }| j                  }|j                  }|j                  }t        dddg      } |d|       |d|       |d|       |d|       |d|       |d	|       |d
|       |d|       |d|       |d|       |d|       |d|      f}|D ]O  }| j                  |j                        5   ||j                         |j                   |              d d d        Q y # 1 sw Y   \xY w)Nr]   r1   assert_r   rc   z:
za:
z):
z(:
z":
rf   !def function1(self, a):
    pass
z# A comment:
z"""A docstring:
r0   )	
assertTrueassertFalser   r2   is_block_openerr   r5   r1   r   )	r   yesnor9   r:   openerr]   r;   rr   s	            r   test_is_block_openerz PyParseTest.test_is_block_opener  s    ooKK**""j8Y*?@\3'JCPUC VS!VS!VS!VR 4b9:B?%r*("-("-  	'DT[[1 '$VX&' '	'' 's   )DD	c                 ,   | j                   }| j                  }| j                  }|j                  }|j                  }t        dddg      } |d|       |d|       |d|       |d|       |d|       |d	|       |d
|       |d|       |d|       |d|       |d|       |d|       |d|      f}|D ]O  }| j                  |j                        5   ||j                         |j                   |              d d d        Q y # 1 sw Y   \xY w)Nr]   r1   r   zreturn
z	break
z  continue
z     raise
z	pass    
zpass	
z	return #
zraised
z
returning
z	# return
z	"""break
z
"continue
r   r0   )	r   r   r   r2   is_block_closerr   r5   r1   r   )	r   r   r   r9   r:   closerr]   r;   rr   s	            r   test_is_block_closerz PyParseTest.test_is_block_closer  s%   ooKK**""j8Y*?@Z%[#&^S)^S)\3'Z%\3'Z$]B'\2&\2&]B':C@   	'DT[[1 '$VX&' '	'' 's   )D

D	c                    | j                   }| j                  }|j                  }|j                  }t	        dddg      } |dd       |dd       |dd       |d	d
       |dd       |dd       |dd       |dd       |dd       |dd      f
}|D ]Q  }| j                  |j                        5   ||j                          | |       |j                         d d d        S y # 1 sw Y   ^xY w)Nr]   r1   bracketr.   r}   r/   z()()
r   z(
)()
)r~   r   r   rd   r`   rY   r   z()
()
)r   r   r   z()(
)
)r~   r   r   r   r   z(())
)r~   r   r`   ra   r   r   z(
())
)r~   r   )ra   ra   r   r   ri   z(((())
)r~   r   r   )ra   rd   )rd   r   )rY   rd   )r   ra   r0   )r   r   r2   get_last_stmt_bracketingr   r5   r1   r   )r   r8   r9   r:   r|   r]   r;   rr   s           r   test_get_last_stmt_bracketingz)PyParseTest.test_get_last_stmt_bracketing  s
   KK**//
j8Y*?@R#UI&XGHZ!IJZ!9:Z!IJXGHZ!IJXGHZMO  	/DT[[1 /$:<./ /	// /s   2+C((C1	N)r   r   r   classmethodr'   r*   r,   r<   rW   r[   rs   rw   r   r   r   r   r   r   r   r   r   r   r   r!   r!      st    ? ?  2%$?DB-00#d1*;#z+8&@%*N.*'8':/r   r!   __main__ra   )	verbosity)
idlelibr   unittestcollectionsr   TestCaser   r!   r   mainr   r   r   <module>r      sU       "/8$$ / G/(## G/T zHMMA r   