tntpath.nim 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. discard """
  2. matrix: "--mm:refc; --mm:orc"
  3. """
  4. import std/private/ntpath
  5. import std/assertions
  6. block: # From Python's `Lib/test/test_ntpath.py`
  7. doAssert splitDrive(r"c:\foo\bar") == (r"c:", r"\foo\bar")
  8. doAssert splitDrive(r"c:/foo/bar") == (r"c:", r"/foo/bar")
  9. doAssert splitDrive(r"\\conky\mountpoint\foo\bar") == (r"\\conky\mountpoint", r"\foo\bar")
  10. doAssert splitDrive(r"//conky/mountpoint/foo/bar") == (r"//conky/mountpoint", r"/foo/bar")
  11. doAssert splitDrive(r"\\\conky\mountpoint\foo\bar") == (r"", r"\\\conky\mountpoint\foo\bar")
  12. doAssert splitDrive(r"///conky/mountpoint/foo/bar") == (r"", r"///conky/mountpoint/foo/bar")
  13. doAssert splitDrive(r"\\conky\\mountpoint\foo\bar") == (r"", r"\\conky\\mountpoint\foo\bar")
  14. doAssert splitDrive(r"//conky//mountpoint/foo/bar") == (r"", r"//conky//mountpoint/foo/bar")
  15. # Issue #19911: UNC part containing U+0130
  16. doAssert splitDrive(r"//conky/MOUNTPOİNT/foo/bar") == (r"//conky/MOUNTPOİNT", r"/foo/bar")
  17. # gh-81790: support device namespace, including UNC drives.
  18. doAssert splitDrive(r"//?/c:") == (r"//?/c:", r"")
  19. doAssert splitDrive(r"//?/c:/") == (r"//?/c:", r"/")
  20. doAssert splitDrive(r"//?/c:/dir") == (r"//?/c:", r"/dir")
  21. doAssert splitDrive(r"//?/UNC") == (r"", r"//?/UNC")
  22. doAssert splitDrive(r"//?/UNC/") == (r"", r"//?/UNC/")
  23. doAssert splitDrive(r"//?/UNC/server/") == (r"//?/UNC/server/", r"")
  24. doAssert splitDrive(r"//?/UNC/server/share") == (r"//?/UNC/server/share", r"")
  25. doAssert splitDrive(r"//?/UNC/server/share/dir") == (r"//?/UNC/server/share", r"/dir")
  26. doAssert splitDrive(r"//?/VOLUME{00000000-0000-0000-0000-000000000000}/spam") == (r"//?/VOLUME{00000000-0000-0000-0000-000000000000}", r"/spam")
  27. doAssert splitDrive(r"//?/BootPartition/") == (r"//?/BootPartition", r"/")
  28. doAssert splitDrive(r"\\?\c:") == (r"\\?\c:", r"")
  29. doAssert splitDrive(r"\\?\c:\") == (r"\\?\c:", r"\")
  30. doAssert splitDrive(r"\\?\c:\dir") == (r"\\?\c:", r"\dir")
  31. doAssert splitDrive(r"\\?\UNC") == (r"", r"\\?\UNC")
  32. doAssert splitDrive(r"\\?\UNC\") == (r"", r"\\?\UNC\")
  33. doAssert splitDrive(r"\\?\UNC\server\") == (r"\\?\UNC\server\", r"")
  34. doAssert splitDrive(r"\\?\UNC\server\share") == (r"\\?\UNC\server\share", r"")
  35. doAssert splitDrive(r"\\?\UNC\server\share\dir") == (r"\\?\UNC\server\share", r"\dir")
  36. doAssert splitDrive(r"\\?\VOLUME{00000000-0000-0000-0000-000000000000}\spam") == (r"\\?\VOLUME{00000000-0000-0000-0000-000000000000}", r"\spam")
  37. doAssert splitDrive(r"\\?\BootPartition\") == (r"\\?\BootPartition", r"\")
  38. block:
  39. doAssert splitDrive(r"C:") == (r"C:", r"")
  40. doAssert splitDrive(r"C:\") == (r"C:", r"\")
  41. doAssert splitDrive(r"non/absolute/path") == (r"", r"non/absolute/path")
  42. # Special for `\`-rooted paths on Windows. I don't know if this is correct,
  43. # rbut `\` is not recognized as a drive, in contrast to `C:` or `\?\c:`.
  44. # This behavior is the same for Python's `splitdrive` function.
  45. doAssert splitDrive(r"\\") == (r"", r"\\")