2017-10-24 13:30:02 +00:00
|
|
|
# coding: utf-8
|
2017-11-18 02:53:05 +00:00
|
|
|
from pydu.string import safeencode, safeunicode, strips, lstrips, rstrips
|
2017-10-24 13:30:02 +00:00
|
|
|
|
|
|
|
|
2017-11-18 02:53:05 +00:00
|
|
|
def test_safeencode():
|
|
|
|
assert safeencode('hello') == 'hello'
|
|
|
|
assert safeencode(1) == '1'
|
|
|
|
assert safeencode(u'中文') == '中文'
|
2017-10-24 13:30:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_safeunicode():
|
|
|
|
assert safeunicode('hello') == u'hello'
|
|
|
|
assert safeunicode(1) == u'1'
|
|
|
|
assert safeunicode('中文') == u'中文'
|
2017-10-02 08:52:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_lstrips():
|
|
|
|
assert lstrips('foobbar', '') == 'foobbar'
|
|
|
|
assert lstrips('foobar', 'fo') == 'obar'
|
|
|
|
assert lstrips('foofoobar', 'foo') == 'foobar'
|
|
|
|
assert lstrips('foobarbaz', ('foo', 'bar')) == 'baz'
|
|
|
|
assert lstrips('foobarbaz', ('bar', 'foo')) == 'barbaz'
|
|
|
|
|
|
|
|
|
|
|
|
def test_rstrips():
|
|
|
|
assert rstrips('foobbar', '') == 'foobbar'
|
|
|
|
assert rstrips('foobbar', 'bar') == 'foob'
|
|
|
|
assert rstrips('foobarbar', 'bar') == 'foobar'
|
|
|
|
assert rstrips('fozfoobar', ('bar', 'foo')) == 'foz'
|
|
|
|
assert rstrips('fozfoobar', ('foo', 'bar')) == 'fozfoo'
|
|
|
|
|
|
|
|
|
|
|
|
def test_strips():
|
|
|
|
assert strips('foobarfoo', '') == 'foobarfoo'
|
|
|
|
assert strips('foobarfoo', 'foo') == 'bar'
|
|
|
|
assert strips('foobarfoo', ('foo', 'bar')) == ''
|