o
    JAf:\  ã                   @   sB  d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	m
Z
 ddlmZ ddlmZ G d	d
„ d
ejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dƒZG dd„ dƒZG dd„ dejƒZG dd„ dƒZG dd„ dejƒZG dd„ dejƒZG dd „ d ejƒZed!krŸejd"d"d# dS dS )$zTest format, coverage 99%.é    )ÚformatN)Úmock)Úrequires)ÚTkÚText)ÚEditorWindow)ÚEditorc                   @   s<   e Zd ZdZdZdZdZdZdZdd„ Z	d	d
„ Z
dd„ ZdS )ÚIs_Get_TestzTest the is_ and get_ functionsz# This is a commentzThis is not a commentz# This is a comment   z    # This is a commentz    This is not a commentc                 C   s6   |   t d¡¡ |   t d¡¡ |  t | j¡¡ d S )NÚ z	
)Z
assertTrueÚftZis_all_whiteZassertFalseÚtest_comment©Úself© r   ú4/usr/lib/python3.10/idlelib/idle_test/test_format.pyÚtest_is_all_white   s   zIs_Get_Test.test_is_all_whitec                 C   sR   | j }|t | j¡dƒ |t | j¡dƒ |t | j¡dƒ |t | j¡dƒ d S )Nr
   ú    )ÚassertEqualr   Z
get_indentr   Útrailingws_commentÚleadingws_commentÚleadingws_nocomment©r   ÚEqualr   r   r   Útest_get_indent   s
   zIs_Get_Test.test_get_indentc                 C   sd   | j }|t | j¡dƒ |t | j¡dƒ |t | j¡dƒ |t | j¡dƒ |t | j¡dƒ d S )Nú#ú    #r   r
   )r   r   Zget_comment_headerr   r   r   r   Útest_nocommentr   r   r   r   Útest_get_comment_header    s   z#Is_Get_Test.test_get_comment_headerN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r   r   r   r   r	      s    r	   c                   @   s4   e Zd ZdZedd„ ƒZdd„ Zdd„ Zdd	„ Zd
S )ÚFindTestaa  Test the find_paragraph function in paragraph module.

    Using the runcase() function, find_paragraph() is called with 'mark' set at
    multiple indexes before and inside the test paragraph.

    It appears that code with the same indentation as a quoted string is grouped
    as part of the same paragraph, which is probably incorrect behavior.
    c                 C   s   ddl m} |ƒ | _d S )Nr   )r   )Zidlelib.idle_test.mock_tkr   Útext)Úclsr   r   r   r   Ú
setUpClass5   s   zFindTest.setUpClassc           	      C   s‚   | j }| d|¡ td|ƒD ]*}t| d| ¡ d¡d ƒ}d|d |fD ]}d||f }|  t ||¡|¡ q%q| 	dd¡ d S )	Nú1.0é   z%d.endÚ.r   é   z%d.%dÚend)
r#   ÚinsertÚrangeÚintÚindexÚsplitr   r   Zfind_paragraphÚdelete)	r   Z
inserttextZstoplineÚexpectedr#   ÚlineZ
linelengthÚcolZ	tempindexr   r   r   Úruncase:   s   þzFindTest.runcasec              
   C   s  d}|   |dddd|dd… f¡ d}|   |d	d
dd|dd… f¡ d}|   |d	d
dd|dd… f¡ d}|   |dd
dd|dd… f¡ d}|   |dd
dd|dd… f¡ d}|   |dd
dd|dd… f¡ d}|   |dd
dd|dd… f¡ d}|   |dd
dd|dd… f¡ d S )Nz;# Comment block with no blank lines before
# Comment line

é   r&   ú3.0r   r   é:   zG
# Comment block with whitespace line before and after
# Comment line

é   ú2.0ú4.0r'   éF   zS
    # Indented comment block with whitespace before and after
    # Comment line

r   éR   z
# Single line comment

é   z4
    # Single line comment with leading whitespace

é3   z0
# Comment immediately followed by code
x = 42

é(   z=
    # Indented comment immediately followed by code
x = 42

é5   z=
# Comment immediately followed by indented code
    x = 42

é1   ©r4   )r   Úcommentr   r   r   Útest_find_commentG   s0   ÿÿÿÿÿÿÿÿ"zFindTest.test_find_commentc              
   C   s®   d}|   |dddd|dd… f¡ d}|   |d	d
dd|dd… f¡ d}|   |d	d
dd|dd… f¡ d}|   |dd
dd|dd… f¡ d}|   |dd
dd|dd… f¡ d S )Nz6"""String with no blank lines before
String line
"""

r8   r&   r:   r
   r   r@   zC
"""String with whitespace line before and after
String line.
"""

é   r9   z5.0r'   éB   zV
    """Indented string with whitespace before and after
    Comment string.
    """

r   éU   z
"""Single line string."""

r5   r6   é   z8
    """Single line string with leading whitespace."""

é7   rB   )r   Z
teststringr   r   r   Útest_find_paragraph}   s   ÿÿÿÿÿ"zFindTest.test_find_paragraphN)	r   r   r    r!   Úclassmethodr%   r4   rD   rJ   r   r   r   r   r"   +   s    	
6r"   c                   @   ó   e Zd ZdZdd„ ZdS )ÚReformatFunctionTestz?Test the reformat_paragraph function without the editor window.c                 C   sØ   | j }tj}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 S )NzO hello worldú r'   zHello    worldé   zHello  worldzO
hello
worldé   é   zO hello
worldé   é   z
O hello worldz
O
hello
worldz
O hello
world)r   r   Zreformat_paragraph)r   r   ZreformZhwr   r   r   Útest_reformat_paragraph¥   s    z,ReformatFunctionTest.test_reformat_paragraphN)r   r   r    r!   rT   r   r   r   r   rM   ¢   ó    rM   c                   @   rL   )ÚReformatCommentTestz=Test the reformat_comment function without the editor window.c                 C   sJ   | j }d}t |dd¡}d}|||ƒ d}t |dd¡}d}|||ƒ d S )Nzu    """this is a test of a reformat for a triple quoted string will it reformat to less than 70 characters for me?"""r;   r   zy    """this is a test of a reformat for a triple quoted string will it
    reformat to less than 70 characters for me?"""zm# this is a test of a reformat for a triple quoted string will it reformat to less than 70 characters for me?r   zo# this is a test of a reformat for a triple quoted string will it
# reformat to less than 70 characters for me?)r   r   Zreformat_comment)r   r   Útest_stringÚresultr1   r   r   r   r   Útest_reformat_comment¿   s   ÿÿ
ÿÿz)ReformatCommentTest.test_reformat_commentN)r   r   r    r!   rY   r   r   r   r   rV   ¼   rU   rV   c                   @   s   e Zd Zdd„ ZdS )ÚFormatClassTestc                 C   s2   t  d¡}|  |jd¡ | ¡  |  |jd ¡ d S )NÚeditor)r   ÚFormatParagraphr   ZeditwinÚclose)r   Úinstancer   r   r   Útest_init_close×   s   
zFormatClassTest.test_init_closeN)r   r   r    r_   r   r   r   r   rZ   Ö   s    rZ   c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚTextWrapperc                 C   s   t |d| _d S )N)Úmaster)r   r#   )r   ra   r   r   r   Ú__init__ê   s   zTextWrapper.__init__c                 C   s   t | j|ƒS ©N)Úgetattrr#   )r   Únamer   r   r   Ú__getattr__ì   s   zTextWrapper.__getattr__c                 C   ó   d S rc   r   r   r   r   r   Úundo_block_startî   ó    zTextWrapper.undo_block_startc                 C   rg   rc   r   r   r   r   r   Úundo_block_stopï   ri   zTextWrapper.undo_block_stopN)r   r   r    rb   rf   rh   rj   r   r   r   r   r`   é   s
    r`   c                   @   s   e Zd Zdd„ ZejZdS )r   c                 C   s   t |ƒ| _d S rc   )r`   r#   )r   Úrootr   r   r   rb   ò   s   zEditor.__init__N)r   r   r    rb   r   Úget_selection_indicesr   r   r   r   r   ñ   s    
r   c                   @   sT   e Zd ZdZd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S )ÚFormatEventTestz­Test the formatting of text inside a Text widget.

    This is done with FormatParagraph.format.paragraph_event,
    which calls functions in the module as appropriate.
    zv    '''this is a test of a reformat for a triple quoted string will it reformat to less than 70 characters for me?'''
a      '''The first line is under the max width.
    The second line's length is way over the max width. It goes on and on until it is over 100 characters long.
    Same thing with the third line. It is also way over the max width, but FormatParagraph will fix it.
    '''
a,  # The first line is under the max width.
# The second line's length is way over the max width. It goes on and on until it is over 100 characters long.
# Same thing with the third line. It is also way over the max width, but FormatParagraph will fix it.
# The fourth line is short like the first line.c                 C   sB   t dƒ tƒ | _| j ¡  t| jd}|jj| _t |¡j| _	d S )NÚgui)rk   )
r   r   rk   Úwithdrawr   r#   r   r\   Zformat_paragraph_eventÚ	formatter)r$   r[   r   r   r   r%     s   

zFormatEventTest.setUpClassc                 C   s$   | ` | `| j ¡  | j ¡  | `d S rc   )r#   rp   rk   Úupdate_idletasksÚdestroy©r$   r   r   r   ÚtearDownClass  s   

zFormatEventTest.tearDownClassc                 C   s@   | j  dd¡ |  d¡ |  | j  dd¡d¡ | j  dd¡ d S )Nr&   zShort line
ZDummyr+   r*   )r#   r+   rp   r   Úgetr0   r   r   r   r   Útest_short_line   s   
zFormatEventTest.test_short_linec                 C   s¬   | j }| d| j¡ | dd¡ | jddd | dd¡}d}|  ||¡ | dd¡ | d| j¡ | dd	d
¡ | jddd | dd¡}d}|  ||¡ | dd¡ d S )Nr&   r+   ÚParameterDoesNothingr;   ©Úlimitzz    '''this is a test of a reformat for a triple quoted string will it
    reformat to less than 70 characters for me?'''
r*   Úselz1.11z1.endzv    '''this is a test of a reformat for a triple quoted string will it reformat
 to less than 70 characters for me?''')	r#   r+   rW   Zmark_setrp   ru   r   r0   Útag_add©r   r#   rX   r1   r   r   r   Útest_long_line&  s"   ÿÿzFormatEventTest.test_long_linec                 C   s\   | j }| d| j¡ | ddd¡ | jddd | dd¡}d	}|  ||¡ | dd
¡ d S )Nr&   rz   r9   r:   rw   r;   rx   r+   zà    The second line's length is way over the max width. It goes on and
    on until it is over 100 characters long. Same thing with the third
    line. It is also way over the max width, but FormatParagraph will
    fix it.
r*   )r#   r+   Úmultiline_test_stringr{   rp   ru   r   r0   r|   r   r   r   Útest_multiple_linesA  s   ÿz#FormatEventTest.test_multiple_linesc                 C   s    | j }| d| j¡ | jddd | dd¡}d}|  ||¡ | dd¡ | d| j¡ | dd	d
¡ | jddd | dd¡}d}|  ||¡ | dd¡ d S )Nr&   rw   r;   rx   r+   a/  # The first line is under the max width. The second line's length is
# way over the max width. It goes on and on until it is over 100
# characters long. Same thing with the third line. It is also way over
# the max width, but FormatParagraph will fix it. The fourth line is
# short like the first line.
r*   rz   r9   r6   z™# The first line is under the max width.
# The second line's length is way over the max width. It goes on and
# on until it is over 100 characters long.
)r#   r+   Úmultiline_test_commentrp   ru   r   r0   r{   r|   r   r   r   Útest_comment_blockP  s    ÿÿz"FormatEventTest.test_comment_blockN)r   r   r    r!   rW   r~   r€   rK   r%   rt   rv   r}   r   r   r   r   r   r   rm   ö   s     ÿÿÿ
	
rm   c                   @   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 )Nr8   FT)rk   r#   ÚindentwidthZtabwidthÚusetabsZcontext_use_ps1)r   rk   r#   r   r   r   rb   }  s   
zDummyEditwin.__init__N)r   r   r    rb   r   Z_make_blanksrl   r   r   r   r   r‚   |  s    
r‚   c                   @   s®   e Zd Zedd„ ƒZedd„ ƒZdd„ Zdd„ Zd	Zd
d„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zej ejd¡dd„ ƒZej ejd¡dd„ ƒZej ed¡dd„ ƒZdS )ÚFormatRegionTestc                 C   s`   t dƒ tƒ | _| j ¡  t| jƒ| _t ¡ | j_t ¡ | j_	t
| j| jƒ| _t | j¡| _d S )Nrn   )r   r   rk   ro   r   r#   r   ÚMockrh   rj   r‚   r[   r   ÚFormatRegionrp   rs   r   r   r   r%   ‹  s   
zFormatRegionTest.setUpClassc                 C   ó(   | ` | `| `| j ¡  | j ¡  | `d S rc   )r#   rp   r[   rk   rq   rr   rs   r   r   r   rt   –  ó   

zFormatRegionTest.tearDownClassc                 C   s   | j  d| j¡ d S )Nr&   )r#   r+   Úcode_sampler   r   r   r   ÚsetUp  s   zFormatRegionTest.setUpc                 C   ó   | j  dd¡ d S )Nr&   r*   ©r#   r0   r   r   r   r   ÚtearDown   ó   zFormatRegionTest.tearDowna  # WS line needed for test.
class C1:
    # Class comment.
    def __init__(self, a, b):
        self.a = a
        self.b = b

    def compare(self):
        if a > b:
            return a
        elif a < b:
            return b
        else:
            return None
c                 C   sn   | j j}| j}| j}| ddd¡ g d¢}||ƒ ddd |¡|fƒ | ddd¡ ||ƒ dd	dd
d
gfƒ d S )Nrz   ú7.0ú10.0)r
   z    def compare(self):z        if a > b:r
   Ú
r&   r*   z15.0z16.0r
   )rp   Ú
get_regionr#   r   r{   ÚjoinÚ
tag_remove)r   ru   r#   ÚeqZexpected_linesr   r   r   Útest_get_region´  s   z FormatRegionTest.test_get_regionc                 C   s&  | j j}| j}| j}|j}t ¡ |_| j ¡ d }| j ¡ d }| 	ddd¡ | j  
¡ \}}}	}
||||	|
ƒ |j ¡  || dd¡|	ƒ || dd¡|	ƒ | ddd	¡ d
}| d¡}|dd|	|ƒ || dd¡|ƒ || dd¡|ƒ || dd¡|ƒ || dd¡|ƒ | ddd	¡ ||_d S )NrE   é	   rz   z6.0z11.0z	sel.firstzsel.lastr&   r*   zadded line 1



r’   r   r‘   z7.0-1cz12.0-1c)rp   Ú
set_regionr#   r   Zbellr   r†   rŠ   Ú
splitlinesr{   r“   Zassert_called_onceru   r•   r/   )r   Zset_r#   r–   Z	save_bellZline6Zline10ÚheadÚtailÚcharsÚlinesZ	newstringÚnewlinesr   r   r   Útest_set_regionÅ  s.   



z FormatRegionTest.test_set_regionc                 C   ó>   | j j}| j}| j}| ddd¡ |ƒ  || dd¡dƒ d S )Nrz   r   r‘   z2
        def compare(self):
            if a > b:
)rp   Zindent_region_eventr#   r   r{   ru   )r   Úindentr#   r–   r   r   r   Útest_indent_region_eventè  ó   z)FormatRegionTest.test_indent_region_eventc                 C   r¡   )Nrz   r   r‘   z"
def compare(self):
    if a > b:
)rp   Zdedent_region_eventr#   r   r{   ru   )r   Údedentr#   r–   r   r   r   Útest_dedent_region_eventò  r¤   z)FormatRegionTest.test_dedent_region_eventc                 C   r¡   )Nrz   r   r‘   z0##
##    def compare(self):
##        if a > b:
)rp   Úcomment_region_eventr#   r   r{   ru   )r   rC   r#   r–   r   r   r   Útest_comment_region_eventü  s   z*FormatRegionTest.test_comment_region_eventc                 C   s®   | j j}| j j}| j}| j}| ddd¡ |ƒ  |ƒ  || dd¡dƒ | ddd¡ | ddd¡ |ƒ  || dd	¡d
ƒ | j  dddddg¡ |ƒ  || dd	¡dƒ d S )Nrz   r   r‘   z*
    def compare(self):
        if a > b:
r&   r*   r6   r:   z3.endz    # Class comment.r
   z# Class comment.z Class comment.)	rp   r§   Zuncomment_region_eventr#   r   r{   ru   r•   r™   )r   rC   Z	uncommentr#   r–   r   r   r   Útest_uncomment_region_event  s   z,FormatRegionTest.test_uncomment_region_eventÚ_asktabwidthc                 C   s\   | j j}| j}| j}| ddd¡ d |_|  |ƒ ¡ d|_|  |ƒ ¡ || dd¡dƒ d S )Nrz   r   r‘   r5   z$
	 def compare(self):
		  if a > b:
)	rp   Útabify_region_eventr#   r   r{   Úreturn_valueÚassertIsNoneÚassertIsNotNoneru   )r   rª   Ztabifyr#   r–   r   r   r   Útest_tabify_region_event  s   z)FormatRegionTest.test_tabify_region_eventc                 C   sl   | j j}| j}| j}| ddd¡ d |_|  |ƒ ¡ d|_| j  ¡  d|_|  |ƒ ¡ || 	dd¡dƒ d S )Nrz   r   r‘   r)   r5   z0
      def compare(self):
            if a > b:
)
rp   Zuntabify_region_eventr#   r   r{   r¬   r­   r«   r®   ru   )r   rª   Zuntabifyr#   r–   r   r   r   Útest_untabify_region_event)  s   
z+FormatRegionTest.test_untabify_region_eventÚ
askintegerc                 C   s    | j j}d|_|  |ƒ d¡ d S )Né
   )rp   rª   r¬   r   )r   r±   Zaskr   r   r   Útest_ask_tabwidth:  s   z"FormatRegionTest.test_ask_tabwidthN)r   r   r    rK   r%   rt   r‹   rŽ   rŠ   r—   r    r£   r¦   r¨   r©   r   ÚpatchÚobjectr   r‡   r¯   r°   r³   r   r   r   r   r…   ‰  s(    


#

	

r…   c                   @   s8   e Zd Zej ed¡dd„ ƒZej ed¡dd„ ƒZdS )ÚIndentsTestÚaskyesnoc                 C   sj   t d d ƒ}t |¡}d|_| d ¡ |  |jd¡ |  |jd¡ | d ¡ |  |jd¡ |  |jd¡ d S )NTé   F)r‚   r   ÚIndentsr¬   Ztoggle_tabs_eventr   r„   rƒ   )r   r·   r[   Úindentsr   r   r   Útest_toggle_tabsC  s   



zIndentsTest.test_toggle_tabsr±   c                 C   sx   t d d ƒ}t |¡}d |_| d ¡ |  |jd¡ d|_| d ¡ |  |jd¡ d|_d|_| d ¡ |  |jd¡ d S )Nr8   r5   rE   T)r‚   r   r¹   r¬   Zchange_indentwidth_eventr   rƒ   r„   )r   r±   r[   rº   r   r   r   Útest_change_indentwidthQ  s   




z#IndentsTest.test_change_indentwidthN)	r   r   r    r   r´   rµ   r   r»   r¼   r   r   r   r   r¶   A  s
    
r¶   c                   @   s<   e Zd Zedd„ ƒZedd„ ƒZdd„ Zdd„ Zd	d
„ ZdS )Ú
RstripTestc                 C   sH   t dƒ tƒ | _| j ¡  t| jƒ| _t| jd| _t 	| j¡j
| _
d S )Nrn   )r#   )r   r   rk   ro   r   r#   Ú
MockEditorr[   r   ZRstripÚ	do_rstriprs   r   r   r   r%   f  s   
zRstripTest.setUpClassc                 C   rˆ   rc   )r#   r¿   r[   rk   rq   rr   rs   r   r   r   rt   o  r‰   zRstripTest.tearDownClassc                 C   rŒ   )Nr&   úend-1cr   r   r   r   r   rŽ   v  r   zRstripTest.tearDownc                 C   s8   d}d}| j  d|¡ |  ¡  |  | j  dd¡|¡ d S )NzˆLine with an ending tab    
Line ending in 5 spaces     
Linewithnospaces
    indented line
    indented line with trailing space 
    
zyLine with an ending tab
Line ending in 5 spaces
Linewithnospaces
    indented line
    indented line with trailing space
r&   r+   )r#   r+   r¿   r   ru   )r   ZoriginalÚstrippedr   r   r   Útest_rstrip_linesy  s   ÿÿzRstripTest.test_rstrip_linesc              	   C   sÒ   | j }dD ],}| j|d | d|¡ |  ¡  |  | dd¡d¡ W d   ƒ n1 s,w   Y  qdD ]2}| j|d" | dd¡ | d|¡ |  ¡  |  | dd¡d¡ W d   ƒ n1 saw   Y  q4d S )N)r
   r’   z


)Úcoder&   rÀ   r
   )úa
za

za


rÄ   )r#   ZsubTestr+   r¿   r   ru   r0   )r   r#   rÃ   r   r   r   Útest_rstrip_endŒ  s"   ý€ü€ÿzRstripTest.test_rstrip_endN)	r   r   r    rK   r%   rt   rŽ   rÂ   rÅ   r   r   r   r   r½   d  s    

r½   Ú__main__r)   )Ú	verbosityÚexit)r!   Zidlelibr   r   Zunittestr   Ztest.supportr   Útkinterr   r   Zidlelib.editorr   Zidlelib.idle_test.mock_idler   r¾   ZTestCaser	   r"   rM   rV   rZ   r`   rm   r‚   r…   r¶   r½   r   Úmainr   r   r   r   Ú<module>   s2    w  9#7ÿ