diff options
| author | Loic Bistuer <loic.bistuer@gmail.com> | 2014-09-23 19:45:59 +0700 |
|---|---|---|
| committer | Loic Bistuer <loic.bistuer@gmail.com> | 2014-09-23 19:45:59 +0700 |
| commit | 3c6ac0bab8bfaf1f1bb79a8b6a7a36533666908c (patch) | |
| tree | c6dcd5e7f164164a1eed144f6949c1eb2e61de7b /tests/utils_tests/test_text.py | |
| parent | 0dab07e5da43f8965db24adc4363cec01944de4d (diff) | |
Consolidated some text utils into the utils_tests test package.
Diffstat (limited to 'tests/utils_tests/test_text.py')
| -rw-r--r-- | tests/utils_tests/test_text.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/utils_tests/test_text.py b/tests/utils_tests/test_text.py index 4015556bae..4ef30314cf 100644 --- a/tests/utils_tests/test_text.py +++ b/tests/utils_tests/test_text.py @@ -7,12 +7,58 @@ import warnings from django.test import SimpleTestCase from django.utils import six, text from django.utils.deprecation import RemovedInDjango19Warning +from django.utils.encoding import force_text +from django.utils.functional import lazy +from django.utils.translation import override + +lazystr = lazy(force_text, six.text_type) IS_WIDE_BUILD = (len('\U0001F4A9') == 1) class TestUtilsText(SimpleTestCase): + def test_get_text_list(self): + self.assertEqual(text.get_text_list(['a', 'b', 'c', 'd']), 'a, b, c or d') + self.assertEqual(text.get_text_list(['a', 'b', 'c'], 'and'), 'a, b and c') + self.assertEqual(text.get_text_list(['a', 'b'], 'and'), 'a and b') + self.assertEqual(text.get_text_list(['a']), 'a') + self.assertEqual(text.get_text_list([]), '') + with override('ar'): + self.assertEqual(text.get_text_list(['a', 'b', 'c']), "a، b أو c") + + def test_smart_split(self): + testdata = [ + ('This is "a person" test.', + ['This', 'is', '"a person"', 'test.']), + ('This is "a person\'s" test.', + ['This', 'is', '"a person\'s"', 'test.']), + ('This is "a person\\"s" test.', + ['This', 'is', '"a person\\"s"', 'test.']), + ('"a \'one', + ['"a', "'one"]), + ('all friends\' tests', + ['all', 'friends\'', 'tests']), + ('url search_page words="something else"', + ['url', 'search_page', 'words="something else"']), + ("url search_page words='something else'", + ['url', 'search_page', "words='something else'"]), + ('url search_page words "something else"', + ['url', 'search_page', 'words', '"something else"']), + ('url search_page words-"something else"', + ['url', 'search_page', 'words-"something else"']), + ('url search_page words=hello', + ['url', 'search_page', 'words=hello']), + ('url search_page words="something else', + ['url', 'search_page', 'words="something', 'else']), + ("cut:','|cut:' '", + ["cut:','|cut:' '"]), + (lazystr("a b c d"), # Test for #20231 + ['a', 'b', 'c', 'd']), + ] + for test, expected in testdata: + self.assertEqual(list(text.smart_split(test)), expected) + def test_truncate_chars(self): truncator = text.Truncator( 'The quick brown fox jumped over the lazy dog.' |
