o
    JAf:\  ã                   @   s@  	 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 )#é    )ÚformatN)Úmock)Úrequires)ÚTkÚText)ÚEditorWindow)ÚEditorc                   @   s:   e 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# 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__r   r   r   r   r   r   r   r   r   r   r   r   r	      s    r	   c                   @   s2   e Zd Z	 edd„ ƒZdd„ Zdd„ Zdd„ Zd	S )
ÚFindTestc                 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   ©r3   )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
"""

r7   r%   r9   r
   r   r?   zC
"""String with whitespace line before and after
String line.
"""

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

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

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

é7   rA   )r   Z
teststringr   r   r   Útest_find_paragraph}   s   ÿÿÿÿÿ"zFindTest.test_find_paragraphN)r   r   r    Úclassmethodr$   r3   rC   rI   r   r   r   r   r!   +   s    	
6r!   c                   @   ó   e Zd Z	 dd„ ZdS )ÚReformatFunctionTestc                 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    rS   r   r   r   r   rL   ¢   ó    rL   c                   @   rK   )ÚReformatCommentTestc                 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Úresultr0   r   r   r   r   Útest_reformat_comment¿   s   ÿÿ
ÿÿz)ReformatCommentTest.test_reformat_commentN)r   r   r    rX   r   r   r   r   rU   ¼   rT   rU   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   rY   Ö   s    rY   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   r`   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 rb   r   r   r   r   r   Úundo_block_startî   ó    zTextWrapper.undo_block_startc                 C   rf   rb   r   r   r   r   r   Úundo_block_stopï   rh   zTextWrapper.undo_block_stopN)r   r   r    ra   re   rg   ri   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 rb   )r_   r"   )r   Úrootr   r   r   ra   ò   s   zEditor.__init__N)r   r   r    ra   r   Úget_selection_indicesr   r   r   r   r   ñ   s    
r   c                   @   sR   e 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 )ÚFormatEventTestzv    '''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)rj   )
r   r   rj   Úwithdrawr   r"   r   r[   Zformat_paragraph_eventÚ	formatter)r#   rZ   r   r   r   r$     s   

zFormatEventTest.setUpClassc                 C   s$   | ` | `| j ¡  | j ¡  | `d S rb   )r"   ro   rj   Ú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*   ro   r   Úgetr/   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*   rV   Zmark_setro   rt   r   r/   Útag_add©r   r"   rW   r0   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%   ry   r8   r9   rv   r:   rw   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_stringrz   ro   rt   r   r/   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%   rv   r:   rw   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)   ry   r8   r5   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_commentro   rt   r   r/   rz   r{   r   r   r   Útest_comment_blockP  s    ÿÿz"FormatEventTest.test_comment_blockN)r   r   r    rV   r}   r   rJ   r$   rs   ru   r|   r~   r€   r   r   r   r   rl   ö   s     ÿÿÿ
	
rl   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 )Nr7   FT)rj   r"   ÚindentwidthZtabwidthÚusetabsZcontext_use_ps1)r   rj   r"   r   r   r   ra   }  s   
zDummyEditwin.__init__N)r   r   r    ra   r   Z_make_blanksrk   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 )Nrm   )r   r   rj   rn   r   r"   r   ÚMockrg   ri   r   rZ   r   ÚFormatRegionro   rr   r   r   r   r$   ‹  s   
zFormatRegionTest.setUpClassc                 C   ó(   | ` | `| `| j ¡  | j ¡  | `d S rb   )r"   ro   rZ   rj   rp   rq   rr   r   r   r   rs   –  ó   

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"   r/   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 )Nry   ú7.0ú10.0)r
   z    def compare(self):z        if a > b:r
   Ú
r%   r)   z15.0z16.0r
   )ro   Ú
get_regionr"   r   rz   ÚjoinÚ
tag_remove)r   rt   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 )NrD   é	   ry   z6.0z11.0z	sel.firstzsel.lastr%   r)   zadded line 1



r‘   r   r   z7.0-1cz12.0-1c)ro   Ú
set_regionr"   r   Zbellr   r…   r‰   Ú
splitlinesrz   r’   Zassert_called_oncert   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 )Nry   r   r   z2
        def compare(self):
            if a > b:
)ro   Zindent_region_eventr"   r   rz   rt   )r   Úindentr"   r•   r   r   r   Útest_indent_region_eventè  ó   z)FormatRegionTest.test_indent_region_eventc                 C   r    )Nry   r   r   z"
def compare(self):
    if a > b:
)ro   Zdedent_region_eventr"   r   rz   rt   )r   Údedentr"   r•   r   r   r   Útest_dedent_region_eventò  r£   z)FormatRegionTest.test_dedent_region_eventc                 C   r    )Nry   r   r   z0##
##    def compare(self):
##        if a > b:
)ro   Úcomment_region_eventr"   r   rz   rt   )r   rB   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 )Nry   r   r   z*
    def compare(self):
        if a > b:
r%   r)   r5   r9   z3.endz    # Class comment.r
   z# Class comment.z Class comment.)	ro   r¦   Zuncomment_region_eventr"   r   rz   rt   r”   r˜   )r   rB   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 )Nry   r   r   r4   z$
	 def compare(self):
		  if a > b:
)	ro   Útabify_region_eventr"   r   rz   Úreturn_valueÚassertIsNoneÚassertIsNotNonert   )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 )Nry   r   r   r(   r4   z0
      def compare(self):
            if a > b:
)
ro   Zuntabify_region_eventr"   r   rz   r«   r¬   rª   r­   rt   )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é
   )ro   r©   r«   r   )r   r°   Zaskr   r   r   Útest_ask_tabwidth:  s   z"FormatRegionTest.test_ask_tabwidthN)r   r   r    rJ   r$   rs   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¶   rZ   Ú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 )Nr7   r4   rD   T)r   r   r¸   r«   Zchange_indentwidth_eventr   r‚   rƒ   )r   r°   rZ   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 )Nrm   )r"   )r   r   rj   rn   r   r"   Ú
MockEditorrZ   r   ZRstripÚ	do_rstriprr   r   r   r   r$   f  s   
zRstripTest.setUpClassc                 C   r‡   rb   )r"   r¾   rZ   rj   rp   rq   rr   r   r   r   rs   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   rt   )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   rt   r/   )r   r"   rÂ   r   r   r   Útest_rstrip_endŒ  s"   ý€ü€ÿzRstripTest.test_rstrip_endN)	r   r   r    rJ   r$   rs   r   rÁ   rÄ   r   r   r   r   r¼   d  s    

r¼   Ú__main__r(   )Ú	verbosityÚexit)Zidlelibr   r   Zunittestr   Ztest.supportr   Útkinterr   r   Zidlelib.editorr   Zidlelib.idle_test.mock_idler   r½   ZTestCaser	   r!   rL   rU   rY   r_   rl   r   r„   rµ   r¼   r   Úmainr   r   r   r   Ú<module>   s2    w  9#7ÿ