B
    u9a                 @   sJ   d dl Z d dlZd dlZd dlZdZG dd dejZedkrFe  dS )    Nzglobal variablec               @   s  e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Z d=d> Z!d?d@ Z"dAdB Z#dCdD Z$dEdF Z%dGdH Z&dIdJ Z'dKdL Z(dMdN Z)dOdP Z*dQdR Z+dSdT Z,dUdV Z-dWdX Z.dYdZ Z/d[d\ Z0d]d^ Z1d_d` Z2dadb Z3dcdd Z4dedf Z5dgdh Z6didj Z7dkdl Z8dmdn Z9dodp Z:dqdr Z;dsS )tTestCasec             C   sJ   xD|D ]<}| j |d& | || t| W d Q R X W d Q R X qW d S )N)str)ZsubTestassertRaisesRegexeval)selfZexception_typeZregexZerror_stringsr    r   "/usr/lib/python3.7/test_fstring.pyassertAllRaise   s    
zTestCase.assertAllRaisec             C   s   G dd d}| }| }t dd ||_| | t| | | d | t|t| | |dd | |dd | t||dd | t||dd d S )Nc               @   s   e Zd Zdd ZdS )z(TestCase.test__format__lookup.<locals>.Xc             S   s   dS )Nclassr   )r   specr   r   r   
__format__   s    z3TestCase.test__format__lookup.<locals>.X.__format__N)__name__
__module____qualname__r   r   r   r   r   X   s   r   c             S   s   dS )Ninstancer   )r   r   r   r   r   <lambda>!       z/TestCase.test__format__lookup.<locals>.<lambda>r
    r   )types
MethodTyper   assertEqualformattype)r   r   xyr   r   r   test__format__lookup   s    zTestCase.test__format__lookupc             C   sR   G dd d}| }d}t |}t|dd}| |j t| | |j d S )Nc               @   s   e Zd Zdd Zdd ZdS )zTestCase.test_ast.<locals>.Xc             S   s
   d| _ d S )NF)called)r   r   r   r   __init__4   s    z%TestCase.test_ast.<locals>.X.__init__c             S   s
   d| _ dS )NT   )r   )r   r   r   r   __call__6   s    z%TestCase.test_ast.<locals>.X.__call__N)r   r   r   r   r    r   r   r   r   r   3   s   r   z
a = 10
f'{a * x()}'r   exec)astparsecompileZassertFalser   r!   Z
assertTrue)r   r   r   exprtcr   r   r   test_ast1   s    
zTestCase.test_astc             C   s  d}t |}| t|t j | t|jd | t|jd t j | |jd jd | t|jd t j	 | t|jd j
t j | t|jd j
jd | t|jd j
jd t j | |jd jd | |jd j
jd | |jd j
jd jd |jd j
jd j
}| t|t j | t|jt j | t|jt j | t|jt j | |jd | |jjd | |jjd | |jd | |jjd | |jjd d S )Nz
a = 10
f'{a * x()}'   r            )r"   r#   r   r   ModulelenbodyAssignlinenoExprvalue	JoinedStrvaluesFormattedValueBinOpleftNameopMultrightCall
col_offset)r   r%   r&   binopr   r   r   test_ast_line_numbersI   s0    
 zTestCase.test_ast_line_numbersc             C   s^  d}t |}| t|t j | t|jd | t|jd t j | t|jd jt j	 | |jd j
d | t|jd t j | t|jd jt j	 | t|jd jjd | t|jd jjd t j | t|jd jjd t j | t|jd jjd t j | t|jd jjd t j | |jd j
d | |jd jj
d | |jd jjd j
d | |jd jjd j
d | |jd jjd j
d | |jd jjd j
d |jd jjd j}| t|t j | t|jt j | t|jt j | t|jt j | |j
d | |jj
d | |jj
d | |jd | |jjd | |jjd |jd jjd j}| t|t j | t|jt j | t|jt j | t|jt j | |j
d | |jj
d | |jj
d | |jd	 | |jjd	 | |jjd
 d S )Nz8
f'no formatted values'
f'eggs {a * x()} spam {b + y()}'r)   r   r*   r   r+               )r"   r#   r   r   r-   r.   r/   r2   r3   r4   r1   r5   Strr6   r7   r8   r9   r:   r;   r<   r=   r>   ZAdd)r   r%   r&   Zbinop1Zbinop2r   r   r   .test_ast_line_numbers_multiple_formattedvaluesh   sT    
    z7TestCase.test_ast_line_numbers_multiple_formattedvaluesc             C   s  d}t |}| t|t j | t|jd | t|jd t j | |jd jd | t|jd t j	 | t|jd j
t j | t|jd j
jd | t|jd j
jd t j | |jd jd | |jd j
jd | |jd j
jd jd |jd j
jd j
}| t|t j | t|jt j | t|jt j | t|jt j | |jd | |jjd | |jjd | |jd | |jjd | |jjd | t|jjd | t|jjd t j | t|jjd t j | t|jjd t j | |jjd jd | |jjd jd | |jjd jd |jjd j
}| t|t j | |jd | |jd d S )Nz
a = 10
f'{a * f"-{x()}-"}'r)   r   r*   r+   r,      )r"   r#   r   r   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r>   rE   r=   )r   r%   r&   r?   Zcallr   r   r   test_ast_line_numbers_nested   sF    
 z%TestCase.test_ast_line_numbers_nestedc             C   s>  d}t |}| t|t j | t|jd | t|jd t j | |jd jd | t|jd t j	 | t|jd j
t j | t|jd j
jd | t|jd j
jd t j | t|jd j
jd t j | t|jd j
jd t j | t|jd j
jd t j | t|jd j
jd t j | |jd jd | |jd j
jd | |jd j
jd jd | |jd j
jd jd | |jd j
jd jd | |jd j
jd jd | |jd j
jd jd |jd j
jd j
}| t|t j | t|jt j | t|jt j | t|jt j | |jd | |jjd | |jjd | |jd | |jjd | |jjd |jd j
jd j
}| t|t j | t|jt j | t|jt j | t|jt j | |jd | |jjd | |jjd | |jd | |jjd | |jjd |jd j
jd j
}| t|t j | t|jt j | t|jt j | t|jt j | |jd | |jjd | |jjd | |jd | |jjd | |jjd d	S )
z|Duplicate expression

        NOTE: this is currently broken, always sets location of the first
        expression.
        z)
a = 10
f'{a * x()} {a * x()} {a * x()}'
r)   r   r*      r+   r   r,   N)r"   r#   r   r   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   rE   r7   r8   r9   r:   r;   r<   r=   r>   )r   r%   r&   r?   r   r   r   *test_ast_line_numbers_duplicate_expression   sl    	
     z3TestCase.test_ast_line_numbers_duplicate_expressionc             C   s  d}t |}| t|t j | t|jd | t|jd t j | |jd jd | t|jd t j	 | t|jd j
t j | t|jd j
jd | t|jd j
jd t j | t|jd j
jd t j | t|jd j
jd t j | |jd jd | |jd j
jd | |jd j
jd jd | |jd j
jd jd | |jd j
jd jd | |jd jd | |jd j
jd | |jd j
jd jd | |jd j
jd jd | |jd j
jd jd |jd j
jd j
}| t|t j | t|jt j | t|jt j | t|jt j | |jd | |jjd | |jjd	 | |jd | |jjd | |jjd
 d S )Nz?
a = 10
f'''
  {a
     *
       x()}
non-important content
'''
r)   r   r*   r+   rA   r      r,   )r"   r#   r   r   r-   r.   r/   r0   r1   r2   r3   r4   r5   rE   r6   r>   r7   r8   r9   r:   r;   r<   r=   )r   r%   r&   r?   r   r   r   'test_ast_line_numbers_multiline_fstring
  sB    
   z0TestCase.test_ast_line_numbers_multiline_fstringc             C   s,   dd }|  |j dd }|  |j d S )Nc               S   s   d d S )NzNot a docstringr   r   r   r   r   fA  s    z"TestCase.test_docstring.<locals>.fc               S   s   d d S )NzNot a docstringr   r   r   r   r   gD  s    z"TestCase.test_docstring.<locals>.g)ZassertIsNone__doc__)r   rN   rO   r   r   r   test_docstring@  s    zTestCase.test_docstringc          	   C   s&   |  td td W d Q R X d S )Nzmalformed node or stringzf'x')r   
ValueErrorr"   Zliteral_eval)r   r   r   r   test_literal_evalI  s    zTestCase.test_literal_evalc             C   s<   dg}d}t |}t|dd}t| | |d d d S )Nr   zx[0] = 'foo' f'{3}'r!   r   Zfoo3)r"   r#   r$   r!   r   )r   r   r%   r&   r'   r   r   r   test_ast_compile_time_concatM  s    
z%TestCase.test_ast_compile_time_concatc             C   s   |  tdddg d S )Nz&cannot mix bytes and nonbytes literalszf'' b''zb'' f'')r	   SyntaxError)r   r   r   r   test_compile_time_concat_errorsV  s    z(TestCase.test_compile_time_concat_errorsc             C   s(   |   d |  dd |  dd d S )Nr   a )r   )r   r   r   r   test_literal]  s    zTestCase.test_literalc             C   s   |  tdddddg d S )Nzf-string: unterminated stringzf'{"x'zf'{"x}'zf'{("x'zf'{("x}')r	   rU   )r   r   r   r   test_unterminated_stringb  s
    z!TestCase.test_unterminated_stringc             C   s   |  tddg d S )Nzf-string: mismatchedzf'{((}')r	   rU   )r   r   r   r   test_mismatched_parensj  s    zTestCase.test_mismatched_parensc             C   sr  |  dd |  dd |  dd |  dd |  dd |  dd |  dd |  dd |  d	d	 |  d
d
 |  dd |  dd |  dd |  dd |  dd |  dd |  dd d |  dd d |  dd d |  dd d |  d dd |  d dd |  d dd |  d dd |  d d | tddg d S ) N{za{z{bza{b}za}z}bza}bz{}za{}z{b}z{}cza{b}za{}cz{b}cza{b}c
   z{10z}10z}{z}{10z}a{z}a{10z10{z10}z10}{z}a{}z10}a{}z{{}}zunhashable typezf'{ {{}} }')r   r	   	TypeError)r   r   r   r   test_double_braceso  s6    zTestCase.test_double_bracesc             C   s  d}|  d| dd |  d| dd |  d| d|dd |  d	| d
 |  d| d |  d	| d
 |  d| d |  d| d |  d| d |  | dd |  | d |  | d |  | d |  | dd |  d| dd |  d| d |  | d| d |   d |   d |   d |   d |   d |   d |   d | tddg d S )Ndefzabc## Zghizabc## defghiabcZ	abcdefghi4zabcdefghidef z{x}z{x}defz{xz{xdefz{{x}}z{{x}}defz{{xz{{xdefzx}}zx}}defzdefx}}2Zdef21Z1def2Z1def-zdef-defr   zf-string: expecting '}'z
f'{3' f'}')r   r	   rU   )r   r   r   r   r   test_compile_time_concat  s6    z!TestCase.test_compile_time_concatc             C   sB   ddi}|  d d |  |d  d | tdddddg d S )N#hashz+f-string expression part cannot include '#'zf'{1#}'z	f'{3(#)}'zf'{#}'zf'{)#}')r   r	   rU   )r   dr   r   r   test_comments  s    zTestCase.test_commentsc             C   s   ddd}d}d}x.t ddD ] }| t|||d |  qW | t|d	d
 |d d  |dd}| t||d d  dd }| t|d d S )Nr   c             S   s   dd|   | d S )Nzf'z{x} 'r   )nZextrar   r   r   
build_fstr  s    z2TestCase.test_many_expressions.<locals>.build_fstrr   r*      i  rX         i      z{x:{width}}    zf'{1}' 'x' 'y'i   A   1xy1xy1xy1xy1xy1xy1xy1xy1xy1xy1xy1xy1xy1xy1xy1xy1xy1xy1xy1xy1xy1xy1xy1xy1xy1xy1xy1xy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||dd|dd | d|d	 d
dd|dd | d|d	 d
dd|dd | ddd	 dd | dd dd
 d d | ddd dd
 dd | dd dd	 dd d | dddddikoH| dd | tddg | tddg | tddg | tddg d S )Nr^   r   z12.34567zresult: .zresult:      12.350re   r*   r   rh   0xz
       0xar   irf   z
      -0xar+   rI   zf-string: expecting '}'zf'{"s"!r{":10"}}'zinvalid syntaxzf'{4:{/5}}'z'f-string: expressions nested too deeplyz,f'result: {value:{width:{0}}.{precision:1}}'z&f-string: invalid conversion characterzf'{"s"!{"r"}}')decimalZDecimalr   r	   rU   )r   ru   Z	precisionr3   r   r   r   !test_format_specifier_expressions  s*    
"&& &z*TestCase.test_format_specifier_expressionsc             C   s.   G dd d}| }|  | d| d d S )Nc               @   s   e Zd Zdd Zdd ZdS )z*TestCase.test_side_effect_order.<locals>.Xc             S   s
   d| _ d S )Nr   )rv   )r   r   r   r   r     s    z3TestCase.test_side_effect_order.<locals>.X.__init__c             S   s   |  j d7  _ t| j S )Nr*   )rv   r   )r   r   r   r   r   r     s    z5TestCase.test_side_effect_order.<locals>.X.__format__N)r   r   r   r   r   r   r   r   r   r     s   r   rX   z1 2)r   )r   r   r   r   r   r   test_side_effect_order  s    zTestCase.test_side_effect_orderc             C   sJ   |  tddddddddd	d
ddddddddddg |  tdddg d S )Nz&f-string: empty expression not allowedzf'{}'zf'{ }'f' {} 'zf'{!r}'zf'{ !r}'zf'{10:{ }}'zf' { } 'zf'''{	
}'''zf'{!x}'z	f'{ !xr}'zf'{!x:}'z	f'{!x:a}'z
f'{ !xr:}'zf'{ !xr:a}'zf'{!}'zf'{:}'zf'{!'zf'{!s:'zf'{:'zf'{:x'zinvalid character in identifieru   f'''{ }'''    )r	   rU   )r   r   r   r   test_missing_expression  s.    z TestCase.test_missing_expressionc             C   sD   |  d d | tdddg | tddg | tddg d S )	N)r+   z(3,)zinvalid syntaxzf'{,}'zf-string: expecting '}'z
f'{3)+(4}'z!EOL while scanning string literalzf'{
}')r   r	   rU   )r   r   r   r   test_parens_in_expressions0  s    z#TestCase.test_parens_in_expressionsc          	   C   s  |  dd |  dd |  dd |  d dd |  d dd d |  dd d |  dd |  d	d	 |  d	d	 |  d dd
 |  d dd d |  dd d |  dd |  dd |  dd |  d dd
 |  d dd d |  dd d |  dd |  d dd
 |  d dd d |  dd d |  d
d
 |  dd |  dd |  dd |  dd |  dd |  d dd |  d dd d |  dd d |  dd |  dd |  dd | t td}W d Q R X |  |d |  dd d |  dd d d}|  dd |  d| d |  d| d |  dd d S )N	z\tr)   z2	r+   z2	3z	3u   Δz\u0394u   2Δu   2Δ3u   Δ3z
\U00000394rX   z\x20z2 z2 3z 3z	f'\{6*7}'z\42\*   Zspam&z\Nz\Nspamz\&)r   ZassertWarnsDeprecationWarningr   )r   r3   Z	AMPERSANDr   r   r   test_backslashes_in_string_partD  sX    z(TestCase.test_backslashes_in_string_partc          
   C   s   |  tdddddddg d S )Nzi\(unicode error\) 'unicodeescape' codec can't decode bytes in position .*: malformed \\N character escapezf'\N'zf'\N{'z f'\N{GREEK CAPITAL LETTER DELTA'z'\N'z'\N{'z'\N{GREEK CAPITAL LETTER DELTA')r	   rU   )r   r   r   r   %test_misformed_unicode_character_name{  s    z.TestCase.test_misformed_unicode_character_namec             C   s"   |  tddddddddd	g d S )
Nz3f-string expression part cannot include a backslashz
f'{\'a\'}'zf'{\t3}'zf'{\}'zrf'{\'a\'}'z	rf'{\t3}'zrf'{\}'zrf'{"\N{LEFT CURLY BRACKET}"}'zf'{\n}')r	   rU   )r   r   r   r   &test_no_backslashes_in_expression_part  s    z/TestCase.test_no_backslashes_in_expression_partc             C   s4   |  dd |  dd |  dd |  dd dS )z@
        Only literal curly braces begin an expression.
        z{1+1}z{1+1N)r   )r   r   r   r   test_no_escapes_for_braces  s    z#TestCase.test_no_escapes_for_bracesc             C   s    |  d d |  d d d S )Nr   rz   r,   7)r   )r   r   r   r   test_newlines_in_expressions  s    z%TestCase.test_newlines_in_expressionsc                sj   d |   fdddd |   fddddd |   fd	dddd
 | tddg d S )NrI   c                s    |  S )Nr   )r   )r   r   r   r     r   z&TestCase.test_lambda.<locals>.<lambda>8z'88888'c                s    |  S )Nr   )r   )r   r   r   r     r   Z10z
'88888'   c                s    |  S )Nr   )r   )r   r   r   r     r   z
88888     zunexpected EOF while parsingzf'{lambda x:x}')r   r	   rU   )r   r   )r   r   test_lambda  s    zTestCase.test_lambdac             C   s$   dd }|d}|  t|d d S )Nc             s   s   d| d V   d S )Nzy:r)   r   )r   r   r   r   fn  s    zTestCase.test_yield.<locals>.fnr   rA   )r   next)r   r   rO   r   r   r   
test_yield  s    zTestCase.test_yieldc             C   s>   dd }|d}t |}| |dd | |dd d S )Nc             3   s   d fddV  V  d S )Nzx:c                s    |  S )Nr   )rv   )r   r   r   r     r   z6TestCase.test_yield_send.<locals>.fn.<locals>.<lambda>r   )r   r   )r   r   r     s    z$TestCase.test_yield_send.<locals>.fnr^   r   (   stringzx:string)r   r   send)r   r   rO   Z
the_lambdar   r   r   test_yield_send  s
    zTestCase.test_yield_sendc             C   st   |  d d |  d d |  d d |  d d |  d d |  d d |  d d |  d d d S )Nr   zeric'szxeric"syzxeric"szeric"sy)r   )r   r   r   r   +test_expressions_with_triple_quoted_strings  s    z4TestCase.test_expressions_with_triple_quoted_stringsc             C   s   d}d}|  | | d |  d| | d |  | d| d |  | | dd |  d| d| d	 |  d| | dd
 |  | d| dd |  d| d| dd d S )Nb   rb   Z98abcr   ZX98abcZ98XabcZ98abcXYZX98YabcZX98abcYZ98XabcYZZX98YabcZ)r   )r   r   r   r   r   r   test_multiple_vars  s    zTestCase.test_multiple_varsc             C   s0   dd }|  |d d |  |d d d S )Nc                s    fdd}|S )Nc                  s
   d  S )Nzx:r   r   )r   r   r   inner  s    z3TestCase.test_closure.<locals>.outer.<locals>.innerr   )r   r   r   )r   r   outer  s    z$TestCase.test_closure.<locals>.outerZ987zx:987r,   zx:7)r   )r   r   r   r   r   test_closure  s    zTestCase.test_closurec                s<   d  fdd}|  |ddd d}|  |ddd d S )	Nr)   c                s   d|   | S )Nzx=r   )r   ru   )r   r   r   rN     s    z"TestCase.test_arguments.<locals>.ffoor^   zx=foofoo    barzx=        20)r   )r   rN   r   r   )r   r   test_arguments  s
    zTestCase.test_argumentsc             C   s   d}|  d| d d S )N{   zv:zv:123)r   )r   r3   r   r   r   test_locals  s    zTestCase.test_localsc          	   C   s$   |  t dt  W d Q R X d S )Nzv:)ZassertRaises	NameErrorr3   )r   r   r   r   test_missing_variable  s    zTestCase.test_missing_variablec             C   sf   G dd d}|  | dd |  |  d |  |  d |  d d |  d d d S )Nc               @   s   e Zd Zdd ZdS )z,TestCase.test_missing_format_spec.<locals>.Oc             S   s   |sdS |S )N*r   )r   r   r   r   r   r     s    z7TestCase.test_missing_format_spec.<locals>.O.__format__N)r   r   r   r   r   r   r   r   O  s   r   r   r   r+   3)r   )r   r   r   r   r   test_missing_format_spec  s    z!TestCase.test_missing_format_specc             C   s|   |  dt d |  dtd d}|  dt d| d |  dtd |  dt d|d | dt  d S )	Nzg:zg:global variablezg:'global variable'zlocal variablez l:z"g:global variable l:local variablez$g:global variable l:'local variable'zmodule 'unittest' from)r   a_globalZassertInunittest)r   a_localr   r   r   test_global  s    zTestCase.test_globalc             C   sr   d}|  d| d |  d|d d}|  d| d| d |  d|d |  d| d|d d S )	Nzreally a localzg:zg:really a localzg:'really a local'zlocal variablez l:z!g:really a local l:local variablez#g:really a local l:'local variable')r   )r   r   r   r   r   r   test_shadowed_global  s    zTestCase.test_shadowed_globalc             C   s   dd }|  |d d d S )Nc             S   s   dt |  S )Nzx=)r   )r   r   r   r   r   "  s    zTestCase.test_call.<locals>.foor^   zx=10)r   )r   r   r   r   r   	test_call!  s    zTestCase.test_callc             C   s0   d}|  d d  d |  | d  d d S )NrI   r   r+   Z000Z555)r   )r   r   r   r   r   test_nested_fstrings'  s    zTestCase.test_nested_fstringsc             C   s>   |  tddddddddd	d
dddddddddddddg d S )Nzunexpected EOF while parsingzfu''zuf''zFu''zfU''zUf''zuF''zufr''zurf''zfur''zfru''zrfu''zruf''zFUR''zFur''zfb''zfB''zFb''zFB''zbf''zbF''zBf''zBF'')r	   rU   )r   r   r   r   test_invalid_string_prefixes,  s.    z%TestCase.test_invalid_string_prefixesc             C   st   |  d d |  d d |  d d |  d d |  ddd dD  d |  ddd dD  d d S )	Nr+   r   zexpr=c             S   s   i | ]\}}||qS r   r   ).0r   r   r   r   r   
<dictcomp>L  s    z9TestCase.test_leading_trailing_spaces.<locals>.<dictcomp>))r*   r)   zexpr={1: 2}c             S   s   i | ]\}}||qS r   r   )r   r   r   r   r   r   r   N  s    )r   )r   r   r   r   test_leading_trailing_spacesF  s    z%TestCase.test_leading_trailing_spacesc             C   sP   |  ddk d |  ddk d |  ddkd |  ddkdd d S )Nr+   r   Truez.3ZTru)r   )r   r   r   r   test_not_equalQ  s    zTestCase.test_not_equalc             C   s   |  ddd |  ddd |  ddd |  ddd |  d d |  dd |  dd |  d d |  ddd	 | td
dddddddg | tdddddg d S )NgQ	@z10.10z
      3.14z
3.14      rW   z'a'za!rz!<10.10z
3.14!!!!!!z&f-string: invalid conversion characterzf'{3!g}'zf'{3!A}'zf'{3!3}'zf'{3!G}'zf'{3!!}'zf'{3!:}'z	f'{3! s}'zf-string: expecting '}'zf'{x!s{y}}'z	f'{3!ss}'z
f'{3!ss:}'zf'{3!ss:s}')r   r	   rU   )r   r   r   r   test_conversions[  s,    zTestCase.test_conversionsc             C   s   |  tddddg d S )Nzinvalid syntaxzf'' = 3z
f'{0}' = xz
f'{x}' = x)r	   rU   )r   r   r   r   test_assignment|  s    zTestCase.test_assignmentc             C   s   |  tdddg d S )Nzinvalid syntaxzdel f''z
del '' f'')r	   rU   )r   r   r   r   test_del  s    zTestCase.test_delc             C   s   |  tddddddddd	g |  td
ddddddddddddddg | d d | d d | dd dd | dd dd d S ) Nz#f-string: single '}' is not allowedzf'{{}'zf'{{}}}'zf'}'zf'x}'zf'x}x'z
f'\u007b}'zf'{3:}>10}'zf'{3:}}>10}'zf-string: expecting '}'zf'{3:{{>10}'zf'{3'zf'{3!'zf'{3:'zf'{3!s'zf'{3!s:'z	f'{3!s:3'zf'x{'zf'x{x'zf'{x'zf'{3:s'zf'{{{'zf'{{}}{'zf'{'r\   r]   r+   z>10z
}}}}}}}}}3r)   z
{{{{{{{{{2)r	   rU   r   )r   r   r   r   test_mismatched_braces  s8    zTestCase.test_mismatched_bracesc                sd    fdd} fdd} fdd}|dd |d	d
 |dd |d	d
 |dd
 |d	d
 d S )Nc                s$   d}|  rd}nd}  || d S )Nr   r*   r)   )r   )r   expectedflag)r   r   r   test_fstring  s
    z2TestCase.test_if_conditional.<locals>.test_fstringc                s$   d}|  rd}nd}  || d S )Nr   r*   r)   )r   )r   r   r   )r   r   r   test_concat_empty  s
    z7TestCase.test_if_conditional.<locals>.test_concat_emptyc                s(   d}d|  rd}nd}  || d S )Nr   rX   r*   r)   )r   )r   r   r   )r   r   r   test_concat_non_empty  s
    
z;TestCase.test_if_conditional.<locals>.test_concat_non_emptyr   r)   rX   r*   r   )r   r   r   r   r   )r   r   test_if_conditional  s    




zTestCase.test_if_conditionalc             C   sF   d}|  | d |  | d |  | d |  | d d S )NZtestz'test')r   )r   r   r   r   r   test_empty_format_specifier  s
    z$TestCase.test_empty_format_specifierc             C   sp   ddd}d}|  |d  d |  |d  d |  ||  d |  dj|dd |  dj|dd d S )	Nr   Zinteger)rW   r   r   rW   z{d[a]})rj   z{d[0]})r   r   )r   rj   rW   r   r   r   test_str_format_differences  s    z$TestCase.test_str_format_differencesc             C   s   |  tdddg d S )Nzinvalid syntaxz	f'{a[4)}'z	f'{a(4]}')r	   rU   )r   r   r   r   test_invalid_expressions  s    z!TestCase.test_invalid_expressionsc             C   s(   |  tdddg |  tdddg d S )NZunsupportedzf'{(lambda: 0):x}'zf'{(0,):x}'zUnknown format codezf'{1000:j}')r	   r_   rR   )r   r   r   r   test_errors  s    zTestCase.test_errorsc             C   s0   x*t dD ]}| d| dt|  q
W d S )Ni  zi:)rt   r   r   )r   rv   r   r   r   	test_loop  s    zTestCase.test_loopc             C   sX   dddd}|  |d  d |  |d  d |  |d  d |  |d  d d S )NZdquoteZsquoter   )"rl   r   rl   r   r   )r   )r   rj   r   r   r   	test_dict  s    zTestCase.test_dictc             C   s$   |  tdd |  tdd d S )Nzf"\
"r   zf"\")r   r   )r   r   r   r   test_backslash_char  s    zTestCase.test_backslash_charN)<r   r   r   r	   r   r(   r@   rF   rH   rJ   rM   rQ   rS   rT   rV   rY   rZ   r[   r`   rg   rk   rx   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r      sr   2+E6		#%(7
				
!%&r   __main__)r"   r   r|   r   r   r   r   mainr   r   r   r   <module>   s   	        