o
    b8;                     @   sp   d Z ddlmZ ddlZddlZddlZddlZddlZddlm	Z	m
Z
 ejd dkr-eZG dd dejZdS )z,
This script tests ``GitWildMatchPattern``.
    )unicode_literalsN)GitWildMatchPatternGitWildMatchPatternError   c                   @   sp  e Zd 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"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zeejd2 d3kd4d5d6 Z eejd2 d7kd8d9d: Z!eejd2 d3kd4d;d< Z"eejd2 d7kd8d=d> Z#d?d@ Z$dAdB Z%dCdD Z&dEdF Z'dGdH Z(dIS )JGitWildMatchTestzU
	The ``GitWildMatchTest`` class tests the ``GitWildMatchPattern``
	implementation.
	c                 C   &   t d\}}| | | | dS )z
		Tests an empty pattern.
		 Nr   pattern_to_regexZassertIsNoneselfregexinclude r   _/var/www/secure340b-portal/env/lib/python3.10/site-packages/pathspec/tests/test_gitwildmatch.pytest_00_empty      
zGitWildMatchTest.test_00_emptyc                 C   sZ   t d\}}| | | |d t t||}t|g d}| |ddh dS )z
		Tests an absolute path pattern.

		This should match:

			an/absolute/file/path
			an/absolute/file/path/foo

		This should NOT match:

			foo/an/absolute/file/path
		z/an/absolute/file/pathz^an/absolute/file/path(?:/.*)?$)an/absolute/file/pathan/absolute/file/path/foozfoo/an/absolute/file/pathr   r   Nr   r
   
assertTrueassertEqualrecompilesetmatchr   r   r   patternresultsr   r   r   test_01_absolute!      

z!GitWildMatchTest.test_01_absolutec                 C   r   )z~
		Tests a single root absolute path pattern.

		This should NOT match any file (according to git check-ignore
		(v2.4.1)).
		/Nr	   r   r   r   r   test_01_absolute_root=   s   
z&GitWildMatchTest.test_01_absolute_rootc                 C   Z   t d\}}| | | |d t t||}t|g d}| |h d dS )zt
		Tests a relative path pattern.

		This should match:

			spam
			spam/
			foo/spam
			spam/foo
			foo/spam/bar
		spam^(?:.+/)?spam(?:/.*)?$)r$   spam/foo/spamspam/foofoo/spam/bar>   r$   r&   r'   r(   r)   Nr   r   r   r   r   test_01_relativeH      
z!GitWildMatchTest.test_01_relativec                 C   sZ   t d\}}| | | |d t t||}t|g d}| |ddh dS )z
		Tests a relative nested path pattern.

		This should match:

			foo/spam
			foo/spam/bar

		This should **not** match (according to git check-ignore (v2.4.1)):

			bar/foo/spam
		r'   z^foo/spam(?:/.*)?$)r'   r)   zbar/foo/spamr)   Nr   r   r   r   r   test_01_relative_nestedh   r    z(GitWildMatchTest.test_01_relative_nestedc                 C   r   )z
		Tests a comment pattern.
		z# Cork soakers.Nr	   r   r   r   r   test_02_comment   r   z GitWildMatchTest.test_02_commentc                 C   s`   t d\}}| | | | | |d t t||}t|dg}| |t  dS )zo
		Tests an exclude pattern.

		This should NOT match (according to git check-ignore (v2.4.1)):

			temp/foo
		z!tempz^(?:.+/)?temp$ztemp/fooN)	r   r
   ZassertIsNotNoneZassertFalser   r   r   r   r   r   r   r   r   test_02_ignore   s   

zGitWildMatchTest.test_02_ignorec                 C   sX   t d\}}| | | |d t t||}t|ddg}| |dh dS )z
		Tests a directory name with a double-asterisk child
		directory.

		This should match:

			spam/bar

		This should **not** match (according to git check-ignore (v2.4.1)):

			foo/spam/bar
		zspam/**z	^spam/.*$zspam/barr)   Nr   r   r   r   r   test_03_child_double_asterisk   s   
z.GitWildMatchTest.test_03_child_double_asteriskc                 C   r#   )z
		Tests a path with an inner double-asterisk directory.

		This should match:

			left/right
			left/bar/right
			left/foo/bar/right
			left/bar/right/foo

		This should **not** match (according to git check-ignore (v2.4.1)):

			foo/left/bar/right
		zleft/**/rightz^left(?:/.+)?/right(?:/.*)?$)
left/rightleft/bar/rightleft/foo/bar/rightleft/bar/right/foozfoo/left/bar/right>   r0   r1   r3   r2   Nr   r   r   r   r   test_03_inner_double_asterisk   s   
z.GitWildMatchTest.test_03_inner_double_asteriskc                 C   s(   t d\}}| | | |d dS )z?
		Tests a double-asterisk pattern which matches everything.
		**^.+$Nr   r
   r   r   r   r   r   r   test_03_only_double_asterisk   s   
z-GitWildMatchTest.test_03_only_double_asteriskc                 C   r#   )z{
		Tests a file name with a double-asterisk parent directory.

		This should match:

			spam
			foo/spam
			foo/spam/bar
		z**/spamr%   )r$   r'   r)   >   r$   r'   r)   Nr   r   r   r   r   test_03_parent_double_asterisk   s   

z/GitWildMatchTest.test_03_parent_double_asteriskc                 C   s$  t d\}}| | | |d t d\}}| | | || t d\}}| | | || t d\}}| | | |d t d\}}| | | || t d\}}| | | |d	 t d
\}}| | | || t d\}}| | | || dS )z4
		Regression test for duplicate leading **/ bug.
		r5   r6   z**/**z**/**/**z**/apiz^(?:.+/)?api(?:/.*)?$z	**/**/apiz**/api/z^(?:.+/)?api/.*$z	**/api/**z**/**/api/**/**Nr7   r   r   r   Zequivalent_regexr   r   r   3test_03_duplicate_leading_double_asterisk_edge_case   s0   







zDGitWildMatchTest.test_03_duplicate_leading_double_asterisk_edge_casec                 C   sL   t d\}}| | | |d t d\}}| | | || dS )zu
		Tests the edge-case **/ pattern.

		This should match everything except individual files in the root directory.
		z**/z^.+/.*$z**/**/Nr7   r:   r   r   r   0test_03_double_asterisk_trailing_slash_edge_case  s   

zAGitWildMatchTest.test_03_double_asterisk_trailing_slash_edge_casec                 C   r#   )z
		Tests a pattern with an infix wildcard.

		This should match:

			foo--bar
			foo-hello-bar
			a/foo-hello-bar
			foo-hello-bar/b
			a/foo-hello-bar/b
		z	foo-*-barz!^(?:.+/)?foo\-[^/]*\-bar(?:/.*)?$)foo--barfoo-hello-bara/foo-hello-barfoo-hello-bar/ba/foo-hello-bar/b>   r=   r>   r?   r@   rA   Nr   r   r   r   r   test_04_infix_wildcard+  r+   z'GitWildMatchTest.test_04_infix_wildcardc                 C   r#   )z
		Tests a pattern with a postfix wildcard.

		This should match:

			~temp-
			~temp-foo
			~temp-foo/bar
			foo/~temp-bar
			foo/~temp-bar/baz
		z~temp-*z^(?:.+/)?\~temp\-[^/]*(?:/.*)?$)~temp-	~temp-foo~temp-foo/barfoo/~temp-barfoo/~temp-bar/baz>   rC   rD   rF   rE   rG   Nr   r   r   r   r   test_04_postfix_wildcardK  r+   z)GitWildMatchTest.test_04_postfix_wildcardc                 C   r#   )zy
		Tests a pattern with a prefix wildcard.

		This should match:

			bar.py
			bar.py/
			foo/bar.py
			foo/bar.py/baz
		*.pyz^(?:.+/)?[^/]*\.py(?:/.*)?$)bar.pybar.py/
foo/bar.pyfoo/bar.py/baz>   rJ   rK   rL   rM   Nr   r   r   r   r   test_04_prefix_wildcardk  s   
z(GitWildMatchTest.test_04_prefix_wildcardc                 C   r#   )z
		Tests a directory pattern.

		This should match:

			dir/
			foo/dir/
			foo/dir/bar

		This should **not** match:

			dir
		dir/z^(?:.+/)?dir/.*$)rO   foo/dir/foo/dir/bardir>   rO   rP   rQ   Nr   r   r   r   r   test_05_directory  s   
z"GitWildMatchTest.test_05_directoryc                 C   s   |  tjdt dS )z+
		Tests that the pattern is registered.
		gitwildmatchN)assertIspathspecutillookup_patternr   r   r   r   r   test_06_registered  s   z#GitWildMatchTest.test_06_registeredc                 C   s&   |  ttd |  ttjt dS )z]
		Tests that the pattern is accessible from the root module using the
		deprecated alias.
		GitIgnorePatternN)r   hasattrrV   
issubclassr[   r   rY   r   r   r   test_06_access_deprecated  s   z*GitWildMatchTest.test_06_access_deprecatedc                 C   s   |  tjdtj dS )zF
		Tests that the pattern is registered under the deprecated alias.
		Z	gitignoreN)rU   rV   rW   rX   r[   rY   r   r   r   test_06_registered_deprecated  s   z.GitWildMatchTest.test_06_registered_deprecatedc                 C   s6   d tttddtjjj}d}| 	|| dS )z
		Test encoding bytes.
		r   r      s    	
 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~N)
joinmapunichrrangeencoderV   patternsrT   _BYTES_ENCODINGr   )r   encodedexpectedr   r   r   test_07_encode_bytes  s   "z%GitWildMatchTest.test_07_encode_bytesc                 C   s2   t ttddtjjj}d}| || dS )z
		Test decoding bytes.
		r   r`   u   	
 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿN)	bytes	bytearrayrd   decoderV   rf   rT   rg   r   )r   decodedri   r   r   r   test_07_decode_bytes  s   z%GitWildMatchTest.test_07_decode_bytesc                 C   *   t d}t|dg}| |dh dS );
		Test byte string patterns matching byte string paths.
		   *.py   a.pyNr   r   r   r   r   r   r   r   r   r   test_07_match_bytes_and_bytes     z.GitWildMatchTest.test_07_match_bytes_and_bytesc                    s\   t ttdd d fddtt D }t|}t| g}| | h dS )rq   r   r`       c                 3   s$    | ]}d  ||d   V  qdS )   \   Nr   ).0irh   r   r   	<genexpr>  s   " zJGitWildMatchTest.test_07_match_bytes_and_bytes_complete.<locals>.<genexpr>N)	rk   rl   rd   ra   lenr   r   r   r   )r   escapedr   r   r   r}   r   &test_07_match_bytes_and_bytes_complete  s
    z7GitWildMatchTest.test_07_match_bytes_and_bytes_completer   r   zPython 3 is strictc                 C   rp   rq   rr   a.pyNrt   ru   r   r   r   test_07_match_bytes_and_unicode     z0GitWildMatchTest.test_07_match_bytes_and_unicode   zPython 2 is lenientc                 C   J   t d}| t |dgD ]}qW d   dS 1 sw   Y  dS r   r   assertRaises	TypeErrorr   r   r   _r   r   r   $test_07_match_bytes_and_unicode_fail     "z5GitWildMatchTest.test_07_match_bytes_and_unicode_failc                 C   rp   z,
		Test unicode patterns with byte paths.
		rI   rs   Nrt   ru   r   r   r   test_07_match_unicode_and_bytes  r   z0GitWildMatchTest.test_07_match_unicode_and_bytesc                 C   r   r   r   r   r   r   r   $test_07_match_unicode_and_bytes_fail  r   z5GitWildMatchTest.test_07_match_unicode_and_bytes_failc                 C   rp   )z/
		Test unicode patterns with unicode paths.
		rI   r   Nrt   ru   r   r   r   !test_07_match_unicode_and_unicode  rw   z2GitWildMatchTest.test_07_match_unicode_and_unicodec                 C   s"   d}d}t |}| || dS )z1
		Test escaping a string with meta-characters
		zfile!with*weird#naming_[1].t?tz$file\!with\*weird\#naming_\[1\].t\?tN)r   escaper   )r   fnamer   resultr   r   r   test_08_escape  s   
zGitWildMatchTest.test_08_escapec                 C      |  d dS ))
		Test an escape on a line by itself.
		\N_check_invalid_patternrY   r   r   r   test_09_single_escape_fail     z+GitWildMatchTest.test_09_single_escape_failc                 C   r   )r   !Nr   rY   r   r   r   $test_09_single_exclamation_mark_fail  r   z5GitWildMatchTest.test_09_single_exclamation_mark_failc                 C   sH   t t|}| t| t| W d    d S 1 sw   Y  d S )N)r   r   reprZassertRaisesRegexpr   r   )r   Zgit_ignore_patternZexpected_message_patternr   r   r   r      s   
"z'GitWildMatchTest._check_invalid_patternN))__name__
__module____qualname____doc__r   r   r"   r*   r,   r-   r.   r/   r4   r8   r9   r;   r<   rB   rH   rN   rS   rZ   r^   r_   rj   ro   rv   r   unittestZskipIfsysversion_infor   r   r   r   r   r   r   r   r   r   r   r   r   r      sN     "$  


	

		r   )r   
__future__r   r   r   r   Zpathspec.patterns.gitwildmatchrV   Zpathspec.utilr   r   r   chrrc   ZTestCaser   r   r   r   r   <module>   s   