'Copied from swift.common.utils.split_path'

def test_split_path(self):

    def _test_split_path(path, minsegs=1, maxsegs=None, rwl=False):
        req = swift.common.swob.Request.blank(path)
        return req.split_path(minsegs, maxsegs, rwl)
    self.assertRaises(ValueError, _test_split_path, '')
    self.assertRaises(ValueError, _test_split_path, '/')
    self.assertRaises(ValueError, _test_split_path, '//')
    self.assertEqual(_test_split_path('/a'), ['a'])
    self.assertRaises(ValueError, _test_split_path, '//a')
    self.assertEqual(_test_split_path('/a/'), ['a'])
    self.assertRaises(ValueError, _test_split_path, '/a/c')
    self.assertRaises(ValueError, _test_split_path, '//c')
    self.assertRaises(ValueError, _test_split_path, '/a/c/')
    self.assertRaises(ValueError, _test_split_path, '/a//')
    self.assertRaises(ValueError, _test_split_path, '/a', 2)
    self.assertRaises(ValueError, _test_split_path, '/a', 2, 3)
    self.assertRaises(ValueError, _test_split_path, '/a', 2, 3, True)
    self.assertEqual(_test_split_path('/a/c', 2), ['a', 'c'])
    self.assertEqual(_test_split_path('/a/c/o', 3), ['a', 'c', 'o'])
    self.assertRaises(ValueError, _test_split_path, '/a/c/o/r', 3, 3)
    self.assertEqual(_test_split_path('/a/c/o/r', 3, 3, True), ['a', 'c', 'o/r'])
    self.assertEqual(_test_split_path('/a/c', 2, 3, True), ['a', 'c', None])
    self.assertRaises(ValueError, _test_split_path, '/a', 5, 4)
    self.assertEqual(_test_split_path('/a/c/', 2), ['a', 'c'])
    self.assertEqual(_test_split_path('/a/c/', 2, 3), ['a', 'c', ''])
    try:
        _test_split_path('o\nn    e', 2)
    except ValueError as err:
        self.assertEqual(str(err), 'Invalid    path:    o%0An%20e')
    try:
        _test_split_path('o\nn    e', 2, 3, True)
    except ValueError as err:
        self.assertEqual(str(err), 'Invalid    path:    o%0An%20e')
