From 6f4e933fcc78da11ec43214efd3472192030eced Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Sun, 1 Jul 2007 01:17:51 +0000 Subject: newforms-admin: Merged to [5571] git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@5572 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/modeltests/lookup/models.py | 94 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) (limited to 'tests/modeltests') diff --git a/tests/modeltests/lookup/models.py b/tests/modeltests/lookup/models.py index 6af70f8351..60ed6f7685 100644 --- a/tests/modeltests/lookup/models.py +++ b/tests/modeltests/lookup/models.py @@ -251,4 +251,98 @@ Traceback (most recent call last): ... TypeError: Cannot resolve keyword 'headline__starts' into field. Choices are: id, headline, pub_date +# Create some articles with a bit more interesting headlines for testing field lookups: +>>> now = datetime.now() +>>> for a in Article.objects.all(): +... a.delete() +>>> a1 = Article(pub_date=now, headline='f') +>>> a1.save() +>>> a2 = Article(pub_date=now, headline='fo') +>>> a2.save() +>>> a3 = Article(pub_date=now, headline='foo') +>>> a3.save() +>>> a4 = Article(pub_date=now, headline='fooo') +>>> a4.save() +>>> a5 = Article(pub_date=now, headline='Foo') +>>> a5.save() + +# zero-or-more +>>> Article.objects.filter(headline__regex=r'fo*') +[, , , ] +>>> Article.objects.filter(headline__iregex=r'fo*') +[, , , , ] + +# one-or-more +>>> Article.objects.filter(headline__regex=r'fo+') +[, , ] + +# wildcard +>>> Article.objects.filter(headline__regex=r'fooo?') +[, ] + +# and some more: +>>> a6 = Article(pub_date=now, headline='bar') +>>> a6.save() +>>> a7 = Article(pub_date=now, headline='Bar') +>>> a7.save() +>>> a8 = Article(pub_date=now, headline='baz') +>>> a8.save() +>>> a9 = Article(pub_date=now, headline='baZ') +>>> a9.save() + +# leading anchor +>>> Article.objects.filter(headline__regex=r'^b') +[, , ] +>>> Article.objects.filter(headline__iregex=r'^b') +[, , , ] + +# trailing anchor +>>> Article.objects.filter(headline__regex=r'z$') +[] +>>> Article.objects.filter(headline__iregex=r'z$') +[, ] + +# character sets +>>> Article.objects.filter(headline__regex=r'ba[rz]') +[, ] +>>> Article.objects.filter(headline__regex=r'ba[RZ]') +[] +>>> Article.objects.filter(headline__iregex=r'ba[RZ]') +[, , , ] + +# and yet more: +>>> a10 = Article(pub_date=now, headline='foobar') +>>> a10.save() +>>> a11 = Article(pub_date=now, headline='foobaz') +>>> a11.save() +>>> a12 = Article(pub_date=now, headline='FooBarBaz') +>>> a12.save() +>>> a13 = Article(pub_date=now, headline='foobarbaz') +>>> a13.save() +>>> a14 = Article(pub_date=now, headline='zoocarfaz') +>>> a14.save() +>>> a15 = Article(pub_date=now, headline='barfoobaz') +>>> a15.save() +>>> a16 = Article(pub_date=now, headline='BAZBARFOO') +>>> a16.save() + +# alternation +>>> Article.objects.filter(headline__regex=r'foo(bar|baz)') +[, , , ] +>>> Article.objects.filter(headline__iregex=r'foo(bar|baz)') +[, , , , ] +>>> Article.objects.filter(headline__regex=r'^foo(bar|baz)') +[, , ] + +# greedy matching +>>> Article.objects.filter(headline__regex=r'f.*z') +[, , , ] +>>> Article.objects.filter(headline__iregex=r'f.*z') +[, , , , ] + +# grouping and backreferences +>>> Article.objects.filter(headline__regex=r'b(.).*b\1') +[, ] +>>> Article.objects.filter(headline__iregex=r'b(.).*b\1') +[, , , ] """} -- cgit v1.3