File: quote_test.py

package info (click to toggle)
python-flanker 0.9.15-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 17,976 kB
  • sloc: python: 9,308; makefile: 4
file content (55 lines) | stat: -rw-r--r-- 1,743 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# coding=utf-8
from nose.tools import eq_
from flanker.addresslib.quote import smart_quote, smart_unquote


def test_quote():
    eq_('"foo, bar"', smart_quote('foo, bar'))
    eq_('"foo; bar"', smart_quote('foo; bar'))
    eq_('"foo< bar"', smart_quote('foo< bar'))
    eq_('"foo> bar"', smart_quote('foo> bar'))
    eq_('"foo\\" bar"', smart_quote('foo" bar'))
    eq_('"foo: bar"', smart_quote('foo: bar'))


def test_quote__periods():
    eq_('foo. bar', smart_quote('foo. bar'))


def test_quote__spaces():
    eq_('foo bar', smart_quote('foo bar'))
    eq_('" foo bar"', smart_quote(' foo bar'))
    eq_('"foo bar "', smart_quote('foo bar '))
    eq_('" foo bar "', smart_quote(' foo bar '))
    eq_('foo\tbar', smart_quote('foo\tbar'))
    eq_('"\tfoo\tbar"', smart_quote('\tfoo\tbar'))
    eq_('"foo\tbar\t"', smart_quote('foo\tbar\t'))
    eq_('"\tfoo\tbar\t"', smart_quote('\tfoo\tbar\t'))


def test_quote__escaping():
    eq_('"f\\\\o\\"o \\"bar\\""', smart_quote('f\\o"o "bar"'))
    eq_('"\\"foo\\""', smart_quote('"foo"'))
    eq_('"\\"foo\\"bar\\""', smart_quote('"foo"bar"'))


def test_quote__nothing_to_quote():
    eq_('', smart_quote(''))
    eq_('foo bar', smart_quote('foo bar'))
    eq_("!#$%&'*+-/=?^_`{|}~",
        smart_quote("!#$%&'*+-/=?^_`{|}~"))


def test_unquote():
    eq_('foo bar "(bazz)" blah oops',
        smart_unquote('foo "bar \\"(bazz)\\" blah" oops'))
    eq_('foo;  bar. \\bazz\\', smart_unquote('"foo;"  "bar." "\\\\bazz\\\\"'))
    eq_('"foo"bar"', smart_unquote('"\\"foo\\"bar\\"'))


def test_unquote__nothing_to_unquote():
    eq_('foo\\.;\tbar', smart_unquote('foo\\.;\tbar'))


def test_unquote__unicode():
    eq_(u'Превед Медвед', smart_unquote(u'Превед Медвед'))