o
    HXhl                    @   s   d dl mZmZmZmZmZ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Zd dlmZ d dlmZ G dd deZG dd de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rre  dS dS )    )
gc_collect
bigmemtest_2Gcpython_onlycaptured_stdoutcheck_disallow_instantiationN)Scanner)proxyc                          e Zd Z fddZ  ZS )Sc                       t t |S N)r   super__getitem__selfindex	__class__ 6/opt/python-3.10.19/usr/lib/python3.10/test/test_re.pyr         zS.__getitem____name__
__module____qualname__r   __classcell__r   r   r   r   r          r   c                       r
   )Bc                    r   r   )r   r   r   r   r   r   r   r      r   zB.__getitem__r   r   r   r   r   r      r   r   c                   @   s>  e Zd Zd ddZd ddZd 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d2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Zd<d= Z d>d? Z!d@dA Z"dBdC Z#dDdE Z$dFdG Z%dHdI Z&dJdK Z'dLdM Z(dNdO Z)dPdQ Z*dRdS Z+dTdU Z,dVdW Z-dXdY Z.dZd[ Z/d\d] Z0d^d_ Z1d`da Z2dbdc Z3ddde Z4e5dfdg Z6dhdi Z7djdk Z8dldm Z9dde:j;fdndoZ<e=j>e=j? dp Z@dqdr ZAdsdt ZBdudv ZCdwdx ZDdydz ZEd{d| ZFd}d~ ZGdd ZHdd ZIdd ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTdd ZUdd ZVdd ZWdd ZXdd ZYdd ZZdd Z[dd Z\dd Z]dd Z^dd Z_dd Z`dd Zadd Zbdd Zcdd Zddd Zedd Zfdd Zgdd Zhdd ZiddĄ ZjddƄ ZkddȄ Zlddʄ Zmeneodd̍dd΄ Zpeneodd̍ddф Zqddӄ ZrddՄ Zse5ddׄ Ztddل Zuddۄ Zvdd݄ Zwdd߄ Zxdd Zydd Zze5dd Z{dd Z|dd Z}dd Z~dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS (  ReTestsNc                    s,    ||   fdd|| d S )Nc                    sJ   t |ttfrt| |D ]	\}}|| qd S t| t|  d S r   )
isinstancetuplelistzipassertIstype)actualexpectxymsgrecurser   r   r   r,      s
   z)ReTests.assertTypedEqual.<locals>.recurse)assertEqual)r   r&   r'   r+   r   r*   r   assertTypedEqual   s   zReTests.assertTypedEqualc                 C   s   |  tj}t| W d    n1 sw   Y  | j|d& |j}| |j| |d ur?| |j| W d    d S W d    d S 1 sJw   Y  d S )N)pattern)	assertRaisesreerrorcompilesubTest	exceptionr-   r+   pos)r   r/   errmsgr6   cmerrr   r   r   checkPatternError'   s   "zReTests.checkPatternErrorc                 C   s   |  tj}t||| W d    n1 sw   Y  | j||d& |j}| |j| |d urB| |j| W d    d S W d    d S 1 sMw   Y  d S )N)r/   repl)	r0   r1   r2   subr4   r5   r-   r+   r6   )r   r/   r;   stringr7   r6   r8   r9   r   r   r   checkTemplateError0   s   "zReTests.checkTemplateErrorc                 C   sf   t d}td|}| t |d W d    n1 sw   Y  t| ~t  |d d S )N   x   as  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)	bytearrayr1   finditerr0   BufferErrorextendr"   r   )r   bitr   r   r   test_keep_buffer9   s   zReTests.test_keep_bufferc                 C   s2   d}t d}t|}| |d|d d S )NZQabbbcRzab+c)r1   r3   r	   r-   findall)r   sr(   r)   r   r   r   test_weakrefD   s   
zReTests.test_weakrefc                 C   s   |  tdddd |  tdd d |  tdddd |  tdd d | tdd |  td	d
dd |  td	d
 d |  tdddd |  tdd d | tdd
 d S )Nzx*Zaxxr   r   r   zx+      r(   Zaaaza*xxxZxxxar   rN   a+)r-   r1   searchspanassertIsNonematchr   r   r   r   test_search_star_plusJ   s   zReTests.test_search_star_plusc                 C   s   t |d}t|d S )Nr   rM   )intgroupstr)r   ZmatchobjZ	int_valuer   r   r   bump_numV   s   zReTests.bump_numc              
      s  |  tdddd |  tdtdtdd |  tdddd |  tdtdtdd |  tdtdtdd |  tdtdtdd d	D ]}| t|dd
| d qT| tdddd | td| jdd | td| jddd | tjd| jdddd | tddd dd | tdddd d | td dd | td 	ddd  | td fddd  | td d!dd" | td d#dd" | td$d%dd" | td$d&dd" | tdd'dd( | tdd(dd( | tdd(dt
d)t
d* t
d+ t
d, t
d- t
d. t
d/  d0D ]?}| |. | tj | tdd| dd|  W d    n	1 skw   Y  W d    n	1 s{w   Y  qB| td1d2d3d4 d S )5Nr)   axyzZxaz   yr@      xyzs   xaz   àu   аu   𝒜zx%sz(?i)b+r(   	bbbb BBBBx x\d+z08.2 -2 23x99yz9.3 -3 24x100yrN   z9.3 -3 23x99ycount.c                 S      dS )N\nr   mr   r   r   <lambda>l       z+ReTests.test_basic_re_sub.<locals>.<lambda>rj   
z\1\1z(.)xx\\\c                    s    S r   r   rk   rI   r   r   rm   r   rn   (?P<a>x)z
\g<a>\g<a>Zxxxxz
\g<a>\g<1>
(?P<unk>x)z\g<unk>\g<unk>z
\g<1>\g<1>z\t\n\v\r\f\a\bz	
	   
                  Z,cdehijklmopqsuwxyzABCDEFGHIJKLMNOPQRSTUVWXYZz^\s*XtestZXtest)r.   r1   r<   r   r   rA   
memoryviewr-   r[   replacechrr4   r0   r2   )r   r)   cr   rs   r   test_basic_re_subZ   sT   6 zReTests.test_basic_re_subc                 C      |  tdddd d S )Nru   z\g<1>\g<1>\brp   zxxxxr-   r1   r<   rV   r   r   r   test_bug_449964   s   zReTests.test_bug_449964c                 C   s\   |  tdddd |  tdddd |  tdddd |  tdddd d S )Nz\r\nrj   z
abc
def
zabc
def
z
ro   r   rV   r   r   r   test_bug_449000   s   zReTests.test_bug_449000c                 C   sd   t d}| tt j|dt j | tt j|dt j | tt j|dt j | tt j|t j d S )Nrh   A)r1   r3   r0   
ValueErrorrU   IrR   rH   r   r/   r   r   r   test_bug_1661   s
   
zReTests.test_bug_1661c                 C   s   t d d S )Nz(?P<quote>)(?(quote)))r1   r3   rV   r   r   r   test_bug_3629   s   zReTests.test_bug_3629c                 C   s  |  tdddd |  tdddd |  tdddd |  tdddd |  tdd	dd
 |  tdddd |  tdddd |  tdddd |  tdddd |  tdddd |  tdddd |  tdddd |  tdddd |  tdddd
 |  tdddd | ddddd | ddddd | dddd d! | dd"dd#d! | dd$dd%d! | dd&dd'd! | dd(dd)d! | dd*dd d! | dd+dd,d! | dd-dd.d! | dd/dd'd! | dd0dd'd! | dd1dd)d! | dd2dd3d! | dd"d4d#d! |  td5d&dd |  td6d/d7d8 |  td6d0d7d9 d S ):Nr(   \0 z\000z\001z\008 8z\009z 9z\111r   z\117Oz\377   ÿz\1111ZI1z\00z\07\08z\09z\0az az\400z0octal escape value \400 outside of range 0-0o377r   z\777z0octal escape value \777 outside of range 0-0o377z\1zinvalid group reference 1rM   z\8zinvalid group reference 8z\9zinvalid group reference 9z\11zinvalid group reference 11z\18zinvalid group reference 18z\1az\90zinvalid group reference 90z\99zinvalid group reference 99z\118z\11az\181z\800zinvalid group reference 80 z(((((((((((x)))))))))))z((((((((((y))))))))))(.)r]   Zxz8Zxza)r-   r1   r<   r>   rV   r   r   r    test_sub_template_numeric_escape   sV   

z(ReTests.test_sub_template_numeric_escapec                 C   sL   |  tdddd |  tddddd |  tjdddddd d S )Nr\   rE   ZaaaaaZbbbbbrM   Zbaaaarf   r   rV   r   r   r   test_qualified_re_sub   s   zReTests.test_qualified_re_subc                 C   r   )Nz(\S)\s+(\S)z\1 \2zhello  therezhello therer   rV   r   r   r   test_bug_114660   s   zReTests.test_bug_114660c                 C   sz   t d t d t d t d t d t d ddd	 td
dD }d| }| t |d d d S )Nz(?P<a>x)(?P=a)(?(a)y)z(?P<a1>x)(?P=a1)(?(a1)y)z(?P<a1>x)\1(?(1)y)s   (?P<a1>x)(?P=a1)(?(a1)y)u   (?P<µ>x)(?P=µ)(?(µ)y)uf   (?P<𝔘𝔫𝔦𝔠𝔬𝔡𝔢>x)(?P=𝔘𝔫𝔦𝔠𝔬𝔡𝔢)(?(𝔘𝔫𝔦𝔠𝔬𝔡𝔢)y)|c                 s       | ]	}d ||f V  qdS zx(?P<a%d>%x)yNr   .0ir   r   r   	<genexpr>       z/ReTests.test_symbolic_groups.<locals>.<genexpr>rM      z(?:%s)(?(200)z|t)xc8yzr      )r1   r3   joinranger-   rU   rS   r   patr   r   r   test_symbolic_groups   s   





zReTests.test_symbolic_groupsc                 C   sZ  |  dd |  ddd |  dd |  dd	d
 |  ddd |  ddd |  ddd |  dd |  dd |  ddd |  ddd |  ddd |  ddd |  ddd |  ddd |  ddd |  ddd |  d dd |  d!dd |  d"d#d |  d$d%d |  d&dd |  d'd(d |  d)d(d |  d*d(d d S )+Nz(?P<a>)(?P<a>)z6redefinition of group name 'a' as group 2; was group 1z(?P<a>(?P=a))cannot refer to an open grouprw   z(?Pxy)zunknown extension ?Pxz(?P<a>)(?P=amissing ), unterminated namerx   z(?P=missing group name   z(?P=)z(?P=1)zbad character in group name '1'z(?P=a)zunknown group name 'a'z(?P=a1)zunknown group name 'a1'z(?P=a.)z bad character in group name 'a.'z(?P<)missing >, unterminated namez(?P<az(?P<z(?P<>)z(?P<1>)z(?P<a.>)z(?(rN   z(?())z(?(a))z(?(-1)) bad character in group name '-1'z(?(1a))z bad character in group name '1a'z(?(a.))u	   (?P<©>x)    bad character in group name '©'u   (?P=©)u   (?(©)y)r:   rV   r   r   r   test_symbolic_groups_errors   s:   z#ReTests.test_symbolic_groups_errorsc                 C   s   |  tdddd |  tdddd |  tdddd |  td	d
dd |  tdddd ddd tddD }|  t|ddd d S )Nz(?P<a>x)|(?P<b>y)z\g<b>rp   r   \2s	   (?P<a1>x)s   \g<a1>s   xxu	   (?P<µ>x)u   \g<µ>u#   (?P<𝔘𝔫𝔦𝔠𝔬𝔡𝔢>x)u    \g<𝔘𝔫𝔦𝔠𝔬𝔡𝔢>r   c                 s   r   r   r   r   r   r   r   r     r   z-ReTests.test_symbolic_refs.<locals>.<genexpr>rM   r   z\g<200>Z	xc8yzxc8yZc8zc8)r-   r1   r<   r   r   r   r   r   r   test_symbolic_refs  s   zReTests.test_symbolic_refsc                 C   s  |  ddddd |  ddddd |  dddd	d
 |  ddddd |  ddddd |  ddddd |  ddddd |  ddddd | td tddd W d    n1 s`w   Y  |  ddddd |  ddddd |  ddddd |  ddddd d S )Nrt   z\g<arp   r   rN   z\g<r   z\gz	missing <   z\g<a a>z!bad character in group name 'a a'z\g<>z\g<1a1>z!bad character in group name '1a1'z\g<2>invalid group reference 2r   rM   zunknown group name 'ab'z\g<ab>z\g<-1>r   u   \g<©>r   u   \g<㊀>!   bad character in group name '㊀'u   \g<¹>    bad character in group name '¹')r>   assertRaisesRegex
IndexErrorr1   r<   rV   r   r   r   test_symbolic_refs_errors  sJ   










z!ReTests.test_symbolic_refs_errorsc                 C   s   |  tdddd |  tdddd |  tdddd |  td	ddd
 |  td	dddd |  tjd	ddddd d S )Nrb   r(   rc   )rd   r   zb+)zx BBBBrM   r]   )r]   r   zb*)Zxxxyxzxr   r   )Zxxxyzr   rf   )r-   r1   subnrV   r   r   r   test_re_subn*  s   zReTests.test_re_subnc                 C   s  dt dfD ]&}| td|g d | td|g d | td|g d qdtdtdtdfD ]&}| td	|g d
 | td|g d | td|g d q9dD ]:\}}}d|||f }| td|d||d|g | td|d|||g | td|dd|d|d|g qb| tddg d | tddg d | tddg d | tddg d | tddg d dg dfdg dfdg d fd!g d"ffD ]%\}}| j|d# | t|d| W d    n	1 sw   Y  qdg d$fd%g d&fd'g d(fd)g d*ffD ]&\}}| j|d# | t|d| W d    n	1 sKw   Y  q+d S )+N:a:b::c:)r   r\   rE   r   r   :+)r   r\   rE   r   (:+))r   r   r\   r   rE   ::r   s   :a:b::c   :)    r@      br      c   :+)r   r@   r   r      (:+))r   r   r@   r   r      ::r   )u   àßçu   абвu   𝒜𝒞𝒵z
:%s:%s::%sr   r   z(?::+)z(:)+)r   r   r\   r   rE   r   r   z([b:]+))r   r   r\   z:b::r   z(b)|(:+))r   Nr   r\   Nr   r   rE   Nr   Nr   r   z(?:b)|(?::+))r   r\   r   r   r   z:*)r   r   r\   r   rE   r   r   r   z(?::*)(:*))r   r   r   r   r\   r   r   r   rE   r   r   r   r   r   r   z(:)*)r   r   r   Nr\   r   r   NrE   r   r   Nr   Nr   )sep)	r   r   r\   r   rE   r   r   r   r   \b)r   r\   r   rE   r   r   r   z(?=:))r   z:az:br   z:cz(?<=:))r   a:zb:r   r   )	r   r.   r1   splitr   rA   r   r-   r4   )r   r=   r\   rE   r   r   expectedr   r   r   test_re_split2  sz   







zReTests.test_re_splitc                 C   s   |  tdddg d |  tjddddg d |  tjddddg d |  tjddddg d	 |  tjd
dddg d	 |  tjddddg d d S )Nr   r   r   )r   r\   b::c)maxsplitza:b:c:d)r\   rE   zc:dz(:))r   r   r\   r   r   r   r   )r   r   r   r   za:b::c)r-   r1   r   rV   r   r   r   test_qualified_re_splitg  s   zReTests.test_qualified_re_splitc                 C   sj  |  tddg  dtdfD ]&}| td|g d | td|g d | td|g d qdtdtdtdfD ]&}| td	|g d
 | td|g d
 | td|g d qCdD ]F}|d }|d }d|||f }|  td| ||||g |  td| ||||g |  td||f ||df||f||fg qld S )Nr   abc
a:b::c:::dr   r   z:::r   z(:)(:*)))r   r   )r   r   )r   r   s
   a:b::c:::dr   )r   r   s   :::r   s   (:)(:*)))r   r   )r   r   )r   r   r`   r   rN   z
a%sb%sc%sdz%s+z(%s+)z	(%s)(%s*)r   )r-   r1   rH   r   r.   r   rA   r   )r   r=   r(   rp   rO   r   r   r   test_re_findallr  sB   zReTests.test_re_findallc                 C   s   |  tddg d d S )Nz(a|(b))aba)r\   r   )rE   rE   r   )r-   r1   rH   rV   r   r   r   test_bug_117612  s   zReTests.test_bug_117612c                 C   s  dt dfD ]B}| td| d | td| d | td|dd | td|dd | td|ddd qdtdtdtdfD ]B}| td| d | td	| d
 | td	|dd | td	|dd | td	|ddd qUdD ]M}| t|| d | td| | |f | td| |d| | td| |d| | td| |dd||f qt	d}| |d d | |d d | |d d | |d d | |ddd t	d}| |ddddd | |ddddd | |ddddd  d S )!Nr\   r   (a))r\   r   rM   r\   r\   r@   s   (a))r@   )r@   r@   r`   z(%s)z((a)|(b))(c)?)r\   r\   NNrE   )rE   NrE   Nac)r\   r\   Nr   bc)rE   NrE   r   r   )rE   r   rE   r   !(?:(?P<a1>a)|(?P<b2>b))(?P<c3>c)?r   rN   r\   NNa1b2c3)NrE   N)r\   Nr   )
r   r-   r1   rU   groupsrY   r   rA   r   r3   )r   r=   r\   r   r   r   r   test_re_match  s<   &

 zReTests.test_re_matchc                 C   s   G dd d}t dd}| | d | |dd | |dd | ||dd | t|jd | t|jd	 | t|jdd
>  | t|j|dd
>  | t|jd | |ddd | ||d|dd d S )Nc                   @      e Zd Zdd Zdd ZdS )z!ReTests.test_group.<locals>.Indexc                 S   s
   || _ d S r   value)r   r   r   r   r   __init__  s   
z*ReTests.test_group.<locals>.Index.__init__c                 S   s   | j S r   r   rV   r   r   r   	__index__  s   z+ReTests.test_group.<locals>.Index.__index__N)r   r   r   r   r   r   r   r   r   Index  s    r   z(a)(b)abr   rM   r\   rN     r(   r   rE   r\   )r1   rU   r-   rY   r0   r   )r   r   rl   r   r   r   
test_group  s    zReTests.test_groupc                 C   s  t d}|d}| |d d | |d d  | |d d  | d|d | |d d | |d	 d | |d
 d  | |d d  | td |d  W d    n1 s`w   Y  | td |d  W d    n1 szw   Y  | td |d  W d    n1 sw   Y  | td |d  W d    n1 sw   Y  | td |d  W d    n1 sw   Y  | td |d  W d    n1 sw   Y  | td d| W d    n1 sw   Y  |d}| |d d | |d d  | |d d | d|d | |d d | |d	 d | |d
 d  | |d d | t d	|d< W d    n	1 s]w   Y  | tt	| d S )Nr   r\   r   r   r   za1={a1} b2={b2} c3={c3}za1=a b2=None c3=Noner   rM   r   rN   zno such groupr}   r   r   r   rM   r   za1={a2}r   r   za1=a b2=None c3=c)
r1   r3   rU   r-   
format_mapr   r   r0   	TypeErrorlen)r   r   rl   r   r   r   test_match_getitem  sX   









zReTests.test_match_getitemc                 C   s$  |  tdd d dtdfD ]}|  td| d qdtdtdtdfD ]}|  td| d q-dD ]\}}d	||| f }|  t|||  d q>|  td
d d |  tdd d |  tdd d |  tdd d |  tdd d | tdd | tdd | tdd | tdd |  tdd d |  tdd d |  tdd d |  t	djdddd d |  t	d
jdddd d |  t	djdddd d d S ) Nr\   r   r   za|abr   r   s   abs   a|ab)u   àßu   абu   𝒜𝒞z%s|%sz.*?$r   rP   z.*?za.*?babbZaxxbr   r   rQ   zabc$zabc
zabc\Zz(?m)abc$z	ab(?=c)cdabcdz
ab(?<=b)cdz
(?=a|ab)abr   rM   rN   r6   endposrL   )
r-   r1   	fullmatchrS   r   r   rA   r   rT   r3   )r   r=   r\   rE   rr   r   r   test_re_fullmatch  s:   zReTests.test_re_fullmatchc                 C   sH  |  tdd d |  tdd d | tdd | tdd |  tdd	 d
 |  tdd d |  tdd d |  tdd d td}|  |d d |  |d d | |d | |d ddd tddD }d| }|  t|d d d S )Nz^(\()?([^()]+)(?(1)\))$r   )(r\   r\   Nr\   za)z(az^(?:(a)|c)((?(1)b|d))$r   r\   rE   cd)Ndz^(?:(a)|c)((?(1)|d))$r   z(?P<g1>a)(?P<g2>b)?((?(g2)c|d))r   r\   rE   r   Zad)r\   Nr  Zabdr   r   c                 s   r   r   r   r   r   r   r   r   *  r   z2ReTests.test_re_groupref_exists.<locals>.<genexpr>rM   r   z(?:%s)(?(200)z)r   r   )	r-   r1   rU   r   rT   r3   r   r   rS   )r   pr   r   r   r   test_re_groupref_exists  s@   
zReTests.test_re_groupref_existsc                 C   s   |  ddd |  ddd |  ddd |  d	d
d |  ddd |  ddd |  ddd |  ddd |  ddd |  ddd d S )Nz(?P<a>)(?(0)a|b)zbad group numberrw   z()(?(-1)a|b)r   r   u   ()(?(㊀)a|b)r   u   ()(?(¹)a|b)r   z()(?(1r   z()(?(1)a"missing ), unterminated subpatternr   z
()(?(1)a|bz()(?(1)a|b|cz/conditional backref with more than two branchesz()(?(1)a|b|c)z	()(?(2)a)r   r   rV   r   r   r   test_re_groupref_exists_errors.  s<   z&ReTests.test_re_groupref_exists_errorsc              	   C   sL   t dD ]}| j|d td|  W d    n1 sw   Y  qd S )N   )codez()(?(1)\x%02x?))r   r4   r1   r3   r   r   r   r   r   &test_re_groupref_exists_validation_bugE  s   z.ReTests.test_re_groupref_exists_validation_bugc                 C   s@   ddl m} | dd| dd| d | d| d| d	 d S )
Nr   )	MAXGROUPSz()z\g<%s>rp   zinvalid group reference %drN   z(?P<a>)(?(%d))rw   )sre_constantsr  r>   r:   )r   r  r   r   r   test_re_groupref_overflowJ  s   
z!ReTests.test_re_groupref_overflowc                 C   s   |  tdd d |  tdd d | tdd | tdd |  td	d
 d |  tdd d | ddd d S )Nz^(\|)?([^()]+)\1$z|a|)r   r\   z^(\|)?([^()]+)\1?$r\   r  za|z|az^(?:(a)|c)(\1)$Zaar   z^(?:(a)|c)(\1)?$r   NNz(abc\1)r   r   )r-   r1   rU   r   rT   r:   rV   r   r   r   test_re_grouprefQ  s   zReTests.test_re_grouprefc                 C   s"   |  tdd ddd d S )N#(?P<first>first) (?P<second>second)first secondfirstsecond)r  r  )r-   r1   rU   	groupdictrV   r   r   r   test_groupdict_  s   
zReTests.test_groupdictc                 C   s8   |  tdddd |  tdddd d S )	Nr  r  z\2 \1 \g<second> \g<first>zsecond first second firstz#(?P<first>first)|(?P<second>second)r  z\2 \g<second> )r-   r1   rU   expandrV   r   r   r   test_expandd  s   

zReTests.test_expandc                 C   s8  |  tdd |  tdd |  tdd |  tdd | tdddd | td	ddd | td
ddd | tdddd | tdddd | tdddd | tdddd | tdddd |  tdd |  tdd |  tdd |  tdd | tdd | tdd | tdd | tdd | tdd | tdd | tdd | tdd | tdd |  tdd | tdd | ddd  d S )!Nz	^(\w){1}$r   z
^(\w){1}?$z^(\w){1,2}$z^(\w){1,2}?$z	^(\w){3}$rM   r   z^(\w){1,3}$z^(\w){1,4}$z^(\w){3,4}?$z
^(\w){3}?$z^(\w){1,3}?$z^(\w){1,4}?$z^x{1}$rO   z^x{1}?$z^x{1,2}$z	^x{1,2}?$z^x{3}$z^x{1,3}$z^x{3,3}$z^x{1,4}$z	^x{3,4}?$z^x{3}?$z	^x{1,3}?$z	^x{1,4}?$z^x{}$zx{}zx{2,1}z"min repeat greater than max repeatr   )rT   r1   rU   r-   rY   
assertTruer:   rV   r   r   r   test_repeat_minmaxn  s<   zReTests.test_repeat_minmaxc                 C   sZ  |  tdjd |  tdjtjtjB  |  tdjd |  tdji  |  tdjddd |  t	ddj
d |  t	ddjd |  t	ddjd |  t	ddjd	 | t	ddj td}|  t|jd
dg |  |jd d | t d|jd< W d    n1 sw   Y  |  |jd d d S )Nz
(?i)(a)(b)r   z(?i)(?P<first>a)(?P<other>b)rM   )r  otherr   r\   r   )r   r   r  r  )r-   r1   r3   r/   flagsr   Ur   
groupindexrU   r6   r   r=   regsr  sortedr0   r   )r   r  r   r   r   test_getattr  s&   
zReTests.test_getattrc                 C   s  |  tdddd |  tdddd |  tddtjdd |  tddtjdd |  tddtjd	d
 |  tdd
tjd	d
 | tddtj |  tdddd |  tdddd |  tddtjdd |  tddtjdd |  tddtjd	d |  tddtjd	d | tddtj |  tddd	d |  tddd	d |  tddtjd	d |  tddtjd	d d S )Nz\b(b.)\bzabcd abc bcd bxrM   bxz\B(b.)\Bzabc bcd bc abxdz^abc$z
abc
r   r   z	^\Aabc\Z$s   \b(b.)\bs   abcd abc bcd bxs   bxs   \B(b.)\Bs   abc bcd bc abxds   ^abc$s   
abc
   abcs	   ^\Aabc\Z$z\d\D\w\W\s\Sz1aa! as   \d\D\w\W\s\Ss   1aa! a)r-   r1   rR   rY   ASCIIMrT   LOCALErV   r   r   r   test_special_escapes  s   











zReTests.test_special_escapesc              	   C   sn  |  ddd | tdd d | tdd | tdd d | tdd	 d	 | tdd
 | tdd d | tdd | tdd d | tdd t  dD ]"}| | | tj	tj
d|  W d    n1 sw   Y  qmdD ]"}| | | tj	tj
d|  W d    n1 sw   Y  qd S )Nrq   zbad escape (end of pattern)r   z\(r  )rr   z[\]]][z[a\-c]-rE   z[\^a]+za^Z!ceghijklmopqyzCEFGHIJKLMNOPQRTVXYz\%cZ$ceghijklmopqyzABCEFGHIJKLMNOPQRTVXYZz[\%c])r:   r-   r1   rU   rY   rT   purger4   r0   r2   r3   )r   r   r   r   r   test_other_escapes  s,   zReTests.test_other_escapesc                 C   sp  |  tdd |  tdd | tdd |  tdd |  tdd |  td	d
 | td	d | ddd | ddd | ddd | ddd | ddd | ddd | ddd | ddd | ddd | ddd | ddd | dd d! | d"d d | d#d$d! | d%d$d | d&d'd! | d(d'd d S ))Nz\N{LESS-THAN SIGN}<z\N{less-than sign}>z	\N{SNAKE}u   🐍zW\N{ARABIC LIGATURE UIGHUR KIRGHIZ YEH WITH HAMZA ABOVE WITH ALEF MAKSURA ISOLATED FORM}u   ﯹz*[\N{LESS-THAN SIGN}-\N{GREATER-THAN SIGN}]=;z\Nz	missing {r   z[\N]rN   z\N{zmissing character namez[\N{r   z\N{}z[\N{}]z\NSNAKE}z
[\NSNAKE}]z\N{SNAKEzmissing }, unterminated namez
[\N{SNAKE]z[\N{SNAKE]}z!undefined character name 'SNAKE]'rM   z\N{SPAM}zundefined character name 'SPAM'r   z
[\N{SPAM}]z\N{KEYCAP NUMBER SIGN}z-undefined character name 'KEYCAP NUMBER SIGN'z[\N{KEYCAP NUMBER SIGN}]s   \N{LESS-THAN SIGN}zbad escape \Ns   [\N{LESS-THAN SIGN}])r  r1   rU   rT   r:   rV   r   r   r   test_named_unicode_escapes  sX   


z"ReTests.test_named_unicode_escapesc                 C   s   |  tdddd | tdd | tdd | tdd | tdd | tdd |  tt	ddd |  tt	ddd	 |  tt	dd
d	 |  tt	ddd	 |  tt	dd
d d S )Nz	\b(abc)\br   rM   r   \Br   r\   r   r   r  z   )
r-   r1   rR   rY   r  rU   assertFalserT   r   rH   rV   r   r   r   test_string_boundaries  s   zReTests.test_string_boundariesc              	   C   sR   |  tdddd ddtttddd }|  t|d	 d	 d S )
Nu
   ([∢∣])u   ∢rM   z[%s]r   r        u   ！)r-   r1   rU   rY   r   mapr   r   r   r   r   r   r   test_bigcharset  s   
zReTests.test_bigcharsetc                 C   sB   t ddd tdD }| |d | |d d S )Nr   c                 s   s    | ]}d | V  qdS )z%dNr   )r   r(   r   r   r   r   %      z,ReTests.test_big_codesize.<locals>.<genexpr>'  Z1000Z9999)r1   r3   r   r   r  rU   r=  r   r   r   test_big_codesize#  s   zReTests.test_big_codesizec                 C   s@   |  tddtjdd |  tddtjdd d S )Nza.bza
br   za.*bza

b)r-   r1   rU   DOTALLrY   rV   r   r   r   test_anyall)  s   zReTests.test_anyallc                 C   s  |  tdddd |  tdddd |  tdddd |  tdddd |  td	d
dd |  tdddd |  tdd
dd |  tdd
dd |  tdddd |  tdddd |  tdddd | tdd | tdd | tdd | tdd | tdd | tdd | tdd | tdd | tdd | tdd d S )Nz(a(?=\s[^a]))a brM   r\   z(a(?=\s[^a]*))z(a(?=\s[abc]))z(a(?=\s[abc]*))a bcz(a)(?=\s\1)a az(a)(?=\s\1*)a aaz(a)(?=\s(abc|a))z(a(?!\s[^a]))z(a(?!\s[abc]))za dz(a)(?!\s\1)z(a)(?!\s(abc|a))z(a)b(?=\1)ar   z(a)b(?=\1)cZabacz(?:(a)|(x))b(?=(?(2)x|c))cr   z(?:(a)|(x))b(?=(?(2)c|x))cz(?:(a)|(x))b(?=(?(1)b|x))cz(?:(a)|(x))b(?=(?(1)c|x))cz(a)b(?=(?(2)x|c))(c)z(a)b(?=(?(2)b|x))(c)z(a)b(?=(?(1)c|x))(c))r-   r1   rU   rY   r  rT   rV   r   r   r   test_lookahead/  s*   zReTests.test_lookaheadc                 C   sl  |  tdd | tdd | tdd |  tdd |  tdd | tdd	 | td
d |  tdd	 | tdd | tdd |  tdd | tdd |  tdd | tjtjd | tdd |  tdd | tjtjd | tjtjd | tjtjd | tjtjd d S )Nz	ab(?<=b)cr   z	ab(?<=c)cz	ab(?<!b)cz	ab(?<!c)cz(a)a(?<=\1)cZaacz(a)b(?<=\1)aZabaaz(a)a(?<!\1)cz(a)b(?<!\1)az(?:(a)|(x))b(?<=(?(2)x|c))cz(?:(a)|(x))b(?<=(?(2)b|x))cz(?:(a)|(x))b(?<=(?(2)x|b))cz(?:(a)|(x))b(?<=(?(1)c|x))cz(?:(a)|(x))b(?<=(?(1)b|x))cz(a)b(?<=(?(2)b|x))(c)z(a)b(?<=(?(1)c|x))(c)z(a)b(?<=(?(1)b|x))(c)z(a)b(?<=(.)\2)(c)z(a)b(?<=(?P<a>.)(?P=a))(c)z(a)b(?<=(a)(?(2)b|x))(c)z(a)b(?<=(.)(?<=\2))(c))r  r1   rU   rT   r0   r2   r3   rV   r   r   r   test_lookbehindK  s(   zReTests.test_lookbehindc                 C   s(  |  tddtjdd |  tddtjdd |  tddtjdd |  td	d
tjdd
 |  tddtjdd |  tdd
tjdd
 |  tddtjdd |  tddtjdd |  tddtjdd |  tddtjdd d d   krdksJ  J | tddtj | tddtj | tddtj | tddtj d d   krdksJ  J | tddtj | tddtj | tddtj | tddtj d d   kr#dks&J  J | tddtj | tddtj | tddtj | tddtj | td dtj | td dtj d! d"   kryd#ks|J  J | td$d"tj | td%d!tj d S )&Nr   ABCr   r'  s   ABCz	(a\s[^a])rD  rM   z
(a\s[^a]*)za bbz
(a\s[abc])z(a\s[abc]*)z	((a)\s\2)rF  z
((a)\s\2*)rG  z((a)\s(abc|a))z((a)\s(abc|a)*)K   Kkz\u212arI      ſr   z\u017f   в   ᲀ   Вz\u0412z\u0432z\u1c80   ﬅ   ﬆSTz\ufb05z\ufb06)r-   r1   rU   r   rY   lowerr  upperrV   r   r   r   test_ignore_casee  s<   $$((zReTests.test_ignore_casec                 C   s  |  tddtj |  tddtj |  tddtj |  tddtj |  tddtj |  tddtj |  tddtj |  tddtj d	 d
   krgdksjJ  J |  tdd
tj |  tdd
tj |  tdd	tj |  tddtj d d   krdksJ  J |  tddtj |  tddtj |  tddtj |  tddtj d d   krdksJ  J |  tddtj |  tddtj |  tddtj |  tddtj |  tddtj |  tddtj d d   kr9dks<J  J |  tddtj |  tddtj d S ) Nz[19A]r   z[19a]r\   s   [19A]   As   [19a]r@   rK  rL  rM  z[19K]z[19k]z
[19\u212a]rI   rN  r   z[19S]z[19s]z
[19\u017f]rO  rP  rQ  z
[19\u0412]z
[19\u0432]z
[19\u1c80]rR  rS  rT  z
[19\ufb05]z
[19\ufb06])r  r1   rU   r   rU  rV  rV   r   r   r   test_ignore_case_set  s8   $$$(zReTests.test_ignore_case_setc                 C   s^  |  tddtj | tddtj |  tddtj | tddtj |  tddtj | tdd	tj |  td
d	tj | td
dtj |  tddtj |  tddtj |  tddtj |  tddtj |  tddtj |  tddtj |  tddtj |  tddtj d d   krdksJ  J |  tddtj |  tddtj |  tddtj |  tddtj d d   krdksJ  J |  tddtj |  tddtj |  tddtj |  tddtj d d    kr>d!ksAJ  J |  td"dtj |  td"d tj |  td#d!tj |  td#d tj |  td$d!tj |  td$dtj d% d&   krd'ksJ  J |  td(d&tj |  td)d%tj d S )*Nz[9-a]_z[9-A]s   [9-a]   _s   [9-A]z[\xc0-\xde]   ×   ÷z[\xe0-\xfe]z[\u0430-\u045f]u   ѐu   Ѐz[\u0400-\u042f]z[\U00010428-\U0001044f]u   𐐨u   𐐀z[\U00010400-\U00010427]rK  rL  rM  z[J-M]z[j-m]z[\u2129-\u212b]rI   rN  r   z[R-T]z[r-t]z[\u017e-\u0180]rO  rP  rQ  z[\u0411-\u0413]z[\u0431-\u0433]z[\u1c80-\u1c82]rR  rS  rT  z[\ufb04-\ufb05]z[\ufb06-\ufb07])r  r1   rU   r   rT   rU  rV  rV   r   r   r   test_ignore_case_range  sH   $&((zReTests.test_ignore_case_rangec                 C   s   |  tdddd d S )Nz(\s)r  rM   r-   r1   rU   rY   rV   r   r   r   test_category  s   zReTests.test_categoryc                 C   sn  dd l }tdD ]5}t|}t| }| ||| | ||| |tj	v }| |
|| | ||| qttddddg D ]G}t|}| ||| |dkri| ||t|  || kpt|| k}| |
| | |||| kp|| k qI| |dd | |dtd | |
d | |d d S )Nr      i   i  i( i0  r   )_srer   r   ordrU  r-   ascii_tolowerunicode_tolowerr=   ascii_lettersascii_iscasedunicode_iscasedr"   rV  r8  r  )r   rb  r   r   loiscasedr   r   r   test_case_helpers  s.   
zReTests.test_case_helpersc                 C   s8   |  tdddd |  tdddd d S )Nz\s([^a]) brM   rE   z	\s([^a]*)z bbZbbr-   r1   rR   rY   rV   r   r   r   test_not_literal      zReTests.test_not_literalc                 C   s  t td }| t td}W d    n1 sw   Y  | ||t	d | td|t	d | t td}W d    n1 sNw   Y  | ||t	d | t td}W d    n1 ssw   Y  | ||t	d	 | t td
}W d    n1 sw   Y  | ||t	d | t td}W d    n1 sw   Y  | ||t	d | td|t	d | t td}W d    n1 sw   Y  | ||t	d | t td}W d    n	1 sw   Y  | ||t	d | td|t	d | t td}W d    n	1 sFw   Y  | ||t	d | t td}W d    n	1 slw   Y  | ||t	d | td|t	d | t td}W d    n	1 sw   Y  | ||t	d | t td}W d    n	1 sw   Y  | ||t	d d S )Nra  z[0-9--1]z-./0123456789z[--1]z-./01z[%--1]z
%&'()*+,-1z[%--]z	%&'()*+,-z[0-9&&1]z&0123456789z[\d&&1]z[&&1]z&1z[0-9||a]z0123456789a|z[\d||a]z[||1]z1|z[0-9~~1]z0123456789~z[\d~~1]z[~~1]z1~z[[0-9]|]z0123456789[]z[[:digit:]|]z:[]dgit)
bytesr   decodeassertWarnsFutureWarningr1   r3   r-   rH   r"   r   rI   r  r   r   r   test_possible_set_operations  sb   z$ReTests.test_possible_set_operationsc                 C   s8   |  tdddd |  tdddd d S )Nz\s(b)rl  rM   rE   za\sza r   rm  rV   r   r   r   test_search_coverage1  ro  zReTests.test_search_coveragec                 C   sr   |d u r|d u r|}dt |f}n|d u s|d u rtd|||}| | | | | | | | d S )Nr   z@If match is not None, span should be specified (and vice versa).)r   r   r  r-   rY   rS   )r   r/   textrU   rS   Zmatcherrl   r   r   r   assertMatch5  s   

zReTests.assertMatchz!"%',/:;<=>@_`c                 C   s   d dd tdD }|D ]#}| t|| | dt| d | | dt| | q| t|| dD ]}| t|d d	 d
 q=| j}| t|| d S )Nr   c                 s   s    | ]}t |V  qd S r   )r   r   r   r   r   r   F  r?  z)ReTests.test_re_escape.<locals>.<genexpr>r  r.  r-  z(?x)z-.]{}rM   rq   )r   r   rx  r1   escaper-   LITERAL_CHARS)r   r  r   literal_charsr   r   r   test_re_escapeE  s   zReTests.test_re_escapec                 C   s   t td}|D ](}t |g}| t|| | dt| d | | dt| | q| t|| dD ]}t |g}| t|d d d q<| jd}| t|| d S )	Nr     [   ]s   (?x)s   -.]{}rM      \ascii)rp  r   rx  r1   ry  r-   rz  encode)r   r  r   rE   r{  r   r   r   test_re_escape_bytesQ  s   

zReTests.test_re_escape_bytesc                 C   sH   d}t |}| || | || | dt d |ddt j d S )Nu   xxx☠☠☠xxxz.%s+.   ☠u   x☠☠☠x)r   r{   )r1   ry  r-   rx  rR   )r   rI   Z	s_escapedr   r   r   test_re_escape_non_ascii_  s   
z ReTests.test_re_escape_non_asciic                 C   sX   d d}t|}| || | || ttd d|}| t|d d S )Nu	   y☠y☠yzutf-8r  r   )r  r1   ry  r-   rx  rH   r   )r   rE   Z	b_escapedresr   r   r   test_re_escape_non_ascii_bytesg  s   

z&ReTests.test_re_escape_non_ascii_bytesc                 C   s\   dd l }tdtj}t|jd D ]}|||}||}| || qddlm	} d S )Nr   za(?:b|(c|e){1,2}?|d)+?(.)rM   )_compile)
pickler1   r3   UNICODEr   HIGHEST_PROTOCOLdumpsloadsr-   r  )r   r  ZoldpatprotoZpickledZnewpatr  r   r   r   test_picklingo  s   
zReTests.test_picklingc                 C   sh   dd l }td}| | || | ||| |d}| | || | ||| d S )Nr   z (?P<int>\d+)(?:\.(?P<frac>\d*))?z12.34)copyr1   r3   r$   deepcopyrU   )r   r  r  rl   r   r   r   test_copyingy  s   

zReTests.test_copyingc                 C   sT   |  tjtj |  tjtj |  tjtj |  tjtj	 |  tj
tj d S r   )r-   r1   r   
IGNORECASELr*  r)  	MULTILINEr   rB  r}   VERBOSErV   r   r   r   test_constants  s
   zReTests.test_constantsc                 C   sl   t jt jt jt jt jt jfD ]}| t d| qt jt jt jt jt jt j	fD ]}| t d| q(d S )Nz	^pattern$s	   ^pattern$)
r1   r   r)  r}   r   r   r!  r  r3   r  )r   flagr   r   r   
test_flags  s
     zReTests.test_flagsc                 C   s<  dD ]}|dk r^|  td| t| |  td| t|d  |  td| t|d  |  td| t| |  td	| t|d  |  td
| t|d  |dk r|  td| t| |  td| t|d  |  td| t|d  |  td| t| |  td| t|d  |  td| t|d  q|  tdd |  tdd |  tdd |  tdd | ddd | ddd  | d!d"d | d#d"d | d$d%d | d&d%d | d'd(d | d)d(d | d*d+d d S ),Nr   r|          @      ra  r;  r    r:  i r  \%03o\%03o00\%03o88\x%02x\x%02x0\x%02xzzr:  z\u%04xz\u%04x0z\u%04xzz\U%08xz\U%08x0z\U%08xzr   r   r   r   z\01r   z\018z8z\5670octal escape value \567 outside of range 0-0o377r   z\911invalid group reference 91rM   z\x1incomplete escape \x1z\x1zz\u123incomplete escape \u123z\u123zz	\U0001234incomplete escape \U0001234z
\U0001234zz
\U00110000bad escape \U00110000r  r1   rU   r   r:   r  r   r   r   test_sre_character_literals  s>    z#ReTests.test_sre_character_literalsc                 C   s  dD ]}|dk rp|  td| t| |  td| t| |  td| t| |  td| t| |  td| t| |  td| t| |  td	| t| |  td
| t| |dk r|  td| t| |  td| t| |  td| t| |  td| t| |  td| t|d  |  td| t|d  q| ddd | ddd | ddd | ddd | ddd | dd d |  td!d" d S )#Nr  r  [\%o][\%o8][\%03o][\%03o0][\%03o8][\x%02x]	[\x%02x0]	[\x%02xz]r:  z[\u%04x]z	[\u%04x0]z	[\u%04xz]z[\U%08x]z	[\U%08x0]r  z	[\U%08xz]r  z[\567]r  rM   z[\911]bad escape \9z[\x1z]r  z[\u123z]r  z[\U0001234z]r  z[\U00110000]r  z[\U0001d49c-\U0001d4b5]u   𝒞r  r  r   r   r   !test_sre_character_class_literals  s6    z)ReTests.test_sre_character_class_literalsc                 C   s  dD ]j}|  td|  t|g |  td|  t|gd  |  td|  t|gd  |  td|  t|g |  td|  t|gd  |  td	|  t|gd
  q| tjtjd | tjtjd |  tdd |  tdd |  tdd |  tdd | ddd | ddd | ddd | ddd d S )Nr   r|   r  r  r  r  ra  r;  r  r     0r     8r  r  r     zs   \u1234s
   \U00012345s   \0    s   \08s    8s   \01   s   \018s   8s   \567r  r   s   \911r  rM   s   \x1r  s   \x1z	r  r1   rU   r  rp  r0   r2   r3   r:   r  r   r   r   test_sre_byte_literals  s(    $$ $&zReTests.test_sre_byte_literalsc                 C   s\  dD ]}|  td|  t|g |  td|  t|g |  td|  t|g |  td|  t|g |  td|  t|g |  td|  t|g |  td|  t|g |  td	|  t|g q| tjtjd
 | tjtjd | ddd | ddd | ddd d S )Nr  r  r  r  r  r  r  r  r  s   [\u1234]s   [\U00012345]s   [\567]r  rM   s   [\911]r  s   [\x1z]r  r  r  r   r   r   test_sre_byte_class_literals  s"          "z$ReTests.test_sre_byte_class_literalsc                 C   sf   |  ddd |  ddd |  ddd |  ddd |  ddd	 |  d
dd	 |  ddd	 d S )Nr.  zunterminated character setr   z[^z[az[a-z[\w-b]zbad character range \w-brM   z[a-\w]zbad character range a-\wz[b-a]zbad character range b-ar   rV   r   r   r   test_character_set_errors  s   z!ReTests.test_character_set_errorsc                 C   sR   |  tdddd |  tdddd |  tdddd d S )Nz(a)|(b)rE   rM   r   )r   r   )r-   r1   rU   startendrS   rV   r   r   r   test_bug_113254  s   zReTests.test_bug_113254c                 C   sp   |  tddj | tddjd | tddjd | tddjd | tddjd d S )	Nz(a)?ar\   z(a)(b)?br   rM   z(?P<a>a)(?P<b>b)?bz(?P<a>a(b))z((a)))rT   r1   rU   	lastindexr-   	lastgrouprV   r   r   r   test_bug_527371  s
   zReTests.test_bug_527371c                 C   s   |  tddd d dd |  tddd d	 dd  d
 dd |  tddd d dd |  tddd d dd d S )Nz.*?cr@  r   r  r   i!N  z.*?cdi  r   Zcdei#N  i N  r   deia  z(a|b)*?c)r-   r1   rU   r  rR   rV   r   r   r   test_bug_418626
  s   "("&zReTests.test_bug_418626c                 C   s,   dt d d }| t |odd d S )Nr.  u   ‹r-  rM   )r1   ry  r-   r3   r   r   r   r   test_bug_612074  s   zReTests.test_bug_612074c                 C   sf   |  tddd dd |  tddd d dd |  tddd d dd d S )Nz(x)*iP  r(   rM   z(x)*yr)   z(x)*?yr_  rV   r   r   r   test_stack_overflow  s   "&zReTests.test_stack_overflowc                 C   sD   dD ]}dD ]}|  d||f dd |  d||f dd qqd S )N*+?{1,2}r   r  z%s%sznothing to repeatr   z(?:%s%s)rN   r   )r   repsmodr   r   r   test_nothing_to_repeat!  s   zReTests.test_nothing_to_repeatc                 C   sZ   dD ](}dD ]#}|| }dD ]}dD ]}|| }|  d||f ddt|  qqqqd S )N)r  r  r  r  r  zx%s%szmultiple repeatrM   )r:   r   )r   Z
outer_repsZ	outer_modouter_opZ
inner_repsZ	inner_modinner_opr   r   r   test_multiple_repeat)  s   zReTests.test_multiple_repeatc                 C   sp   |  tdd |  tdd |  tdd |  tdd |  tdd |  tdd d S )Nz(?:a?)*yr  z(?:a?)+yz(?:a?){2,}yz	(?:a?)*?yz	(?:a?)+?yz(?:a?){2,}?y)rT   r1   rU   rV   r   r   r    test_unlimited_zero_width_repeat3  s   z(ReTests.test_unlimited_zero_width_repeatc                 C   st   dd }dd }dd }dd }t d	|fd
|fd|fd|fdg}| |jdj | |dg ddf d S )Nc                 S   s   |S r   r   scannertokenr   r   r   s_ident=  rn   z%ReTests.test_scanner.<locals>.s_identc                 S   s   d| S )Nzop%sr   r  r   r   r   
s_operator>      z(ReTests.test_scanner.<locals>.s_operatorc                 S      t |S r   )floatr  r   r   r   s_float?  r  z%ReTests.test_scanner.<locals>.s_floatc                 S   r  r   )rX   r  r   r   r   s_int@  r  z#ReTests.test_scanner.<locals>.s_intz[a-zA-Z_]\w*z\d+\.\d*re   z=|\+|-|\*|/)z\s+Nr   zsum = 3*foo + 312.50 + bar)	sumzop=rN   zop*fooop+g     s@r  Zbar)r   r  r  r/   r-   scan)r   r  r  r  r  r  r   r   r   test_scanner<  s"   zReTests.test_scannerc                 C   sF   dD ]}|  td| d d |  td| d d qd S )N)r   r  r  z
((.%s):)?zr  r  za:z)r   r\   r-   r1   rU   r   )r   opr   r   r   test_bug_448951P  s   zReTests.test_bug_448951c                 C   s   |  tdd d |  tdd d |  tdd d |  tdd d |  td	d d |  td
d d |  tdd d |  tdd d d S )Nz	^((a)|b)*r   r   z^(([ab])|c)*)r   rE   z^((d)|[ab])*rE   Nz^((a)c|[ab])*z^((a)|b)*?cz^(([ab])|c)*?dr   z^((d)|[ab])*?cz^((a)c|[ab])*?cr  rV   r   r   r   test_bug_725106Y  s0   zReTests.test_bug_725106c                 C   s4   |  tdd d |  tdd d d S )Nz(a)(?:(?=(b)*)c)*r   )r\   Nz(a)((?!(b)*))*r   r  rV   r   r   r   test_bug_725149l  s   zReTests.test_bug_725149c                 C   s2   G dd dt }t|d}| |d d S )Nc                   @   s   e Zd ZdS )z+ReTests.test_bug_764548.<locals>.my_unicodeN)r   r   r   r   r   r   r   
my_unicodeu  s    r  r   r]   )rZ   r1   r3   rT   rU   )r   r  r   r   r   r   test_bug_764548s  s   zReTests.test_bug_764548c                 C   s   t dd}| dd |D g d t d}|ddd}| dd |D g d t d}|jdddd	}| d
d |D g d t d}|jdddd}| dd |D g d t d}|jdddd	}| dd |D ddg d S )Nr   r   c                 S      g | ]}| d qS r   rY   r   itemr   r   r   
<listcomp>{      z)ReTests.test_finditer.<locals>.<listcomp>r   rM   rw   c                 S   r  r   r  r  r   r   r   r    r  r   c                 S   r  r   r  r  r   r   r   r    r  )r   r6   c                 S   r  r   r  r  r   r   r   r    r  rN   r|   c                 S   r  r   r  r  r   r   r   r    r  r   )r1   rB   r-   r3   )r   iterr   r   r   r   test_finditery  s0   



zReTests.test_finditerc                 C   s   |  tdtd d S )NZ
bug_926075s
   bug_926075)ZassertIsNotr1   r3   rV   r   r   r   test_bug_926075  s   zReTests.test_bug_926075c                 C   s$   d}|  t|dg d d S )Nu   [.。．｡]za.b.cr  )r-   r1   r3   r   r   r   r   r   test_bug_931848  s   zReTests.test_bug_931848c                 C   sd   t dd}| t| d | tt| t dd}| |	  d | 
|	  d S )Nz\srD  )rM   r   )r1   rB   r-   nextrS   r0   StopIterationr3   r  rR   rT   )r   r  r  r   r   r   test_bug_581080  s   zReTests.test_bug_581080c                 C   sF   t dd}| t| d | t| d | tt| d S )Nz.*Zasdfr   )r   r   )r1   rB   r-   r  rS   r0   r  )r   r  r   r   r   test_bug_817234  s   zReTests.test_bug_817234c                 C   sT   g d}|D ]}|  td|d| qg d}|D ]}| td| qd S )N)7u   ๘u   ０z^\d$r   )u   Ⅵu   〹u   ₂u   ㊴)r-   r1   rU   rY   rT   )r   Zdecimal_digitsr(   Znot_decimal_digitsr   r   r   test_bug_6561  s   zReTests.test_bug_6561c                 C   sR   dd l }dD ] }| |}| td| | td| d qd S )Nr   ZbBuhHiIlLfds   blar   r   )arrayrT   r1   r3   rU   r-   r   )r   r  typecoder\   r   r   r   test_empty_array  s   
zReTests.test_empty_arrayc              	   C   s  d}d}t d| t jt jB }|d| }| | t d| t jt jB }|d| }| | t d| t j}|d| }| | t d| t j}|d| }| | t d| }|d| }| | t d| }|d| }| | t d| }|d| }| | t d| }|d| }| | | t d| | | t d| | | t d	| |t j | t d
| | | t d| |t j |d }| t}| t || W d    n	1 sw   Y  | 	t
|jd jd|  | 	|jd jt |dd  }| t}| t || W d    n	1 s@w   Y  | 	t
|jd jd|d d   | 	|jd jt t G tdt d}| t}| t |d W d    n	1 sw   Y  | 	t
|jd jd|  | 	|jd jt W d    n	1 sw   Y  | t | t d| d|  W d    n	1 sw   Y  | t | t d| d | W d    n	1 sw   Y  | t | t d| | W d    n	1 sw   Y  | t | t d| | W d    n	1 s8w   Y  | t | t d| | W d    n	1 sYw   Y  | t}| t d| d | W d    n	1 s|w   Y  | t
|jd jd | 	|jd jt | t}| t d| d | W d    n	1 sw   Y  | t
|jd jd | 	|jd jt | t}| t d| d | W d    n	1 sw   Y  | t
|jd jd | 	|jd jt d S ) Nu   Ạu   ạrh   ro   z(?i).z(?is).z	(?s)(?i).z(?ix) z (?i) z
(?x) (?i) z (?x) (?i) z(?i)r   z=Flags not at the start of the expression %r but at position 1z(?i)%sz.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?zIFlags not at the start of the expression %r (truncated) but at position 1   r2   s   A(?i)r@   z	(?s).(?i)z(?i) z (?x)z^(?i)z$|(?i)z(?:(?i)r,  zFlags not at the startz(^)?(?(1)(?i)z($)?(?(1)|(?i))r1   r3   r   r   rU   r  r}   rr  DeprecationWarningr-   rZ   warningsmessagefilename__file__catch_warningssimplefilterBytesWarningassertRegexr   )r   Z
upper_charZ
lower_charr  qZwarnsr   r   r   test_inline_flags  s   









zReTests.test_inline_flagsc                 C   s   t d}| |ddd | |ddd | |ddd t dt j}| |ddd	 | |ddd
 | |ddd dS )z>$ matches the end of string, and just before the terminating 
$#za
b
za
b#
#za
b
cza
b
c#ro   z#
#za#
b#
#za#
b#
c#N)r1   r3   r-   r<   r  r   r   r   r   test_dollar_matches_twice0  s   
z!ReTests.test_dollar_matches_twicec                 C   s   t d}t d}| t|jd | t|jd | t|jdd | t|jdd | t|jdd | t|jdd | t|jdd | t|jdd d S )Nrh      .r   rE   r   r   )r1   r3   r0   r   rU   r<   )r   r   bpatr   r   r   test_bytes_str_mixing<  s   

zReTests.test_bytes_str_mixingc                 C   s  dt jfD ]!}t d|t jB }| |d t d|}| |d qt dt jt jB }| |d t dt j}| |d t dt j}| |d t d}| |d dt jfD ]!}t d|t jB }| |d t d	|}| |d qi| t	t jd	t j | t j
t jd
 | t	t jdt jt jB  | t	t jdt j | t	t jdt j | t j
t jd d S )Nr      Àra   z\wu   (?a)Àz(?a)\w         \ws   (?u)\wz(?u)\wz(?au)\w)r1   r  r3   r  r  rU   r(  rT   r0   r   r2   )r   r   r   r   r   r   test_ascii_and_unicode_flagI  s0   
z#ReTests.test_ascii_and_unicode_flagc              
   C   s  t  }tddD ]@}z3t|g|}| }||krW q	||}t|dkr+W q	|||kr4W q	t	t|g}W  n t
tfyI   Y q	w d }d}t|tjtjB }|rb| || td| tj}|ru| || t|tj}|r| || tdtj}|r| || td}|r| || td}|r| || | ttjdtj | tjtjd	 | ttjd
tjtjB  | ttjdtj | ttjdtj | tjtjd d S )Nra  r  rM   rX  s   (?L)r  s   (?L)\wr   z(?L)r   s   (?a)s   (?aL))localegetpreferredencodingr   rp  rq  rU  r  r   r1   ry  UnicodeErrorr   r3   r*  r  r  rU   rT   r0   r   r2   r(  )r   encr   r   ZsletterZbletterr  r   r   r   r   test_locale_flagf  sP   


zReTests.test_locale_flagc                 C   s  |  tdd | tdd | tddtj |  tddtj | tdd |  tdd |  tdd |  tdd |  td	dtj | d
dd | ddd | ddd | ddd | ddd | ddd | ddd | ddd | ddd | ddd | ddd | dd d! | d"d#d | d$d#d | d%dd d S )&Nz(?i:a)bZAbZaBz(?-i:a)bz(?i:(?-i:a)b)z\w(?a:\W)\wu   àààz(?a:\W(?u:\w)\W)z\W(?u:\w)\Wz(?a)(?-a:\w)z8bad inline flags: cannot turn off flags 'a', 'u' and 'L'r|   z(?i-i:a)z(bad inline flags: flag turned on and offr   z(?au:a)z9bad inline flags: flags 'a', 'u' and 'L' are incompatibler   s   (?aL:a)z(?-zmissing flagrN   z(?-+z(?-zunknown flagz(?-iz	missing :z(?-i)z(?-i+z(?-izz(?i:r	  r   (?imissing -, : or )z(?i+z(?iz)r  r1   rU   rT   r  r(  r:   rV   r   r   r   test_scoped_flags  s@   zReTests.test_scoped_flagsc                 C   s   dD ]}|  t|d dtj qdD ]}|  t|d dtj q|  tdd |  tddtj |  tdd |  tdd	 |  td
dtj |  tdd |  tdd |  tdd d S )Nz 	
r\   )       	   
         r@   z(?x) az (?x) az(?x) (?x) az a(?x: b) cz ab cz a(?-x: b) crE  z(?x) a(?-x: b) cz	(?x) a| brE   r  r1   r   r  )r   spacer   r   r   test_ignore_spaces  s   zReTests.test_ignore_spacesc                 C   s   |  tddtj |  tddtj |  tdd |  tddtj |  tdd |  tdd	 |  td
dtj |  tdd |  tdd |  tdd d S )Nz#x
ar\   s   #x
ar@   z(?x)#x
az#x
(?x)#y
az(?x)#x
(?x)#y
az#x
a(?x:#y
b)#z
cz	#x
ab#z
cz#x
a(?-x:#y
b)#z
cza#y
bcz(?x)#x
a(?-x:#y
b)#z
cz(?x)#x
a|#y
brE   r+  rV   r   r   r   test_comments  s   zReTests.test_commentsc                 C   s   t d}| |ddd t d}| |ddd t d}| |d	d
 dd t d}| |ddd t d}| |ddd t d}| |dd
 dd d S )Nza(\w)zb\1r   r   za(.)u   aሴu   bሴz..c                 S   ri   )NrZ   r   rk   r   r   r   rm     rn   z'ReTests.test_bug_6509.<locals>.<lambda>Za5rZ   s   a(\w)s   b\1s   acs   bcs   a(.)s   as   bs   ..c                 S   ri   )N   bytesr   rk   r   r   r   rm     rn   s   a5r/  )r1   r3   r-   r<   r   r   r   r   test_bug_6509  s   





zReTests.test_bug_6509c              	   C   s   dd l }dd }| ttjdi  | t |dd|gdi d W d    n1 s,w   Y  | t |i dg dg g  W d    d S 1 sLw   Y  d S )Nr   r   ra  r\   r   r   )rb  r0   r   r1   rB   OverflowErrorr3   )r   rb  Zlong_overflowr   r   r   test_dealloc  s   "zReTests.test_deallocc                 C   s^   |  tdd |  tdd |  tdd |  tdd |  tdd d S )Nz123.*-z123abc-u   123é-u   123€-u   123􏿿-u   123é€􏿿-)r  r1   rR   rV   r   r   r   test_search_dot_unicode  s
   zReTests.test_search_dot_unicodec                 C   sP   t d}| |t j t |}| |t j | || | tt jd d S )Nrandom patternr   )r1   r3   assertIsInstancePatternr$   r0   r   )r   r/   Zsame_patternr   r   r   test_compile  s   

zReTests.test_compilerM   )sizeZmemusec                 C   sB   d| }t d|}| | | | | | | | d S )Nr\   r  )r1   rR   ZassertIsNotNoner-   r  r  )r   r8  rI   rl   r   r   r   test_large_search   s
   
zReTests.test_large_search   c                 C   s:   d| }t dd|\}}| || | ||d  d S )Nr\   r   rM   )r1   r   r-   )r   r8  rI   r   nr   r   r   test_large_subn  s   zReTests.test_large_subnc                 C   s2   |  tdddg |  tdd d d S )Nz	(?i)(a)\1u   aa Ār\   z
(?s).{1,3}u   ĀĀr   )r-   r1   rH   rU   rS   rV   r   r   r   test_bug_16688  s   zReTests.test_bug_16688c                 C   s  dd }|  td| d |  td| d |  td| d |  td| d |  td	| d |  td
| d | ttjddd   | ttjddd   | ttjddd   | ttjddd dd f  d S )Nr(   順 z.{65535})r   r  z	.{,65535}z
.{65535,}?z.{65536})r   r:  z	.{,65536}z
.{65536,}?.{%d}r   ra  .{,%d}.{%d,}?z.{%d,%d}   )r-   r1   rU   rS   r0   r1  r3   )r   r=   r   r   r   test_repeat_minmax_overflow  s   $z#ReTests.test_repeat_minmax_overflowc                 C   s   zddl m} W n ty   | d Y nw dd }| td|d  | | td|d  | d	 | td
|d  | | 	t
tjd|  | 	t
tjd|  | 	t
tjd
|  d S )Nr   )	MAXREPEATz requires _sre.MAXREPEAT constantr(   r>  r?  rM   r@  )r   r>  rA  )rb  rD  ImportErrorskipTestrT   r1   rU   r-   rS   r0   r1  r3   )r   rD  r=   r   r   r   %test_repeat_minmax_overflow_maxrepeat(  s   z-ReTests.test_repeat_minmax_overflow_maxrepeatc                 C      |  ddd d S )Nz
(?P=<foo>)z#bad character in group name '<foo>'r   r   rV   r   r   r   $test_backref_group_name_in_exception7     z,ReTests.test_backref_group_name_in_exceptionc                 C   rH  )Nz
(?P<?foo>)z"bad character in group name '?foo'r   r   rV   r   r   r   test_group_name_in_exception<  rJ  z$ReTests.test_group_name_in_exceptionc                 C   st   dD ]5}dD ]0}d| | d }| j t|tjddg|d | }| j t|tjddg|d qqd S )N)r  r  r  z{1}r  rh   Zyzr]   )r+   r_   )r-   r1   r3   r   rH   r  )r   r  r  r/   r   r   r   test_issue17998A  s   zReTests.test_issue17998c                 C   s   dt dfD ]}td|}dt|jt|jf }| t|| qdtdt	dt
dfD ]}td|}dt|jt|jf }| t|| q/ttdd\}}d	t|jt|jf }| t|| d
t|jt|jf }| t|| d S )Nz[abracadabra]z(.+)(.*?)\1z7<(%s\.)?%s object; span=\(1, 12\), match='abracadabra'>s   [abracadabra]s   (.+)(.*?)\1z8<(%s\.)?%s object; span=\(1, 12\), match=b'abracadabra'>z	(aa)|(bb)zaa bbz-<(%s\.)?%s object; span=\(0, 2\), match='aa'>z-<(%s\.)?%s object; span=\(3, 5\), match='bb'>)r   r1   rR   r%   r   r   r  reprr   rA   r   r"   rB   )r   r=   rl   r/   r  r  r   r   r   test_match_reprK  s0   zReTests.test_match_reprc                 C   s  |  tddg d |  tddg d |  tddg d |  tddg d	 |  tdd
dd |  tdd
dd |  tdddd |  tddg d |  tddg d |  dd tddD g d |  dd tddD g d d S )Nr   za::bc)r   r\   r   r   r   z\b|:+)r   r\   r   r   r   r   z(?<!\w)(?=\w)|:+)r   r\   r   r   z(?<=\w)(?!\w)|:+)r\   r   r   r   r/  z	-a-::-bc-z-a---bc-z(\b|:+)z[\1]z[]a[][::][]bc[])r   r   r   r   r   z\b|\w+c                 S      g | ]}|  qS r   rS   r   rl   r   r   r   r  t      z*ReTests.test_zerowidth.<locals>.<listcomp>)rK   rM   rM   rL   rN   rN   r   r   c                 S   rO  r   rP  rQ  r   r   r   r  v  rR  )rK   r   rS  rT  )rN   r   rU  )r-   r1   r   r<   rH   rB   rV   r   r   r   test_zerowidthe  s"   zReTests.test_zerowidthc                 C   sj   dD ]0}dD ]+}t d||f }|d}| |dd | |dd | |d	d
 qqd S )N){0,}r  r  z{1,187})rW  r  r  z^((x|y)%s)%sZxyyzyr   ZxyyrM   r   r   r)   )r1   r3   rU   r-   rY   )r   r  r  r   rl   r   r   r   test_bug_2537y  s   
zReTests.test_bug_2537c                 C   s   d}t  }t|tj W d    n1 sw   Y  d | _d}| | | t  }t|tj W d    n1 s>w   Y  | | | d S )Nz(\.)(?:[ch]|py)(?(1)$|: )a  SUBPATTERN 1 0 0
  LITERAL 46
BRANCH
  IN
    LITERAL 99
    LITERAL 104
OR
  LITERAL 112
  LITERAL 121
GROUPREF_EXISTS 1
  AT AT_END
ELSE
  LITERAL 58
  LITERAL 32

 0. INFO 8 0b1 2 5 (to 9)
      prefix_skip 0
      prefix [0x2e] ('.')
      overlap [0]
 9: MARK 0
11. LITERAL 0x2e ('.')
13. MARK 1
15. BRANCH 10 (to 26)
17.   IN 6 (to 24)
19.     LITERAL 0x63 ('c')
21.     LITERAL 0x68 ('h')
23.     FAILURE
24:   JUMP 9 (to 34)
26: branch 7 (to 33)
27.   LITERAL 0x70 ('p')
29.   LITERAL 0x79 ('y')
31.   JUMP 2 (to 34)
33: FAILURE
34: GROUPREF_EXISTS 0 6 (to 41)
37. AT END
39. JUMP 5 (to 45)
41: LITERAL 0x3a (':')
43. LITERAL 0x20 (' ')
45: SUCCESS
)r   r1   r3   DEBUGZmaxDiffr-   getvalue)r   r   outdumpr   r   r   test_debug_flag  s   )zReTests.test_debug_flagc                 C   s   t d}| |jdddd d | |jdddd d | |jdddd d | |jddddd	g | |jdd
dg d | |j	dddd  d d S )Nz(ab)Zabracadabrar{   rw   )r=   r6   r   )r{   rv   rv   rN   r   rM   )r=   r   )r   r   Z	racadabra)
r1   r3   r-   rU   rS   r   rR   rH   r   r  r   r   r   r   test_keyword_parameters  s*   
zReTests.test_keyword_parametersc                 C   s    |  tddtj d d S )Nz[a-c]+rJ  rP   )r-   r1   r   r   rS   rV   r   r   r   test_bug_20998  s    zReTests.test_bug_20998c              	   C   s   t t j}| t jt j| dD ]}z	t t j| W q t jy-   | d|  Y qw t  |   | 	  t  | 	  |   d S )Nen_US.iso88591
en_US.utf8test needs %s locale)
r  	setlocaleLC_CTYPE
addCleanupErrorrF  r1   r0  check_en_US_iso88591check_en_US_utf8)r   	oldlocalelocr   r   r   test_locale_caching  s   zReTests.test_locale_cachingc                 C   s   t t jd | tddtjtjB  | tddtjtjB  | tddtjtjB  | tdd | tdd | tdd d S )Nra              (?Li)   (?Li)   (?Li))r  rd  re  r  r1   rU   r  r   rV   r   r   r   rh       zReTests.check_en_US_iso88591c                 C   s   t t jd | tddtjtjB  | tddtjtjB  | tddtjtjB  | tdd | tdd | tdd d S )Nrb  rm  rn  ro  rp  rq  rr  )	r  rd  re  r  r1   rU   r  r   rT   rV   r   r   r   ri    rs  zReTests.check_en_US_utf8c              	   C   s  t t j}| t jt j| dD ]}z	t t j| W q t jy-   | d|  Y qw t t jd tdtjtj	B }tdtjtj	B }tdtjtj	B }tdtjtj	B }|||fD ]}| 
|d | 
|d | 
|d	 qb| |d
 | |d | |d	 t t jd |||fD ]}| 
|d | |d | |d	 q| 
|d
 | |d | |d	 d S )Nr`  rc  ra  rm  s   [a][a]s
   [az][az]s   [^][^]s   s   s   rb  )r  rd  re  rf  rg  rF  r1   r3   r  r   r  rU   rT   )r   rj  rk  Zp1Zp2Zp3Zp4r  r   r   r   test_locale_compiled  s8   zReTests.test_locale_compiledc                 C   s  |  tj}td W d    n1 sw   Y  |j}| |jt | |jd | |j	d | |j
d | |jd | |jt| | dt| | d|j |  tj}td W d    n1 sow   Y  |j}| |jt | |jd | |j	d |  tj}tdtj W d    n1 sw   Y  |j}| |j	d | |j
d	 | |jd
 | |jt| | dt| | dt| d S )Nu   (€))rN   rM   r   z at position 3s   ())zq
                (
                    abc
                )
                )
                (
                M   r      z at position 77z(line 5, column 17))r0   r1   r2   r3   r5   r5  r/   rZ   r-   r6   linenocolnoassertInr+   ZassertNotInrp  r  )r   r8   r9   r   r   r   
test_error  s>   zReTests.test_errorc                 C   s   |  ddd |  ddd |  ddd |  dd	d
 |  ddd |  ddd
 |  ddd
 |  ddd |  dd	d
 |  ddd |  dd	d d S )Nr  r	  r   z((a|b)z(a|b))zunbalanced parenthesisr   z(?Pzunexpected end of patternrN   z(?z)zunknown extension ?zrM   z(?iz)r!  r"  r#  z(?#abczmissing ), unterminated commentz(?<z(?<>)zunknown extension ?<>z(?r   r   rV   r   r   r   test_misc_errors8  s   zReTests.test_misc_errorsc                 C   s(   |  dttj |  dttj d S )Nr(  rB  )ry  rZ   r1   r   r   rV   r   r   r   	test_enumE  s   zReTests.test_enumc                 C   s   t dt j}| || | ||k t   t dt j}| t|t| | || t   t dt j}| || t   t d}| || | t	 ||k  W d    d S 1 sdw   Y  d S )Nr   ZXYZ)
r1   r3   r  r-   r8  r0  hashassertNotEqualr0   r   )r   pattern1pattern2pattern3Zpattern4r   r   r   test_pattern_compareK  s    

"zReTests.test_pattern_comparec                 C   s   t d}t   t d}| t|t| | || t   t d}t  tdt | 	|| W d    d S 1 sCw   Y  d S )Nr'  r   r2   )
r1   r3   r0  r-   r}  r  r  r  r  r~  )r   r  r  r  r   r   r   test_pattern_compare_bytesh  s   



"z"ReTests.test_pattern_compare_bytesc                 C   sp   t d}td|}td|}| | d | | d d|d d < | | d | | d d S )Ns   abcdefghs   [a-h]+s   [e-h]+s   efghr_   r   )rA   r1   rR   r-   rY   )r   rI   rl   Zm2r   r   r   test_bug_29444y  s   zReTests.test_bug_29444c                 C   s   d}d}|  t|| d d}d}|  t||ddg |  dd	 t||D dd
g d}d}|  t||ddg |  dd	 t||D ddddd dg d}|  dd	 t||D ddddd dg d}|  dd	 t||D ddddd ddd dg d S )Nza	xz\b(?=(\t)|(x))x)Nr(   r   z(?=(.)(.)?)r  )rE   r   c                 S   rO  r   )r   rQ  r   r   r   r    rR  z*ReTests.test_bug_34294.<locals>.<listcomp>r  z1(?=<(?P<tag>\w+)/?>(?:(?P<text>.+?)</(?P=tag)>)?)z<test><foo2/></test>)r~   <foo2/>)foo2r   c                 S   rO  r   r  rQ  r   r   r   r    rR  r~   r  )tagrw  r  z<test>Hello</test><foo/>c                 S   rO  r   r  rQ  r   r   r   r    rR  ZHellor  z<test>Hello</test><foo/><foo/>c                 S   rO  r   r  rQ  r   r   r   r    rR  )r-   r1   rR   r   rH   rB   rt  r   r   r   test_bug_34294  sD   zReTests.test_bug_34294r   )r   r   r   r.   r:   r>   rG   rJ   rW   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+  r1  r6  r9  r>  rA  rC  rH  rI  rW  rY  r^  r`  r   rk  rn  ru  rv  r1   r   rx  r=   rf  digitsrz  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.  r0  r2  r3  r7  r   r   r9  r<  r=  rC  rG  rI  rK  rL  rN  rV  rX  r]  r^  r_  rl  rh  ri  rt  rz  r{  r|  r  r  r  r  r   r   r   r   r      s   
		*05!,
$ ((&/
-

	 
			i-!









5		 $
r   c                   @   st   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S )PatternReprTestsc                 C   s   |  tt|| d S r   r-   rM  r1   r3   )r   r/   r   r   r   r   check  s   zPatternReprTests.checkc                 C   s   |  tt||| d S r   r  )r   r/   r   r   r   r   r   check_flags  s   zPatternReprTests.check_flagsc                 C      |  dd d S )Nr4  re.compile('random pattern')r  rV   r   r   r   test_without_flags     z#PatternReprTests.test_without_flagsc                 C      |  dtjd d S )Nr4  z+re.compile('random pattern', re.IGNORECASE))r  r1   r  rV   r   r   r   test_single_flag     
z!PatternReprTests.test_single_flagc                 C   s    |  dtjtjB tjB d d S )Nr4  z@re.compile('random pattern', re.IGNORECASE|re.DOTALL|re.VERBOSE))r  r1   r   r   r}   rV   r   r   r   test_multiple_flags  s   z$PatternReprTests.test_multiple_flagsc                 C   s0   |  dtjd |  dtjtjB tjB d d S )Nr4  r  z5re.compile('random pattern', re.IGNORECASE|re.DOTALL))r  r1   r!  r   r   rV   r   r   r   test_unicode_flag  s   
z"PatternReprTests.test_unicode_flagc                 C   r  )Nz(?i)patternz(re.compile('(?i)pattern', re.IGNORECASE)r  rV   r   r   r   r    r  z"PatternReprTests.test_inline_flagsc                 C   s&   |  ddd |  ddtjB d d S )Nr4  i 0 z&re.compile('random pattern', 0x123000)z4re.compile('random pattern', re.IGNORECASE|0x123000))r  r1   r   rV   r   r   r   test_unknown_flags  s   z#PatternReprTests.test_unknown_flagsc                 C   s    |  dd | dtjd d S )N   bytes patternzre.compile(b'bytes pattern')z&re.compile(b'bytes pattern', re.ASCII))r  r  r1   r   rV   r   r   r   
test_bytes  s   
zPatternReprTests.test_bytesc                 C   r  )Nr  z're.compile(b'bytes pattern', re.LOCALE))r  r1   r  rV   r   r   r   test_locale  r  zPatternReprTests.test_localec                 C   s(   |  dd |  dd |  dd d S )Nzrandom "double quoted" patternz,re.compile('random "double quoted" pattern')zrandom 'single quoted' patternz,re.compile("random 'single quoted' pattern")z!both 'single' and "double" quotesz1re.compile('both \'single\' and "double" quotes')r  rV   r   r   r   test_quotes  s   zPatternReprTests.test_quotesc                 C   s   ddd  }t t|}| t|d | |d d d t t|tj}| t|d | |d d d | |dd  d d S )	NzVery %spatternzlong r   i,     zre.compile('Very long long loniz, re.IGNORECASE))rM  r1   r3   Z
assertLessr   r-   r   )r   r/   r   r   r   r   test_long_pattern  s   z"PatternReprTests.test_long_patternc                 C   s   |  ttjd |  ttjtjB tjB d |  ttjtjB tjB dB d |  ttj d |  ttjtjB tjB  d |  ttjtjB tjB dB  d d S )Nzre.IGNORECASEz"re.IGNORECASE|re.DOTALL|re.VERBOSEi   z+re.IGNORECASE|re.DOTALL|re.VERBOSE|0x100000z~re.IGNORECASEz%~(re.IGNORECASE|re.DOTALL|re.VERBOSE)z.~(re.IGNORECASE|re.DOTALL|re.VERBOSE|0x100000))r-   rM  r1   r   r   r}   rV   r   r   r   test_flags_repr  s   z PatternReprTests.test_flags_reprN)r   r   r   r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r    s    
r  c                   @   s8   e Zd ZdZedd Zdd Zdd Zedd	 Zd
S )ImplementationTestz7
    Test implementation details of the re module.
    c                 C   s   |  t dtj_W d    n1 sw   Y  |  t dtj_W d    n1 s-w   Y  |  t td}t|d}d|_W d    d S 1 sRw   Y  d S )NrM   r   )	r0   r   r1   Matchr  r6  r3   r%   r  )r   r   tpr   r   r   test_immutable  s   


"z!ImplementationTest.test_immutablec                 C   s|   t j}| |dg  | |ddg | |dg d | |dg d | |dg d	 | |d
g d d S )Nr   r\   r   r   )r   r   r   r   Zaaaa)r   rM   r   rN   Zababba)r   r   rM   r   r   rM   Zabcabdac)r   r   r   rM   r   r   rM   r   )sre_compile_generate_overlap_tabler-   )r   fr   r   r   test_overlap_table	  s   z%ImplementationTest.test_overlap_tablec                 C   s    |  tjd |  tjd d S )Nr   )ZassertGreaterEqualr  rD  r  rV   r   r   r   test_signedness	  s   z"ImplementationTest.test_signednessc                 C   s:   t | tj t | tj td}t | t|d d S )Nr   )r   r1   r  r6  r3   r%   r  r   r   r   r   test_disallow_instantiation	  s   
z.ImplementationTest.test_disallow_instantiationN)	r   r   r   __doc__r   r  r  r  r  r   r   r   r   r    s    
	r  c                   @   r   )ExternalTestsc                 C   s   ddl m} |D ]o\}}| j||d\ t|}| || | || | || dd | dd  }| || | ||d | ||ddt	|  | ||ddt	|  W d   n1 srw   Y  qdS )zre_tests benchmarksr   )
benchmarksr/   r=   r  r@  N)
test.re_testsr  r4   r1   r3   r  rR   rU   r   r   )r   r  r/   rI   r  s2r   r   r   test_re_benchmarks	  s   
z ExternalTests.test_re_benchmarksc                 C   s  ddl m}m}m} |D ]}d } } } }}	t|dkr'|\}}}}}	nt|dkr3|\}}}ntd|| j||d ||krh| tj	 t
| W d   n1 s[w   Y  	 W d   qt
|}
|
|}||kr| |d 	 W d   q|  y | |d	 |d\}}|d| |jjd
}tddD ]!}z||}|du rd}W n ty   d}Y nw ||d| < q|jj D ]}z||}|du rd}W n ty   d}Y nw |||< q| t|||	d W d   n	1 sw   Y  zt|d}t|d}W n
 ty    Y nPw | d t
|}
| |
| W d   n	1 s?w   Y  | d t
|tj}
|
|}|du r`td| W d   n	1 skw   Y  |dd dkr|dd dkr|dur| d t
|}
| |
|||d  W d   n	1 sw   Y  | d t
|tj}
| |
| W d   n	1 sw   Y  | d t
|tj}
| |
| W d   n	1 sw   Y  W d   n	1 sw   Y  qdS )zre_tests test suiter   )testsFAILSYNTAX_ERRORNr   rN   z%Test tuples should have 3 or 5 fieldsr  zSucceeded incorrectlyzFailed incorrectly)foundr   r   rM   d   Nonerg  zg%dzgrouping errorr  zbytes pattern matchzlocale-sensitive matchz#=== Fails on locale-sensitive matchr   r7  zrange-limited matchzcase-insensitive matchzunicode-sensitive match)r  r  r  r  r   r   r4   r0   r1   r2   r3   rR   rT   r  rS   rY   r   r   r   r"  keysr-   evalrp  UnicodeEncodeErrorr*  printr  r  )r   r  r  r  tr/   rI   outcomer;   r   objresultr  r  Zvardictr   Zgir  bsr   r   r   test_re_tests,	  s   












$


zExternalTests.test_re_testsN)r   r   r   r  r  r   r   r   r   r  	  s    r  __main__)Ztest.supportr   r   r   r   r   r   r  r1   r  r=   Zunittestr  r   weakrefr	   rZ   r   rp  r   ZTestCaser   r  r  r  r   mainr   r   r   r   <module>   sF                      N'q