~ubuntu-branches/ubuntu/saucy/python-django/saucy-updates

« back to all changes in this revision

Viewing changes to tests/regressiontests/text/tests.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2009-07-29 11:26:28 UTC
  • mfrom: (1.2.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20090729112628-9qrzwnl9x32jxhbg
Tags: upstream-1.1
ImportĀ upstreamĀ versionĀ 1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# coding: utf-8
 
2
r"""
 
3
# Tests for stuff in django.utils.text and other text munging util functions.
 
4
 
 
5
>>> from django.utils.text import *
 
6
 
 
7
### smart_split ###########################################################
 
8
>>> list(smart_split(r'''This is "a person" test.'''))
 
9
[u'This', u'is', u'"a person"', u'test.']
 
10
>>> print list(smart_split(r'''This is "a person's" test.'''))[2]
 
11
"a person's"
 
12
>>> print list(smart_split(r'''This is "a person\"s" test.'''))[2]
 
13
"a person\"s"
 
14
>>> list(smart_split('''"a 'one'''))
 
15
[u'"a', u"'one"]
 
16
>>> print list(smart_split(r'''all friends' tests'''))[1]
 
17
friends'
 
18
>>> list(smart_split(u'url search_page words="something else"'))
 
19
[u'url', u'search_page', u'words="something else"']
 
20
>>> list(smart_split(u"url search_page words='something else'"))
 
21
[u'url', u'search_page', u"words='something else'"]
 
22
>>> list(smart_split(u'url search_page words "something else"'))
 
23
[u'url', u'search_page', u'words', u'"something else"']
 
24
>>> list(smart_split(u'url search_page words-"something else"'))
 
25
[u'url', u'search_page', u'words-"something else"']
 
26
>>> list(smart_split(u'url search_page words=hello'))
 
27
[u'url', u'search_page', u'words=hello']
 
28
>>> list(smart_split(u'url search_page words="something else'))
 
29
[u'url', u'search_page', u'words="something', u'else']
 
30
 
 
31
### urlquote #############################################################
 
32
>>> from django.utils.http import urlquote, urlquote_plus
 
33
>>> urlquote(u'Paris & Orl\xe9ans')
 
34
u'Paris%20%26%20Orl%C3%A9ans'
 
35
>>> urlquote(u'Paris & Orl\xe9ans', safe="&")
 
36
u'Paris%20&%20Orl%C3%A9ans'
 
37
>>> urlquote_plus(u'Paris & Orl\xe9ans')
 
38
u'Paris+%26+Orl%C3%A9ans'
 
39
>>> urlquote_plus(u'Paris & Orl\xe9ans', safe="&")
 
40
u'Paris+&+Orl%C3%A9ans'
 
41
 
 
42
### cookie_date, http_date ###############################################
 
43
>>> from django.utils.http import cookie_date, http_date
 
44
>>> t = 1167616461.0
 
45
>>> cookie_date(t)
 
46
'Mon, 01-Jan-2007 01:54:21 GMT'
 
47
>>> http_date(t)
 
48
'Mon, 01 Jan 2007 01:54:21 GMT'
 
49
 
 
50
### iri_to_uri ###########################################################
 
51
>>> from django.utils.encoding import iri_to_uri
 
52
>>> iri_to_uri(u'red%09ros\xe9#red')
 
53
'red%09ros%C3%A9#red'
 
54
>>> iri_to_uri(u'/blog/for/J\xfcrgen M\xfcnster/')
 
55
'/blog/for/J%C3%BCrgen%20M%C3%BCnster/'
 
56
>>> iri_to_uri(u'locations/%s' % urlquote_plus(u'Paris & Orl\xe9ans'))
 
57
'locations/Paris+%26+Orl%C3%A9ans'
 
58
 
 
59
iri_to_uri() is idempotent:
 
60
>>> iri_to_uri(iri_to_uri(u'red%09ros\xe9#red'))
 
61
'red%09ros%C3%A9#red'
 
62
"""