Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Made the reg-exp lookup tests more robust. they now pass for all data…

…base

backends and are not dependent on locale sorting order.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@5579 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 3a892122f2347cc2999857bda1139d084a8e7dce 1 parent acf0ff0
Malcolm Tredinnick authored

Showing 1 changed file with 29 additions and 26 deletions. Show diff stats Hide diff stats

  1. 55  tests/modeltests/lookup/models.py
55  tests/modeltests/lookup/models.py
@@ -5,6 +5,7 @@
5 5
 """
6 6
 
7 7
 from django.db import models
  8
+from django.conf import settings
8 9
 
9 10
 class Article(models.Model):
10 11
     headline = models.CharField(maxlength=100)
@@ -263,14 +264,14 @@ def __str__(self):
263 264
 >>> a3.save()
264 265
 >>> a4 = Article(pub_date=now, headline='fooo')
265 266
 >>> a4.save()
266  
->>> a5 = Article(pub_date=now, headline='Foo')
  267
+>>> a5 = Article(pub_date=now, headline='hey-Foo')
267 268
 >>> a5.save()
268 269
 
269 270
 # zero-or-more
270 271
 >>> Article.objects.filter(headline__regex=r'fo*')
271 272
 [<Article: f>, <Article: fo>, <Article: foo>, <Article: fooo>]
272 273
 >>> Article.objects.filter(headline__iregex=r'fo*')
273  
-[<Article: Foo>, <Article: f>, <Article: fo>, <Article: foo>, <Article: fooo>]
  274
+[<Article: f>, <Article: fo>, <Article: foo>, <Article: fooo>, <Article: hey-Foo>]
274 275
 
275 276
 # one-or-more
276 277
 >>> Article.objects.filter(headline__regex=r'fo+')
@@ -283,39 +284,39 @@ def __str__(self):
283 284
 # and some more:
284 285
 >>> a6 = Article(pub_date=now, headline='bar')
285 286
 >>> a6.save()
286  
->>> a7 = Article(pub_date=now, headline='Bar')
  287
+>>> a7 = Article(pub_date=now, headline='AbBa')
287 288
 >>> a7.save()
288 289
 >>> a8 = Article(pub_date=now, headline='baz')
289 290
 >>> a8.save()
290  
->>> a9 = Article(pub_date=now, headline='baZ')
  291
+>>> a9 = Article(pub_date=now, headline='baxZ')
291 292
 >>> a9.save()
292 293
 
293 294
 # leading anchor
294 295
 >>> Article.objects.filter(headline__regex=r'^b')
295  
-[<Article: baZ>, <Article: bar>, <Article: baz>]
296  
->>> Article.objects.filter(headline__iregex=r'^b')
297  
-[<Article: Bar>, <Article: baZ>, <Article: bar>, <Article: baz>]
  296
+[<Article: bar>, <Article: baxZ>, <Article: baz>]
  297
+>>> Article.objects.filter(headline__iregex=r'^a')
  298
+[<Article: AbBa>]
298 299
 
299 300
 # trailing anchor
300 301
 >>> Article.objects.filter(headline__regex=r'z$')
301 302
 [<Article: baz>]
302 303
 >>> Article.objects.filter(headline__iregex=r'z$')
303  
-[<Article: baZ>, <Article: baz>]
  304
+[<Article: baxZ>, <Article: baz>]
304 305
 
305 306
 # character sets
306 307
 >>> Article.objects.filter(headline__regex=r'ba[rz]')
307 308
 [<Article: bar>, <Article: baz>]
308  
->>> Article.objects.filter(headline__regex=r'ba[RZ]')
309  
-[<Article: baZ>]
310  
->>> Article.objects.filter(headline__iregex=r'ba[RZ]')
311  
-[<Article: Bar>, <Article: baZ>, <Article: bar>, <Article: baz>]
  309
+>>> Article.objects.filter(headline__regex=r'ba.[RxZ]')
  310
+[<Article: baxZ>]
  311
+>>> Article.objects.filter(headline__iregex=r'ba[RxZ]')
  312
+[<Article: bar>, <Article: baxZ>, <Article: baz>]
312 313
 
313 314
 # and yet more:
314 315
 >>> a10 = Article(pub_date=now, headline='foobar')
315 316
 >>> a10.save()
316 317
 >>> a11 = Article(pub_date=now, headline='foobaz')
317 318
 >>> a11.save()
318  
->>> a12 = Article(pub_date=now, headline='FooBarBaz')
  319
+>>> a12 = Article(pub_date=now, headline='ooF')
319 320
 >>> a12.save()
320 321
 >>> a13 = Article(pub_date=now, headline='foobarbaz')
321 322
 >>> a13.save()
@@ -323,26 +324,28 @@ def __str__(self):
323 324
 >>> a14.save()
324 325
 >>> a15 = Article(pub_date=now, headline='barfoobaz')
325 326
 >>> a15.save()
326  
->>> a16 = Article(pub_date=now, headline='BAZBARFOO')
  327
+>>> a16 = Article(pub_date=now, headline='bazbaRFOO')
327 328
 >>> a16.save()
328 329
 
329 330
 # alternation
330  
->>> Article.objects.filter(headline__regex=r'foo(bar|baz)')
  331
+>>> Article.objects.filter(headline__regex=r'oo(f|b)')
331 332
 [<Article: barfoobaz>, <Article: foobar>, <Article: foobarbaz>, <Article: foobaz>]
332  
->>> Article.objects.filter(headline__iregex=r'foo(bar|baz)')
333  
-[<Article: FooBarBaz>, <Article: barfoobaz>, <Article: foobar>, <Article: foobarbaz>, <Article: foobaz>]
334  
->>> Article.objects.filter(headline__regex=r'^foo(bar|baz)')
  333
+>>> Article.objects.filter(headline__iregex=r'oo(f|b)')
  334
+[<Article: barfoobaz>, <Article: foobar>, <Article: foobarbaz>, <Article: foobaz>, <Article: ooF>]
  335
+>>> Article.objects.filter(headline__regex=r'^foo(f|b)')
335 336
 [<Article: foobar>, <Article: foobarbaz>, <Article: foobaz>]
336 337
 
337 338
 # greedy matching
338  
->>> Article.objects.filter(headline__regex=r'f.*z')
339  
-[<Article: barfoobaz>, <Article: foobarbaz>, <Article: foobaz>, <Article: zoocarfaz>]
340  
->>> Article.objects.filter(headline__iregex=r'f.*z')
341  
-[<Article: FooBarBaz>, <Article: barfoobaz>, <Article: foobarbaz>, <Article: foobaz>, <Article: zoocarfaz>]
  339
+>>> Article.objects.filter(headline__regex=r'b.*az')
  340
+[<Article: barfoobaz>, <Article: baz>, <Article: bazbaRFOO>, <Article: foobarbaz>, <Article: foobaz>]
  341
+>>> Article.objects.filter(headline__iregex=r'b.*ar')
  342
+[<Article: bar>, <Article: barfoobaz>, <Article: bazbaRFOO>, <Article: foobar>, <Article: foobarbaz>]
  343
+"""}
  344
+
342 345
 
  346
+if settings.DATABASE_ENGINE not in ('mysql', 'mysql_old'):
  347
+    __test__['API_TESTS'] += r"""
343 348
 # grouping and backreferences
344 349
 >>> Article.objects.filter(headline__regex=r'b(.).*b\1')
345  
-[<Article: barfoobaz>, <Article: foobarbaz>]
346  
->>> Article.objects.filter(headline__iregex=r'b(.).*b\1')
347  
-[<Article: BAZBARFOO>, <Article: FooBarBaz>, <Article: barfoobaz>, <Article: foobarbaz>]
348  
-"""}
  350
+[<Article: barfoobaz>, <Article: bazbaRFOO>, <Article: foobarbaz>]
  351
+"""

0 notes on commit 3a89212

Please sign in to comment.
Something went wrong with that request. Please try again.