tntpath.nim 2.9 KB

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