a
    åzeD-  ã                   @   s  d dl mZ d dlZd dlmZmZmZ d dlmZ d dl	m
Z
mZ d dl	mZ d dlZdd„ Zd	d
„ 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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edkr
ejdd dS )é    )ÚsearchengineN)Ú
BooleanVarÚ	StringVarÚTclError)Ú
messagebox)ÚVarÚMbox)ÚTextc                   C   s   t t_t t_tt_d S ©N)r   Úser   r   r   r   © r   r   ú9/usr/lib/python3.9/idlelib/idle_test/test_searchengine.pyÚsetUpModule   s    r   c                   C   s   t t_ tt_tt_d S r
   )r   r   r   r   r   r   r   r   ÚtearDownModule   s    r   c                   @   s   e Zd Zdd„ ZdS )ÚMockc                 O   s   d S r
   r   )ÚselfÚargsÚkwargsr   r   r   Ú__init__    ó    zMock.__init__N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r      s   r   c                   @   s   e Zd Zdd„ ZdS )ÚGetTestc                 C   sb   t j}tt _zHtƒ }t  |¡}|  |t j¡ |  |j|¡ |  t  |¡|¡ W |t _n|t _0 d S r
   )r   ÚSearchEnginer   ÚgetZassertIsInstanceZassertIsZ_searchengine)r   Zsaved_EngineÚrootÚenginer   r   r   Útest_get$   s    
zGetTest.test_getN)r   r   r   r   r   r   r   r   r   "   s   r   c                   @   s   e Zd Zdd„ ZdS )ÚGetLineColTestc                 C   sH   |   t d¡d¡ |   t d¡d¡ |  ttjd¡ |  ttjd¡ d S )Nú1.0)é   r   z1.11)r!   é   z1.0 lineendÚend)ÚassertEqualr   Zget_line_colZassertRaisesÚ
ValueError©r   r   r   r   Útest_get_line_col2   s    z GetLineColTest.test_get_line_colN)r   r   r   r'   r   r   r   r   r   0   s   r   c                   @   s   e Zd Zdd„ ZdS )ÚGetSelectionTestc                 C   sV   t ƒ }| dd¡ dd„ }||_|  t |¡d¡ dd„ }||_|  t |¡d¡ d S )	Nr    zHello World!c                 S   s    | dkrdS | dkrdS t ‚d S )Nú	sel.firstr    úsel.lastú1.12©r   ©Úsr   r   r   ÚselL   s    z0GetSelectionTest.test_get_selection.<locals>.sel)r    r+   c                 S   s   | dkrdS t ‚d S ©NÚinsertú1.5r,   r-   r   r   r   ÚmarkT   s    z1GetSelectionTest.test_get_selection.<locals>.mark)r2   r2   )ÚmockTextr1   Úindexr$   r   Zget_selection)r   Útextr/   r3   r   r   r   Útest_get_selectionF   s    z#GetSelectionTest.test_get_selectionN)r   r   r   r7   r   r   r   r   r(   9   s   r(   c                   @   s   e Zd Zdd„ ZdS )ÚReverseSearchTestc                 C   s   | j }d}t d¡}|t ||t|ƒ¡ ¡ dƒ |t ||d¡ ¡ dƒ |t ||d¡ ¡ dƒ |t ||d¡ ¡ dƒ |t ||d¡d ƒ d S )	NzHere is an 'is' test text.Úis)é   é   r;   é   )é   é   r>   é   )r$   ÚreÚcompiler   Zsearch_reverseÚlenÚspan)r   ÚEqualÚlineÚprogr   r   r   Útest_search_reverse^   s    
z%ReverseSearchTest.test_search_reverseN)r   r   r   rG   r   r   r   r   r8   \   s   r8   c                   @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚSearchEngineTestc                 C   s   t jd d| _d S )N)r   )r   r   r   r&   r   r   r   ÚsetUpl   s    zSearchEngineTest.setUpc                 C   sþ   | j }| j}|| ¡ dƒ | d¡ || ¡ dƒ || ¡ dƒ |j d¡ || ¡ dƒ || ¡ dƒ |j d¡ || ¡ dƒ || 	¡ dƒ |j
 d¡ || 	¡ dƒ || ¡ dƒ |j d¡ || ¡ dƒ || ¡ dƒ |j d¡ || ¡ dƒ d S )NÚ ÚhelloFr!   Tr   )r   r$   ÚgetpatÚsetpatZisreÚrevarÚsetZiscaseÚcasevarZiswordÚwordvarZiswrapÚwrapvarZisbackÚbackvar©r   r   rD   r   r   r   Útest_is_getq   s(    
zSearchEngineTest.test_is_getc                 C   sJ   | j }| d¡ |  | ¡ d¡ |j d¡ | d¡ |  | ¡ d¡ d S )Nú\sr!   ú\\s)r   Zsetcookedpatr$   rL   rN   rO   )r   r   r   r   r   Útest_setcookedpat   s    

z"SearchEngineTest.test_setcookedpatc                 C   sŽ   | j }| j}|| ¡ dƒ | d¡ || ¡ dƒ |j d¡ || ¡ dƒ |j d¡ | d¡ || ¡ dƒ |j d¡ || ¡ dƒ d S )NrJ   rK   Tz	\bhello\bFrV   rW   )r   r$   ZgetcookedpatrM   rQ   rO   rN   rT   r   r   r   Útest_getcookedpat•   s    

z"SearchEngineTest.test_getcookedpatc                 C   s¼   | j }| j}| d¡ | ¡ }||jt dtj¡jƒ |j 	d¡ | ¡ }||jt d¡jdƒ | d¡ || ¡ d ƒ |t
jjdƒ | d¡ |j 	d¡ || ¡ d ƒ |t
jjdƒ d S )NZHellor!   r   rJ   zError: Empty regular expressionú+z-Error: nothing to repeat
Pattern: +
Offset: 0)r   r$   rM   ZgetprogÚpatternr@   rA   Ú
IGNORECASErP   rO   r   Ú	showerrorÚmessagerN   )r   r   rD   Ztemppatr   r   r   Útest_getprog¥   s&    

ÿ
ÿzSearchEngineTest.test_getprogc                 C   s†   t j}| j}d}d}|| j ||¡d ƒ ||jdƒ d| d }||j|ƒ || j ||d¡d ƒ ||jdƒ |d7 }||j|ƒ d S )Nz[a-zz$unexpected end of regular expressionzRegular expression errorzError: z
Pattern: [a-zr=   z

Offset: 5)r   r]   r$   r   Zreport_errorÚtitler^   )r   r]   rD   ÚpatÚmsgZexpected_messager   r   r   Útest_report_errorº   s    z"SearchEngineTest.test_report_errorN)	r   r   r   rI   rU   rX   rY   r_   rc   r   r   r   r   rH   i   s   rH   c                   @   s    e Zd Zedd„ ƒZdd„ ZdS )Ú
SearchTestc                 C   sN   t ƒ | _d}| j d|¡ t d¡| _t d ¡| _dd„ | j_	dd„ | j_
d S )Nú&First line
Line with target
Last line
r    Útargetc                  W   s   d| fS )NÚfr   ©r   r   r   r   Ú<lambda>Ü   r   z'SearchTest.setUpClass.<locals>.<lambda>c                  W   s   d| fS )NÚbr   rh   r   r   r   ri   Ý   r   )r4   r6   r1   r@   rA   ra   r   r   r   Úsearch_forwardÚsearch_backward©ÚclsZ	test_textr   r   r   Ú
setUpClassÎ   s    ÿzSearchTest.setUpClassc              	   C   sx  | j }| j}|j}| j}| j}|j d ¡ |||ƒd ƒ dd„ }||_||||ƒd||ddddffƒ |j d¡ ||||ƒd||ddddffƒ |j d¡ |j	 d¡ ||||ƒd||ddddffƒ |j	 d¡ d	d
„ }||_||||ƒd||ddddffƒ ||||dƒd||ddddffƒ |j	 d¡ ||||ƒd||ddddffƒ ||||dƒd||ddddffƒ d S )Nc                 S   s   | dkrdS t ‚d S r0   r,   r-   r   r   r   r3   ï   s    z$SearchTest.test_search.<locals>.markrg   r!   r=   TFrj   c                 S   s    | dkrdS | dkrdS t ‚d S )Nr)   z2.10r*   z2.16r,   r-   r   r   r   r/   ü   s    z#SearchTest.test_search.<locals>.selé   é   é
   )
r$   r   Zsearch_textr6   ra   ZpatvarrO   r5   rR   rS   )r   rD   r   Úsearchr6   ra   r3   r/   r   r   r   Útest_searchä   s.        " zSearchTest.test_searchN)r   r   r   Úclassmethodro   rt   r   r   r   r   rd   Ë   s   
rd   c                   @   s0   e Zd Zedd„ ƒZdd„ Zdd„ Zdd„ Zd	S )
ÚForwardBackwardTestc                 C   s`   t  d ¡| _tƒ | _dd„ | j_d}| j d|¡ t d¡| _	d| _
t d¡| _t d¡| _d S )	Nc                 S   s   dS )Nz4.0r   )r5   r   r   r   ri     r   z0ForwardBackwardTest.setUpClass.<locals>.<lambda>re   r    rf   )rp   )rr   rq   Zxyzz\w*)r   r   r   r4   r6   r5   r1   r@   rA   ra   ÚresÚfailpatÚemptypatrm   r   r   r   ro     s    ÿzForwardBackwardTest.setUpClassc                    s   d‡ ‡fdd„	}|S )Nr   c                    s0   ˆ ˆj | ||||ƒ}|r,|d |d  ¡ fS |S )Nr   r!   )r6   rC   )ra   rE   ÚcolÚwrapÚokrw   ©Úfuncr   r   r   rs   #  s    z/ForwardBackwardTest.make_search.<locals>.search)r   r   )r   r~   rs   r   r}   r   Úmake_search"  s    zForwardBackwardTest.make_searchc                 C   s¼   | j }|  | jj¡}| j}|||dddƒ| jƒ |||dddƒ| jƒ |||dddƒd ƒ |||dddƒ| jƒ ||| jdddƒd ƒ ||| jddddd	d
ƒ ||| jdddƒ| jƒ d S )Nr!   r   Té   Frp   rr   é	   ©r|   ©rp   )r   r   )r$   r   r   rk   ra   rw   rx   ry   )r   rD   Zforwardra   r   r   r   Útest_search_forward)  s    z'ForwardBackwardTest.test_search_forwardc                 C   sº   | j }|  | jj¡}| j}|||dddƒ| jƒ |||dddƒ| jƒ |||dddƒd ƒ |||dddƒ| jƒ ||| jdddƒd ƒ ||| jdd	ddd
dƒ ||| jdddƒdƒ d S )Nr€   r=   Trp   r   Frq   r   rr   r‚   rƒ   )rp   )r=   r   )r$   r   r   rl   ra   rw   rx   ry   )r   rD   Zbackwardra   r   r   r   Útest_search_backward:  s    z(ForwardBackwardTest.test_search_backwardN)r   r   r   ru   ro   r   r„   r…   r   r   r   r   rv     s
   
rv   Ú__main__rp   )Ú	verbosity)Zidlelibr   r   ZunittestÚtkinterr   r   r   r   Zidlelib.idle_test.mock_tkr   r   r	   r4   r@   r   r   r   ZTestCaser   r   r(   r8   rH   rd   rv   r   Úmainr   r   r   r   Ú<module>   s$   	#b=C
