'Normalize paths.'

def test_Normalizer(self):

    for (inp, outp) in [('a', ['a']), ('/a', ['a']), ('/', []), ('a/b/c', ['a', 'b', 'c']), ('/a/b/c', ['a', 'b', 'c']), ('/a/', ['a']), ('a/', ['a'])]:
        self.assertEqual(ftp.toSegments([], inp), outp)
    for (inp, outp) in [('b', ['a', 'b']), ('b/', ['a', 'b']), ('/b', ['b']), ('/b/', ['b']), ('b/c', ['a', 'b', 'c']), ('b/c/', ['a', 'b', 'c']), ('/b/c', ['b', 'c']), ('/b/c/', ['b', 'c'])]:
        self.assertEqual(ftp.toSegments(['a'], inp), outp)
    for (inp, outp) in [('//', []), ('//a', ['a']), ('a//', ['a']), ('a//b', ['a', 'b'])]:
        self.assertEqual(ftp.toSegments([], inp), outp)
    for (inp, outp) in [('//', []), ('//b', ['b']), ('b//c', ['a', 'b', 'c'])]:
        self.assertEqual(ftp.toSegments(['a'], inp), outp)
    for (inp, outp) in [('..', []), ('../', []), ('a/..', ['x']), ('/a/..', []), ('/a/b/..', ['a']), ('/a/b/../', ['a']), ('/a/b/../c', ['a', 'c']), ('/a/b/../c/', ['a', 'c']), ('/a/b/../../c', ['c']), ('/a/b/../../c/', ['c']), ('/a/b/../../c/..', []), ('/a/b/../../c/../', [])]:
        self.assertEqual(ftp.toSegments(['x'], inp), outp)
    for inp in ['..', '../', 'a/../..', 'a/../../', '/..', '/../', '/a/../..', '/a/../../', '/a/b/../../..']:
        self.assertRaises(ftp.InvalidPath, ftp.toSegments, [], inp)
    for inp in ['../..', '../../', '../a/../..']:
        self.assertRaises(ftp.InvalidPath, ftp.toSegments, ['x'], inp)
