|
| 1 | +# Copyright (c) 2007, Enthought, Inc. |
| 2 | +# All rights reserved. |
| 3 | +# |
| 4 | +# This software is provided without warranty under the terms of the BSD |
| 5 | +# license included in /LICENSE.txt and may be redistributed only |
| 6 | +# under the conditions described in the aforementioned license. The license |
| 7 | +# is also available online at http://www.enthought.com/licenses/BSD.txt |
| 8 | + |
| 9 | +from __future__ import absolute_import, print_function, unicode_literals |
| 10 | + |
| 11 | +import unittest |
| 12 | + |
| 13 | +import six |
| 14 | + |
| 15 | +from traits._py2to3 import str_find, str_rfind |
| 16 | + |
| 17 | + |
| 18 | +class TestPy2to3(unittest.TestCase): |
| 19 | + def test_str_find(self): |
| 20 | + # Note: inputs are Unicode strings. |
| 21 | + self.assertEqual(str_find("abcabc", "c"), 2) |
| 22 | + self.assertEqual(str_find("abcabc", "d"), -1) |
| 23 | + |
| 24 | + def test_str_rfind(self): |
| 25 | + # Note: inputs are Unicode strings. |
| 26 | + self.assertEqual(str_rfind("abcabc", "c"), 5) |
| 27 | + self.assertEqual(str_rfind("abcabc", "d"), -1) |
| 28 | + |
| 29 | + if six.PY2: |
| 30 | + def test_str_find_with_bytestrings(self): |
| 31 | + # Try all possible mixes of Unicode with bytes. |
| 32 | + self.assertEqual(str_find("abcabc", "b"), 1) |
| 33 | + self.assertEqual(str_find(u"abcabc", "b"), 1) |
| 34 | + self.assertEqual(str_find("abcabc", u"b"), 1) |
| 35 | + self.assertEqual(str_find(u"abcabc", u"b"), 1) |
| 36 | + |
| 37 | + def test_str_rfind_with_bytestrings(self): |
| 38 | + # Try all possible mixes of Unicode with bytes. |
| 39 | + self.assertEqual(str_rfind("abcabc", "b"), 4) |
| 40 | + self.assertEqual(str_rfind(u"abcabc", "b"), 4) |
| 41 | + self.assertEqual(str_rfind("abcabc", u"b"), 4) |
| 42 | + self.assertEqual(str_rfind(u"abcabc", u"b"), 4) |
0 commit comments