B
    u9a+                 @   s   d dl Z d dlZd dlZd dlZdZdZG dd dejZeeddstx,e	eD ] Z
e
drPe
dkrPeee
 qPW ed	kre  dS )
    Nu  x|x|
foo bar|foo|bar|
 foo bar|foo|bar|
 foo bar |foo|bar|
foo   bar    bla     fasel|foo|bar|bla|fasel|
x y  z              xxxx|x|y|z|xxxx|
\x bar|\|x|bar|
\ x bar|\|x|bar|
\ bar|\|bar|
foo \x bar|foo|\|x|bar|
foo \ x bar|foo|\|x|bar|
foo \ bar|foo|\|bar|
foo "bar" bla|foo|"bar"|bla|
"foo" "bar" "bla"|"foo"|"bar"|"bla"|
"foo" bar "bla"|"foo"|bar|"bla"|
"foo" bar bla|"foo"|bar|bla|
foo 'bar' bla|foo|'bar'|bla|
'foo' 'bar' 'bla'|'foo'|'bar'|'bla'|
'foo' bar 'bla'|'foo'|bar|'bla'|
'foo' bar bla|'foo'|bar|bla|
blurb foo"bar"bar"fasel" baz|blurb|foo"bar"bar"fasel"|baz|
blurb foo'bar'bar'fasel' baz|blurb|foo'bar'bar'fasel'|baz|
""|""|
''|''|
foo "" bar|foo|""|bar|
foo '' bar|foo|''|bar|
foo "" "" "" bar|foo|""|""|""|bar|
foo '' '' '' bar|foo|''|''|''|bar|
\""|\|""|
"\"|"\"|
"foo\ bar"|"foo\ bar"|
"foo\\ bar"|"foo\\ bar"|
"foo\\ bar\"|"foo\\ bar\"|
"foo\\" bar\""|"foo\\"|bar|\|""|
"foo\\ bar\" dfadf"|"foo\\ bar\"|dfadf"|
"foo\\\ bar\" dfadf"|"foo\\\ bar\"|dfadf"|
"foo\\\x bar\" dfadf"|"foo\\\x bar\"|dfadf"|
"foo\x bar\" dfadf"|"foo\x bar\"|dfadf"|
\''|\|''|
'foo\ bar'|'foo\ bar'|
'foo\\ bar'|'foo\\ bar'|
"foo\\\x bar\" df'a\ 'df'|"foo\\\x bar\"|df'a|\|'df'|
\"foo"|\|"foo"|
\"foo"\x|\|"foo"|\|x|
"foo\x"|"foo\x"|
"foo\ "|"foo\ "|
foo\ xx|foo|\|xx|
foo\ x\x|foo|\|x|\|x|
foo\ x\x\""|foo|\|x|\|x|\|""|
"foo\ x\x"|"foo\ x\x"|
"foo\ x\x\\"|"foo\ x\x\\"|
"foo\ x\x\\""foobar"|"foo\ x\x\\"|"foobar"|
"foo\ x\x\\"\''"foobar"|"foo\ x\x\\"|\|''|"foobar"|
"foo\ x\x\\"\'"fo'obar"|"foo\ x\x\\"|\|'"fo'|obar"|
"foo\ x\x\\"\'"fo'obar" 'don'\''t'|"foo\ x\x\\"|\|'"fo'|obar"|'don'|\|''|t'|
'foo\ bar'|'foo\ bar'|
'foo\\ bar'|'foo\\ bar'|
foo\ bar|foo|\|bar|
foo#bar\nbaz|foobaz|
:-) ;-)|:|-|)|;|-|)|
áéíóú|á|é|í|ó|ú|
u1  x|x|
foo bar|foo|bar|
 foo bar|foo|bar|
 foo bar |foo|bar|
foo   bar    bla     fasel|foo|bar|bla|fasel|
x y  z              xxxx|x|y|z|xxxx|
\x bar|x|bar|
\ x bar| x|bar|
\ bar| bar|
foo \x bar|foo|x|bar|
foo \ x bar|foo| x|bar|
foo \ bar|foo| bar|
foo "bar" bla|foo|bar|bla|
"foo" "bar" "bla"|foo|bar|bla|
"foo" bar "bla"|foo|bar|bla|
"foo" bar bla|foo|bar|bla|
foo 'bar' bla|foo|bar|bla|
'foo' 'bar' 'bla'|foo|bar|bla|
'foo' bar 'bla'|foo|bar|bla|
'foo' bar bla|foo|bar|bla|
blurb foo"bar"bar"fasel" baz|blurb|foobarbarfasel|baz|
blurb foo'bar'bar'fasel' baz|blurb|foobarbarfasel|baz|
""||
''||
foo "" bar|foo||bar|
foo '' bar|foo||bar|
foo "" "" "" bar|foo||||bar|
foo '' '' '' bar|foo||||bar|
\"|"|
"\""|"|
"foo\ bar"|foo\ bar|
"foo\\ bar"|foo\ bar|
"foo\\ bar\""|foo\ bar"|
"foo\\" bar\"|foo\|bar"|
"foo\\ bar\" dfadf"|foo\ bar" dfadf|
"foo\\\ bar\" dfadf"|foo\\ bar" dfadf|
"foo\\\x bar\" dfadf"|foo\\x bar" dfadf|
"foo\x bar\" dfadf"|foo\x bar" dfadf|
\'|'|
'foo\ bar'|foo\ bar|
'foo\\ bar'|foo\\ bar|
"foo\\\x bar\" df'a\ 'df"|foo\\x bar" df'a\ 'df|
\"foo|"foo|
\"foo\x|"foox|
"foo\x"|foo\x|
"foo\ "|foo\ |
foo\ xx|foo xx|
foo\ x\x|foo xx|
foo\ x\x\"|foo xx"|
"foo\ x\x"|foo\ x\x|
"foo\ x\x\\"|foo\ x\x\|
"foo\ x\x\\""foobar"|foo\ x\x\foobar|
"foo\ x\x\\"\'"foobar"|foo\ x\x\'foobar|
"foo\ x\x\\"\'"fo'obar"|foo\ x\x\'fo'obar|
"foo\ x\x\\"\'"fo'obar" 'don'\''t'|foo\ x\x\'fo'obar|don't|
"foo\ x\x\\"\'"fo'obar" 'don'\''t' \\|foo\ x\x\'fo'obar|don't|\|
'foo\ bar'|foo\ bar|
'foo\\ bar'|foo\\ bar|
foo\ bar|foo bar|
foo#bar\nbaz|foo|baz|
:-) ;-)|:-)|;-)|
áéíóú|áéíóú|
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d Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!S )"	ShlexTestc             C   st   dd t  D | _ dd t D | _x"| j D ]}|d dd|d< q0W x"| jD ]}|d dd|d< qTW d S )Nc             S   s   g | ]}| d dd qS )|N)split).0x r    /usr/lib/python3.7/test_shlex.py
<listcomp>   s   z#ShlexTest.setUp.<locals>.<listcomp>c             S   s   g | ]}| d dd qS )r   Nr   )r   )r   r   r   r   r	   r
      s   r   z\n
)data
splitlines
posix_datareplace)selfitemr   r   r	   setUp   s    zShlexTest.setUpc             C   sh   xbt t|D ]R}tj|| d |d}| ||| dd  d|| d ||| dd  f  qW d S )Nr   )comments   z%s: %s != %s)rangelenshlexr   assertEqual)r   r   r   ilr   r   r	   	splitTest   s
    zShlexTest.splitTestc             C   s<   g }t  t|}| }x|r6|| | }qW |S )N)r   ioStringIO	get_tokenappend)r   sretZlextokr   r   r	   oldSplit   s    
zShlexTest.oldSplitc             C   s   | j | jdd dS )z%Test data splitting with posix parserT)r   N)r   r   )r   r   r   r	   testSplitPosix   s    zShlexTest.testSplitPosixc             C   sn   xht t| jD ]V}| | j| d }| || j| dd d| j| d || j| dd f  qW dS )zTest compatibility interfacer   r   Nz%s: %s != %s)r   r   r   r#   r   )r   r   r   r   r   r	   
testCompat   s
    zShlexTest.testCompatc             C   sf   x`dD ]X}d| d| g}dd|ddg}x4|D ],}t j |dd}t|}| ||d	|  q.W qW d
S )z)Test handling of syntax splitting of &, |)
z&&&z|&z;&z;;&z||r   z&|z;|z;;|zecho hi %s echo byezecho hi%secho byeechohibyeT)punctuation_charszWhile splitting '%s'N)r   listr   )r   	delimitersrcrefssr    resultr   r   r	   testSyntaxSplitAmpersandAndPipe   s    


z)ShlexTest.testSyntaxSplitAmpersandAndPipec             C   sl   xfdD ]^}d| d| d| g}dd|ddg}x4|D ],}t j |dd	}t|}| ||d
|  q4W qW dS )z&Test handling of syntax splitting of ;);z;;z;&z;;&zecho hi %s echo byezecho hi%s echo byezecho hi%secho byer'   r(   r)   T)r*   zWhile splitting '%s'N)r   r+   r   )r   r,   r-   r.   r/   r    r0   r   r   r	   testSyntaxSplitSemicolon   s    


z"ShlexTest.testSyntaxSplitSemicolonc             C   sj   xddD ]\}d| d| d| g}dd|dg}x4|D ],}t j |dd	}t|}| ||d
|  q2W qW dS )z&Test handling of syntax splitting of >)<r   zecho hi %s outzecho hi%s outzecho hi%soutr'   r(   outT)r*   zWhile splitting '%s'N)r   r+   r   )r   r,   r-   r.   r/   r    r0   r   r   r	   testSyntaxSplitRedirect   s    


z!ShlexTest.testSyntaxSplitRedirectc             C   sN   ddg}ddddg}x4|D ],}t j |dd}t|}| ||d	|  qW d
S )z'Test handling of syntax splitting of ()z( echo hi )z	(echo hi)(r'   r(   )T)r*   zWhile splitting '%s'N)r   r+   r   )r   r-   r.   r/   r    r0   r   r   r	   testSyntaxSplitParen   s    
zShlexTest.testSyntaxSplitParenc             C   sD   ddddddddg}d}t j |d	d
}t|}| ||d|  dS )z3Test handling of syntax splitting with custom charsz~/ar&   zb-cz--color=autoz||dz*.py?z"~/a && b-c --color=auto || d *.py?r   )r*   zWhile splitting '%s'N)r   r+   r   )r   r.   r/   r    r0   r   r   r	   testSyntaxSplitCustom   s
    zShlexTest.testSyntaxSplitCustomc             C   s   x~ddddddgffD ]f\}}t j |dd}g }x>| }||jkrFP |d	 |jkrZd
}nd}|||f q2W | || qW dS )z2Test that tokens are split with types as expected.za && b || c)ar<   )z&&c)br<   )z||r=   )r=   r<   T)r*   r   r=   r<   N)r   r   eofr*   r   r   )r   sourceexpectedr    Zobservedtttr   r   r	   testTokenTypes   s    
zShlexTest.testTokenTypesc             C   s:   t j ddd}| d|j | t|dddddg dS )	z:Test that any punctuation chars are removed from wordcharsZa_b__c_)r*   r<   r>   __r=   N)r   ZassertNotInZ	wordcharsr   r+   )r   r    r   r   r	   testPunctuationInWordChars  s    z$ShlexTest.testPunctuationInWordCharsc          	   C   s\   t j ddd}| t|ddddddg t j ddd}d	|_| t|dddd
dg dS )z9Test that with whitespace_split, behaviour is as expectedza  && b  ||  cr&   )r*   r<   z&&r>   r   r=   Tz||N)r   r   r+   Zwhitespace_split)r   r    r   r   r	   "testPunctuationWithWhitespaceSplit  s
    z,ShlexTest.testPunctuationWithWhitespaceSplitc             C   sP   t j dddd}| t|dddg t j dddd}| t|dddg d	S )
z@Test that punctuation_chars and posix behave correctly together.zf >"abc"T)posixr*   f>abcz
f >\"abc\"z"abc"N)r   r   r+   )r   r    r   r   r	   testPunctuationWithPosix  s    z"ShlexTest.testPunctuationWithPosixc             C   sh   dddg}x0dD ](}t j dd|d}t|}| || qW dddg}t j ddd	}| t|| d
S )z8Test that parsing of empty strings is correctly handled. r8   rL   )FTz'')abcT)rI   r*   z'')r*   N)r   r+   r   )r   rA   punctr    Zslistr   r   r	   testEmptyStringHandling  s    


z!ShlexTest.testEmptyStringHandlingc             C   s   t jt j d }d}d| }| tdd | t|| | tdd x&|D ]}| td| d	|  qXW x&|D ]}| td
| d|  qW d S )Nz
@%_-+=:,./u   éàßz"`$\!rN   z''ztest file namez'test file name'z
test%snamez'test%sname'ztest%s'name'z'test%s'"'"'name'"'"'')stringZascii_lettersdigitsr   r   Zquote)r   ZsafeunquotedZunicode_sampleZunsafeur   r   r	   	testQuote(  s    

zShlexTest.testQuoteN)__name__
__module____qualname__r   r   r#   r$   r%   r1   r3   r6   r9   r;   rD   rG   rH   rM   rP   rT   r   r   r   r	   r      s    
	r   r   Ztestr%   __main__)r   r   rQ   Zunittestr   r   ZTestCaser   getattrdirZmethname
startswithdelattrrU   mainr   r   r   r	   <module>   s   C@ 0