
    z%i:\                     D   	 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	ej                        Z G d
 dej                        Z G d dej                        Z G d dej                        Z G d dej                        Z G d d      Z G d d      Z G d dej                        Z G d d      Z G d dej                        Z G d dej                        Z G d dej                        Zed k(  r ej8                  d!d!"       yy)#    )formatN)mock)requires)TkText)EditorWindow)Editorc                   4    e Zd Z	 dZdZdZdZdZd Zd Z	d Z
y	)
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                     | j                  t        j                  d             | j                  t        j                  d             | j                  t        j                  | j                               y )N z	
)
assertTrueftis_all_whiteassertFalsetest_commentselfs    Q/home/uftp/.pyenv/versions/3.12.0/lib/python3.12/idlelib/idle_test/test_format.pytest_is_all_whitezIs_Get_Test.test_is_all_white   sI    +,56):):;<    c                 L   | j                   } |t        j                  | j                        d        |t        j                  | j                        d        |t        j                  | j
                        d        |t        j                  | j                        d       y )Nr       )assertEqualr   
get_indentr   trailingws_commentleadingws_commentleadingws_nocommentr   Equals     r   test_get_indentzIs_Get_Test.test_get_indent   sq      bmmD--.3bmmD334b9bmmD223V<bmmD445v>r   c                    | j                   } |t        j                  | j                        d        |t        j                  | j                        d        |t        j                  | j
                        d        |t        j                  | j                        d        |t        j                  | j                        d       y )N#    #r   r   )r   r   get_comment_headerr   r   r   r   test_nocommentr   s     r   test_get_comment_headerz#Is_Get_Test.test_get_comment_header    s      b##D$5$56<b##D$;$;<cBb##D$:$:;WEb##D$<$<=vFb##D$7$78"=r   N)__name__
__module____qualname__r   r&   r   r   r   r   r!   r'    r   r   r   r      s0    )(L,N115=
?>r   r   c                   0    e Zd Z	 ed        Zd Zd Zd Zy)FindTestc                 (    ddl m}  |       | _        y )Nr   )r   )idlelib.idle_test.mock_tkr   text)clsr   s     r   
setUpClasszFindTest.setUpClass5   s    26r   c                 X   | j                   }|j                  d|       t        d|      D ]k  }t        |j	                  d|z        j                  d      d         }d|dz  |fD ]/  }d||fz  }| j                  t        j                  ||      |       1 m |j                  dd       y )	N1.0   z%d.end.r      z%d.%dend)
r0   insertrangeintindexsplitr   r   find_paragraphdelete)	r   
inserttextstoplineexpectedr0   line
linelengthcol	tempindexs	            r   runcasezFindTest.runcase:   s     yyE:&!X& 	ODTZZ48>>sCAFGJ:q=*5 O#tSk1	  !2!24!CXNO	O
 	E5!r   c           
         d}| j                  |dddd|dd f       d}| j                  |d	d
dd|dd f       d}| j                  |d	d
dd|dd f       d}| j                  |dd
dd|dd f       d}| j                  |dd
dd|dd f       d}| j                  |dd
dd|dd f       d}| j                  |dd
dd|dd f       d}| j                  |dd
dd|dd f       y )Nz;# Comment block with no blank lines before
# Comment line

   r4   3.0r#   r   :   zG
# Comment block with whitespace line before and after
# Comment line

   2.04.0r5   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   rG   )r   comments     r   test_find_commentzFindTest.test_find_commentG   sZ    	 	Wa%WQr]!CD 	
 	Wa%WQr]!CD 	
 	Wa%2!GH 	 	Wa%WQr]!CD 	 	Wa%2!GH 	
 	Wa%WQr]!CD 	
 	Wa%2!GH 	
 	Wa%WQr]!CDr   c           
         d}| j                  |dddd|dd f       d}| j                  |d	d
dd|dd f       d}| j                  |d	d
dd|dd f       d}| j                  |dd
dd|dd f       d}| j                  |dd
dd|dd f       y )Nz6"""String with no blank lines before
String line
"""

rL   r4   rN   r   r   rT   zC
"""String with whitespace line before and after
String line.
"""

   rM   z5.0r5   B   zV
    """Indented string with whitespace before and after
    Comment string.
    """

r   U   z
"""Single line string."""

rI   rJ      z8
    """Single line string with leading whitespace."""

7   rV   )r   
teststrings     r   test_find_paragraphzFindTest.test_find_paragraph}   s     	
 	ZUE2z!B7G$HI 	 	ZUE2z!B7G$HI 	 	ZUE6:a;K$LM 	 	ZUE2z!B7G$HI 	 	ZUE6:a;K$LMr   N)r(   r)   r*   classmethodr2   rG   rX   r`   r+   r   r   r-   r-   +   s-      "4El"Nr   r-   c                       e Zd Z	 d Zy)ReformatFunctionTestc                    | 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       y )NzO hello world r5   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   reformat_paragraph)r   r    reformhws       r   test_reformat_paragraphz,ReformatFunctionTest.test_reformat_paragraph   s      &&fS!nc"f%r*N; 	fRm./fRm./fRm-.fRn./fRno. fRm01fRm01fRm/0fRn01fRn/0r   N)r(   r)   r*   rn   r+   r   r   rc   rc      s
    I1r   rc   c                       e Zd Z	 d Zy)ReformatCommentTestc                     | j                   }d}t        j                  |dd      }d} |||       d}t        j                  |dd      }d} |||       y )Nzu    """this is a test of a reformat for a triple quoted string will it reformat to less than 70 characters for me?"""rO   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   reformat_comment)r   r    test_stringresultrB   r   s         r   test_reformat_commentz)ReformatCommentTest.test_reformat_comment   s{      I 	 $$["f=D 	 	fh= 	 $$\2s;< 	 	fhr   N)r(   r)   r*   ru   r+   r   r   rp   rp      s
    G r   rp   c                       e Zd Zd Zy)FormatClassTestc                     t        j                  d      }| j                  |j                  d       |j	                          | j                  |j                  d        y )Neditor)r   FormatParagraphr   editwinclose)r   instances     r   test_init_closezFormatClassTest.test_init_close   sH    %%h/))84))40r   N)r(   r)   r*   r~   r+   r   r   rw   rw      s    1r   rw   c                   $    e Zd Zd Zd Zd Zd Zy)TextWrapperc                 &    t        |      | _        y )N)master)r   r0   )r   r   s     r   __init__zTextWrapper.__init__   s    '	r   c                 .    t        | j                  |      S N)getattrr0   )r   names     r   __getattr__zTextWrapper.__getattr__   s    tyy$''r   c                      y r   r+   r   s    r   undo_block_startzTextWrapper.undo_block_start       r   c                      y r   r+   r   s    r   undo_block_stopzTextWrapper.undo_block_stop   r   r   N)r(   r)   r*   r   r   r   r   r+   r   r   r   r      s    (($#r   r   c                   *    e Zd Zd Zej
                  Zy)r	   c                 $    t        |      | _        y r   )r   r0   )r   roots     r   r   zEditor.__init__   s    %	r   N)r(   r)   r*   r   r   get_selection_indicesr+   r   r   r	   r	      s    &(??r   r	   c                   R    e Zd Z	 dZdZdZed        Zed        Zd Z	d Z
d Zd	 Zy
)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                    t        d       t               | _        | j                  j                          t	        | j                        }|j
                  j
                  | _        t        j                  |      j                  | _	        y )Ngui)r   )
r   r   r   withdrawr	   r0   r   rz   format_paragraph_event	formatter)r1   ry   s     r   r2   zFormatEventTest.setUpClass  sY    4SXX&;;##**62IIr   c                 x    | ` | `| j                  j                          | j                  j	                          | `y r   )r0   r   r   update_idletasksdestroyr1   s    r   tearDownClasszFormatEventTest.tearDownClass  s0    Hcm!!#Hr   c                     | j                   j                  dd       | j                  d       | j                  | j                   j	                  dd      d       | j                   j                  dd       y )Nr4   zShort line
Dummyr9   r8   )r0   r9   r   r   getr?   r   s    r   test_short_linezFormatEventTest.test_short_line   sU    		/wuh7I		&r   c                    | j                   }|j                  d| j                         |j                  dd       | j	                  dd       |j                  dd      }d}| j                  ||       |j                  dd       |j                  d| j                         |j                  dd	d
       | j	                  dd       |j                  dd      }d}| j                  ||       |j                  dd       y )Nr4   r9   ParameterDoesNothingrO   limitzz    '''this is a test of a reformat for a triple quoted string will it
    reformat to less than 70 characters for me?'''
r8   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?''')	r0   r9   rs   mark_setr   r   r   r?   tag_addr   r0   rt   rB   s       r   test_long_linezFormatEventTest.test_long_line&  s    yy 	E4++,h&-R8%*7 	 	*E5! 	E4++,UFG,-R8%*) 	 	*E5!r   c                    | j                   }|j                  d| j                         |j                  ddd       | j	                  dd       |j                  dd      }d	}| j                  ||       |j                  dd
       y )Nr4   r   rM   rN   r   rO   r   r9   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.
r8   )r0   r9   multiline_test_stringr   r   r   r   r?   r   s       r   test_multiple_linesz#FormatEventTest.test_multiple_linesA  sz    yyE4556UE5)-R8%* 	
 	*E5!r   c                    | j                   }|j                  d| j                         | j                  dd       |j	                  dd      }d}| j                  ||       |j                  dd       |j                  d| j                         |j                  dd	d
       | j                  dd       |j	                  dd      }d}| j                  ||       |j                  dd       y )Nr4   r   rO   r   r9   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.
r8   r   rM   rJ   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.
)r0   r9   multiline_test_commentr   r   r   r?   r   r   s       r   test_comment_blockz"FormatEventTest.test_comment_blockP  s    yy 	E4667-R8%*! 	 	*E5! 	E4667UE5)-R8%*/ 	 	*E5!r   N)r(   r)   r*   rs   r   r   ra   r2   r   r   r   r   r   r+   r   r   r   r      sc    	" 
	 	:  J J  '"6""r   r   c                   B    e Zd Zd Zej
                  Zej                  Zy)DummyEditwinc                 X    || _         || _        d| _        d| _        d| _        d| _        y )NrL   FT)r   r0   indentwidthtabwidthusetabscontext_use_ps1)r   r   r0   s      r   r   zDummyEditwin.__init__}  s.    		#r   N)r(   r)   r*   r   r   _make_blanksr   r+   r   r   r   r   |  s     $  ,,L(>>r   r   c                   T   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ej                   j#                  ej&                  d      d        Zej                   j#                  ej&                  d      d        Zej                   j#                  ed      d        Zy)FormatRegionTestc                    t        d       t               | _        | j                  j                          t	        | j                        | _        t        j                         | j
                  _        t        j                         | j
                  _	        t        | j                  | j
                        | _        t        j                  | j                        | _        y )Nr   )r   r   r   r   r   r0   r   Mockr   r   r   ry   r   FormatRegionr   r   s    r   r2   zFormatRegionTest.setUpClass  s    4>$(IIK!#'99; !#((CHH5


3r   c                 |    | ` | `| `| j                  j	                          | j                  j                          | `y r   )r0   r   ry   r   r   r   r   s    r   r   zFormatRegionTest.tearDownClass  4    HcmSZ!!#Hr   c                 P    | j                   j                  d| j                         y )Nr4   )r0   r9   code_sampler   s    r   setUpzFormatRegionTest.setUp  s    		 0 01r   c                 <    | j                   j                  dd       y )Nr4   r8   r0   r?   r   s    r   tearDownzFormatRegionTest.tearDown  s    		&r   a  # 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                    | j                   j                  }| j                  }| j                  }|j	                  ddd       g d} | |       dddj                  |      |f       |j                  ddd        | |       dd	dd
d
gf       y )Nr   7.010.0)r   z    def compare(self):z        if a > b:r   
r4   r8   z15.0z16.0r   )r   
get_regionr0   r   r   join
tag_remove)r   r   r0   eqexpected_liness        r   test_get_regionz FormatRegionTest.test_get_region  s    nn''yy 	UE6* 	355&$))N";^LM 	ue,
35664"b23r   c                    | j                   j                  }| j                  }| j                  }|j                  }t        j                         |_        | j                  j                         d   }| j                  j                         d   }|j                  ddd       | j                   j                         \  }}}	}
 ||||	|
       |j                  j                           ||j                  dd      |	        ||j                  dd      |	       |j                  ddd	       d
}|j                  d      } |dd|	|        ||j                  dd      |        ||j                  dd      |        ||j                  dd      |        ||j                  dd      |       |j                  ddd	       ||_        y )NrZ   	   r   z6.0z11.0z	sel.firstzsel.lastr4   r8   zadded line 1



r   r   r   z7.0-1cz12.0-1c)r   
set_regionr0   r   bellr   r   r   
splitlinesr   r   assert_called_oncer   r   r=   )r   set_r0   r   	save_bellline6line10headtailcharslines	newstringnewliness                r   test_set_regionz FormatRegionTest.test_set_region  s   ~~((yyII	IIK	  ++-a0!!,,.q1UE6*#'>>#<#<#> dE5 	T4&		$$&
488E6"E*
488K,e4ue, +	??4(UFE8,
488K,i8
488E6"I.
488E8$e,
488FI&/ue,	r   c                     | j                   j                  }| j                  }| j                  }|j	                  ddd        |         ||j                  dd      d       y )Nr   r   r   z2
        def compare(self):
            if a > b:
)r   indent_region_eventr0   r   r   r   )r   indentr0   r   s       r   test_indent_region_eventz)FormatRegionTest.test_indent_region_event  sP    33yyUE6*
488E6"%\^r   c                     | j                   j                  }| j                  }| j                  }|j	                  ddd        |         ||j                  dd      d       y )Nr   r   r   z"
def compare(self):
    if a > b:
)r   dedent_region_eventr0   r   r   r   )r   dedentr0   r   s       r   test_dedent_region_eventz)FormatRegionTest.test_dedent_region_event  sP    33yyUE6*
488E6"%LNr   c                     | j                   j                  }| j                  }| j                  }|j	                  ddd        |         ||j                  dd      d       y )Nr   r   r   z0##
##    def compare(self):
##        if a > b:
)r   comment_region_eventr0   r   r   r   )r   rW   r0   r   s       r   test_comment_region_eventz*FormatRegionTest.test_comment_region_event  sP    ..55yyUE6*	
488E6"%Z\r   c                    | j                   j                  }| j                   j                  }| j                  }| j                  }|j                  ddd        |         |         ||j                  dd      d       |j                  ddd       |j                  ddd        |         ||j                  dd	      d
       | j                   j                  dddddg        |         ||j                  dd	      d       y )Nr   r   r   z*
    def compare(self):
        if a > b:
r4   r8   rJ   rN   z3.endz    # Class comment.r   z# Class comment.z Class comment.)	r   r   uncomment_region_eventr0   r   r   r   r   r   )r   rW   	uncommentr0   r   s        r   test_uncomment_region_eventz,FormatRegionTest.test_uncomment_region_event  s    ..55NN99	yyUE6*	
488E6"%TV 	ue,UE5)
488E7#&<>!!%5G4LM
488E7#&79r   _asktabwidthc                 ,   | j                   j                  }| j                  }| j                  }|j	                  ddd       d |_        | j                   |              d|_        | j                   |               ||j                  dd      d       y )Nr   r   r   rI   z$
	 def compare(self):
		  if a > b:
)	r   tabify_region_eventr0   r   r   return_valueassertIsNoneassertIsNotNoner   )r   r   tabifyr0   r   s        r   test_tabify_region_eventz)FormatRegionTest.test_tabify_region_event  s{    33yyUE6*$(!&(#$%!VX&
488E6"%QSr   c                 n   | j                   j                  }| j                  }| j                  }|j	                  ddd       d |_        | j                   |              d|_        | j                   j                          d|_        | j                   |               ||j                  dd      d       y )Nr   r   r   r7   rI   z0
      def compare(self):
            if a > b:
)
r   untabify_region_eventr0   r   r   r   r   r   r   r   )r   r   untabifyr0   r   s        r   test_untabify_region_eventz+FormatRegionTest.test_untabify_region_event)  s    >>77yyUE6*$(!(*%$%!**,$%!XZ(
488E6"%Z\r   
askintegerc                 l    | j                   j                  }d|_        | j                   |       d       y )N
   )r   r   r   r   )r   r   asks      r   test_ask_tabwidthz"FormatRegionTest.test_ask_tabwidth:  s+    nn))"$
#r   N)r(   r)   r*   ra   r2   r   r   r   r   r   r   r   r   r   r   r   patchobjectr   r   r   r   r   r+   r   r   r   r     s    4 4  2'K"4"!F_O]:* 
ZZr7T 8T 
ZZr7] 8]  
ZZr<($ )$r   r   c                       e Zd Zej                  j                  ed      d        Zej                  j                  ed      d        Zy)IndentsTestaskyesnoc                 x   t        d d       }t        j                  |      }d|_        |j	                  d        | j                  |j                  d       | j                  |j                  d       |j	                  d        | j                  |j                  d       | j                  |j                  d       y )NT   F)r   r   Indentsr   toggle_tabs_eventr   r   r   )r   r  ry   indentss       r   test_toggle_tabszIndentsTest.test_toggle_tabsC  s    dD)**V$ $!!$'.++Q/!!$'/++Q/r   r   c                    t        d d       }t        j                  |      }d |_        |j	                  d        | j                  |j                  d       d|_        |j	                  d        | j                  |j                  d       d|_        d|_        |j	                  d        | j                  |j                  d       y )NrL   rI   rZ   T)r   r   r  r   change_indentwidth_eventr   r   r   )r   r   ry   r
  s       r   test_change_indentwidthz#IndentsTest.test_change_indentwidthQ  s    dD)**V$"&
((.++Q/"#
((.++Q/"#
((.++Q/r   N)	r(   r)   r*   r   r  r  r   r  r  r+   r   r   r  r  A  sJ    	ZZr:&0 '0 
ZZr<(0 )0r   r  c                   >    e Zd Zed        Zed        Zd Zd Zd Zy)
RstripTestc                 2   t        d       t               | _        | j                  j                          t	        | j                        | _        t        | j
                        | _        t        j                  | j                        j                  | _
        y )Nr   )r0   )r   r   r   r   r   r0   
MockEditorry   r   Rstrip	do_rstripr   s    r   r2   zRstripTest.setUpClassf  s[    4>SXX.
		#**-77r   c                 |    | ` | `| `| j                  j	                          | j                  j                          | `y r   )r0   r  ry   r   r   r   r   s    r   r   zRstripTest.tearDownClasso  r   r   c                 <    | j                   j                  dd       y )Nr4   end-1cr   r   s    r   r   zRstripTest.tearDownv  s    		)r   c                     d}d}| j                   j                  d|       | j                          | j                  | j                   j	                  dd      |       y )NzLine 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
r4   r9   )r0   r9   r  r   r   )r   originalstrippeds      r   test_rstrip_lineszRstripTest.test_rstrip_linesy  sU     	6 	 			)uh7Br   c                    | j                   }dD ]a  }| j                  |      5  |j                  d|       | j                          | j	                  |j                  dd      d       d d d        c dD ]s  }| j                  |      5  |j                  dd       |j                  d|       | j                          | j	                  |j                  dd      d       d d d        u y # 1 sw Y   xY w# 1 sw Y   xY w)N)r   r   z


)coder4   r  r   )a
za

za


r  )r0   subTestr9   r  r   r   r?   )r   r0   r  s      r   test_rstrip_endzRstripTest.test_rstrip_end  s    yy( 	?D4( ?E4(   %!92>? ?	?
 0 	BD4( BE8,E4(   %!95A	B B	B	? ?
B Bs   AC,
AC8,C5	8D	N)	r(   r)   r*   ra   r2   r   r   r  r   r+   r   r   r  r  d  s9    8 8  *C&Br   r  __main__r7   )	verbosityexit)idlelibr   r   unittestr   test.supportr   tkinterr   r   idlelib.editorr   idlelib.idle_test.mock_idler	   r  TestCaser   r-   rc   rp   rw   r   r   r   r   r  r  r(   mainr+   r   r   <module>r,     s        !  ' <>(## >>tNx   tNn18,, 14 (++  41h'' 1&$ $@ @
t"h'' t"L
? 
?u$x(( u$p 0(##  0F4B"" 4Bn zHMMAA& r   