3
# Tests for stuff in django.utils.text and other text munging util functions.
5
>>> from django.utils.text import *
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]
12
>>> print list(smart_split(r'''This is "a person\"s" test.'''))[2]
14
>>> list(smart_split('''"a 'one'''))
16
>>> print list(smart_split(r'''all friends' tests'''))[1]
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']
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'
42
### cookie_date, http_date ###############################################
43
>>> from django.utils.http import cookie_date, http_date
46
'Mon, 01-Jan-2007 01:54:21 GMT'
48
'Mon, 01 Jan 2007 01:54:21 GMT'
50
### iri_to_uri ###########################################################
51
>>> from django.utils.encoding import iri_to_uri
52
>>> iri_to_uri(u'red%09ros\xe9#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'
59
iri_to_uri() is idempotent:
60
>>> iri_to_uri(iri_to_uri(u'red%09ros\xe9#red'))