Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
1151a8cd
Kaydet (Commit)
1151a8cd
authored
Agu 08, 2000
tarafından
Fredrik Lundh
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
-- whitespace cleanup (more tests to be added in the next commit)
üst
8141cf5c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
23 deletions
+23
-23
test_re.py
Lib/test/test_re.py
+23
-23
No files found.
Lib/test/test_re.py
Dosyayı görüntüle @
1151a8cd
...
...
@@ -37,20 +37,20 @@ if verbose:
try
:
assert
re
.
sub
(
"(?i)b+"
,
"x"
,
"bbbb BBBB"
)
==
'x x'
def
bump_num
(
matchobj
):
int_value
=
int
(
matchobj
.
group
(
0
))
return
str
(
int_value
+
1
)
assert
re
.
sub
(
r'\d+'
,
bump_num
,
'08.2 -2 23x99y'
)
==
'9.3 -3 24x100y'
assert
re
.
sub
(
r'\d+'
,
bump_num
,
'08.2 -2 23x99y'
,
3
)
==
'9.3 -3 23x99y'
assert
re
.
sub
(
'.'
,
lambda
m
:
r"\n"
,
'x'
)
==
'
\\
n'
assert
re
.
sub
(
'.'
,
r"\n"
,
'x'
)
==
'
\n
'
s
=
r"\1\1"
assert
re
.
sub
(
'(.)'
,
s
,
'x'
)
==
'xx'
assert
re
.
sub
(
'(.)'
,
re
.
escape
(
s
),
'x'
)
==
s
assert
re
.
sub
(
'(.)'
,
re
.
escape
(
s
),
'x'
)
==
s
assert
re
.
sub
(
'(.)'
,
lambda
m
:
s
,
'x'
)
==
s
assert
re
.
sub
(
'(?P<a>x)'
,
'
\
g<a>
\
g<a>'
,
'xx'
)
==
'xxxx'
...
...
@@ -146,7 +146,7 @@ except AssertionError:
if
verbose
:
print
'Running tests on re.split'
try
:
assert
re
.
split
(
":"
,
":a:b::c"
)
==
[
''
,
'a'
,
'b'
,
''
,
'c'
]
assert
re
.
split
(
":*"
,
":a:b::c"
)
==
[
''
,
'a'
,
'b'
,
'c'
]
...
...
@@ -165,7 +165,7 @@ try:
assert
re
.
split
(
':'
,
'a:b:c:d'
,
2
)
==
[
'a'
,
'b'
,
'c:d'
]
assert
re
.
split
(
"(:)"
,
":a:b::c"
,
2
)
==
[
''
,
':'
,
'a'
,
':'
,
'b::c'
]
assert
re
.
split
(
"(:*)"
,
":a:b::c"
,
2
)
==
[
''
,
':'
,
'a'
,
':'
,
'b::c'
]
assert
re
.
split
(
"(:*)"
,
":a:b::c"
,
2
)
==
[
''
,
':'
,
'a'
,
':'
,
'b::c'
]
except
AssertionError
:
raise
TestFailed
,
"qualified re.split"
...
...
@@ -187,29 +187,29 @@ if verbose:
try
:
# No groups at all
m
=
re
.
match
(
'a'
,
'a'
)
;
assert
m
.
groups
()
==
()
m
=
re
.
match
(
'a'
,
'a'
)
;
assert
m
.
groups
()
==
()
# A single group
m
=
re
.
match
(
'(a)'
,
'a'
)
;
assert
m
.
groups
()
==
(
'a'
,)
m
=
re
.
match
(
'(a)'
,
'a'
)
;
assert
m
.
groups
()
==
(
'a'
,)
pat
=
re
.
compile
(
'((a)|(b))(c)?'
)
assert
pat
.
match
(
'a'
)
.
groups
()
==
(
'a'
,
'a'
,
None
,
None
)
assert
pat
.
match
(
'b'
)
.
groups
()
==
(
'b'
,
None
,
'b'
,
None
)
assert
pat
.
match
(
'ac'
)
.
groups
()
==
(
'a'
,
'a'
,
None
,
'c'
)
assert
pat
.
match
(
'bc'
)
.
groups
()
==
(
'b'
,
None
,
'b'
,
'c'
)
assert
pat
.
match
(
'bc'
)
.
groups
(
""
)
==
(
'b'
,
""
,
'b'
,
'c'
)
assert
pat
.
match
(
'a'
)
.
groups
()
==
(
'a'
,
'a'
,
None
,
None
)
assert
pat
.
match
(
'b'
)
.
groups
()
==
(
'b'
,
None
,
'b'
,
None
)
assert
pat
.
match
(
'ac'
)
.
groups
()
==
(
'a'
,
'a'
,
None
,
'c'
)
assert
pat
.
match
(
'bc'
)
.
groups
()
==
(
'b'
,
None
,
'b'
,
'c'
)
assert
pat
.
match
(
'bc'
)
.
groups
(
""
)
==
(
'b'
,
""
,
'b'
,
'c'
)
except
AssertionError
:
raise
TestFailed
,
"match .groups() method"
try
:
# A single group
m
=
re
.
match
(
'(a)'
,
'a'
)
assert
m
.
group
(
0
)
==
'a'
;
assert
m
.
group
(
0
)
==
'a'
m
=
re
.
match
(
'(a)'
,
'a'
)
assert
m
.
group
(
0
)
==
'a'
;
assert
m
.
group
(
0
)
==
'a'
assert
m
.
group
(
1
)
==
'a'
;
assert
m
.
group
(
1
,
1
)
==
(
'a'
,
'a'
)
pat
=
re
.
compile
(
'(?:(?P<a1>a)|(?P<b2>b))(?P<c3>c)?'
)
assert
pat
.
match
(
'a'
)
.
group
(
1
,
2
,
3
)
==
(
'a'
,
None
,
None
)
assert
pat
.
match
(
'b'
)
.
group
(
'a1'
,
'b2'
,
'c3'
)
==
(
None
,
'b'
,
None
)
assert
pat
.
match
(
'ac'
)
.
group
(
1
,
'b2'
,
3
)
==
(
'a'
,
None
,
'c'
)
assert
pat
.
match
(
'a'
)
.
group
(
1
,
2
,
3
)
==
(
'a'
,
None
,
None
)
assert
pat
.
match
(
'b'
)
.
group
(
'a1'
,
'b2'
,
'c3'
)
==
(
None
,
'b'
,
None
)
assert
pat
.
match
(
'ac'
)
.
group
(
1
,
'b2'
,
3
)
==
(
'a'
,
None
,
'c'
)
except
AssertionError
:
raise
TestFailed
,
"match .group() method"
...
...
@@ -242,8 +242,8 @@ try:
assert
re
.
I
==
re
.
IGNORECASE
assert
re
.
L
==
re
.
LOCALE
assert
re
.
M
==
re
.
MULTILINE
assert
re
.
S
==
re
.
DOTALL
assert
re
.
X
==
re
.
VERBOSE
assert
re
.
S
==
re
.
DOTALL
assert
re
.
X
==
re
.
VERBOSE
except
AssertionError
:
raise
TestFailed
,
're module constants'
...
...
@@ -260,7 +260,7 @@ if verbose:
else
:
# To save time, only run the first and last 10 tests
#tests = tests[:10] + tests[-10:]
pass
pass
for
t
in
tests
:
sys
.
stdout
.
flush
()
...
...
@@ -268,7 +268,7 @@ for t in tests:
if
len
(
t
)
==
5
:
pattern
,
s
,
outcome
,
repl
,
expected
=
t
elif
len
(
t
)
==
3
:
pattern
,
s
,
outcome
=
t
pattern
,
s
,
outcome
=
t
else
:
raise
ValueError
,
(
'Test tuples should have 3 or 5 fields'
,
t
)
...
...
@@ -276,7 +276,7 @@ for t in tests:
obj
=
re
.
compile
(
pattern
)
except
re
.
error
:
if
outcome
==
SYNTAX_ERROR
:
pass
# Expected a syntax error
else
:
else
:
print
'=== Syntax error:'
,
t
except
KeyboardInterrupt
:
raise
KeyboardInterrupt
except
:
...
...
@@ -330,7 +330,7 @@ for t in tests:
# of the match and see if it still succeeds. \B will
# break (because it won't match at the end or start of a
# string), so we'll ignore patterns that feature it.
if
pattern
[:
2
]
!=
'
\\
B'
and
pattern
[
-
2
:]
!=
'
\\
B'
and
result
!=
None
:
obj
=
re
.
compile
(
pattern
)
result
=
obj
.
search
(
s
,
result
.
start
(
0
),
result
.
end
(
0
)
+
1
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment