a
    VŸ$c‘  ã                   @   sª   d dl mZmZmZmZmZ d dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZ d dlm  mZ d dlZdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Zdd„ ZdS )é    )ÚdivisionÚabsolute_importÚwith_statementÚprint_functionÚunicode_literals)ÚPY2Ú
basestringÚbchrÚbordÚchrÚopenÚpystrÚrangeÚroundÚstrÚtobytesÚunicodeNc                 C   s^   t  ||¡}|  d¡r*t|  | j¡ƒ|_q|  d¡rD|  | j¡|_q|  d¡rZd|_	qqZq|S )NÚbuttonÚposÚalwaysT)
ÚtestastÚClickÚkeywordÚintÚrequireÚintegerr   Úsimple_expressionÚpositionr   )ÚlÚlocÚtargetÚrv© r"   úrenpy/test\testparser.pyÚparse_click   s    


r$   c                 C   sH   t  ||¡}|  d¡r&|  | j¡|_q|  d¡rD|  | j¡|_qqDq|S )NÚpatternr   )r   ÚTyper   r   Ústringr%   r   r   )r   r   Úkeysr!   r"   r"   r#   Ú
parse_type3   s    

r)   c                 C   s:   t  |¡}|  | j¡|_|  d¡r6|  | j¡|_qq6q|S )Nr%   )r   ÚMover   r   r   r   r'   r%   )r   r   r!   r"   r"   r#   Ú
parse_moveD   s    

r+   c                 C   sv   |   | j¡}t ||¡}|  d¡r6t|   | j¡ƒ|_q|  d¡rP|   | j¡|_	q|  d¡rrt|   | j¡ƒ|_
qqrq|S )Nr   r%   Ústeps)r   r   r   ÚDragr   r   r   r   r'   r%   r,   )r   r   Úpointsr!   r"   r"   r#   Ú
parse_dragT   s    


r/   c                 C   s<  |   d¡r"|  | j¡}t ||¡S |   d¡rD|  | j¡}t ||¡S |   d¡rf|  | j¡}t ||¡S |   d¡rª|  ¡ }|d urŽt| ||gƒS |  | j	¡}t| |t
|ƒƒS |   d¡r¾t| |ƒS |   d¡rÒt| |ƒS |   d¡rèt| |d ƒS |   d¡r|  | j	¡}t ||¡S |  	¡ }|r&t| ||ƒS |  d	¡ t ||¡S )
NÚrunÚpauseÚlabelÚtypeÚdragÚmoveÚclickÚscrollz-Expected a test language statement or clause.)r   r   r   r   ÚActionÚPauseÚnameÚLabelr)   r'   Úlistr/   r+   r$   ÚScrollÚerrorr   )r   r   Úexprr:   r'   r%   r    r"   r"   r#   Úparse_clausej   s:    









r@   c           	      C   s\  |   d¡r@|  d¡ |  d¡ |  ¡ }tj ||¡}t ||¡S |   d¡r†|  d¡ t	| |ƒ}|  d¡ t
|  d¡|ƒ}t |||¡S |  d¡ |  d¡rÀ|  | j¡}tj ||¡}t ||¡S |   d	¡râ|  | j¡}t ||¡S |   d
¡r|  | j¡}t ||¡S |   d¡r*|  | j¡}t ||¡S t	| |ƒ}|   d¡rXt	| |ƒ}t |||¡}|S )NÚpythonú:zpython blockÚifzif blockFÚ	statementz\$ÚassertÚjumpÚcallÚuntil)r   r   Úexpect_blockÚpython_blockÚrenpyÚastÚPyCoder   ÚPythonr@   Úparse_blockÚsubblock_lexerÚIfÚexpect_noblockÚmatchÚrestÚAssertr:   ÚJumpÚCallÚUntil)	r   r   ÚsourceÚcodeÚ	conditionÚblockr    r!   Úrightr"   r"   r#   Úparse_statement›   s>    











r^   c                 C   s:   g }|   ¡ r.t| |  ¡ ƒ}| |¡ |  ¡  qt ||¡S )z6
    Parses a named block of testcase statements.
    )Úadvancer^   Úget_locationÚappendÚ
expect_eolr   ÚBlock)r   r   r\   Ústmtr"   r"   r#   rO   Ñ   s    

rO   )Ú
__future__r   r   r   r   r   Úrenpy.compatr   r   r	   r
   r   r   r   r   r   r   r   r   Úrenpy.test.testastÚtestr   rK   r$   r)   r+   r/   r@   r^   rO   r"   r"   r"   r#   Ú<module>   s   816