@@ -975,6 +975,48 @@ def test_is_absolute(self):
975975 self .assertTrue (P ('//a/b/c' ).is_absolute ())
976976 self .assertTrue (P ('//a/b/c/d' ).is_absolute ())
977977
978+ def test_join (self ):
979+ P = self .cls
980+ p = P ('C:/a/b' )
981+ pp = p .joinpath ('x/y' )
982+ self .assertEqual (pp , P ('C:/a/b/x/y' ))
983+ pp = p .joinpath ('/x/y' )
984+ self .assertEqual (pp , P ('C:/x/y' ))
985+ # Joining with a different drive => the first path is ignored, even
986+ # if the second path is relative.
987+ pp = p .joinpath ('D:x/y' )
988+ self .assertEqual (pp , P ('D:x/y' ))
989+ pp = p .joinpath ('D:/x/y' )
990+ self .assertEqual (pp , P ('D:/x/y' ))
991+ pp = p .joinpath ('//host/share/x/y' )
992+ self .assertEqual (pp , P ('//host/share/x/y' ))
993+ # Joining with the same drive => the first path is appended to if
994+ # the second path is relative.
995+ pp = p .joinpath ('c:x/y' )
996+ self .assertEqual (pp , P ('C:/a/b/x/y' ))
997+ pp = p .joinpath ('c:/x/y' )
998+ self .assertEqual (pp , P ('C:/x/y' ))
999+
1000+ def test_div (self ):
1001+ # Basically the same as joinpath()
1002+ P = self .cls
1003+ p = P ('C:/a/b' )
1004+ self .assertEqual (p / 'x/y' , P ('C:/a/b/x/y' ))
1005+ self .assertEqual (p / 'x' / 'y' , P ('C:/a/b/x/y' ))
1006+ self .assertEqual (p / '/x/y' , P ('C:/x/y' ))
1007+ self .assertEqual (p / '/x' / 'y' , P ('C:/x/y' ))
1008+ # Joining with a different drive => the first path is ignored, even
1009+ # if the second path is relative.
1010+ self .assertEqual (p / 'D:x/y' , P ('D:x/y' ))
1011+ self .assertEqual (p / 'D:' / 'x/y' , P ('D:x/y' ))
1012+ self .assertEqual (p / 'D:/x/y' , P ('D:/x/y' ))
1013+ self .assertEqual (p / 'D:' / '/x/y' , P ('D:/x/y' ))
1014+ self .assertEqual (p / '//host/share/x/y' , P ('//host/share/x/y' ))
1015+ # Joining with the same drive => the first path is appended to if
1016+ # the second path is relative.
1017+ self .assertEqual (p / 'C:x/y' , P ('C:/a/b/x/y' ))
1018+ self .assertEqual (p / 'C:/x/y' , P ('C:/x/y' ))
1019+
9781020 def test_is_reserved (self ):
9791021 P = self .cls
9801022 self .assertIs (False , P ('' ).is_reserved ())
0 commit comments