tpathutils.nim 1.0 KB

12345678910111213141516171819
  1. import compiler/pathutils
  2. import os, strutils
  3. doAssert AbsoluteDir"/Users/me///" / RelativeFile"z.nim" == AbsoluteFile"/Users/me/z.nim"
  4. doAssert AbsoluteDir"/Users/me" / RelativeFile"../z.nim" == AbsoluteFile"/Users/z.nim"
  5. doAssert AbsoluteDir"/Users/me/" / RelativeFile"../z.nim" == AbsoluteFile"/Users/z.nim"
  6. doAssert relativePath("/foo/bar.nim", "/foo/", '/') == "bar.nim"
  7. doAssert $RelativeDir"foo/bar" == "foo/bar"
  8. doAssert RelativeDir"foo/bar" == RelativeDir"foo/bar"
  9. doAssert RelativeFile"foo/bar".changeFileExt(".txt") == RelativeFile"foo/bar.txt"
  10. doAssert RelativeFile"foo/bar".addFileExt(".txt") == RelativeFile"foo/bar.txt"
  11. doAssert not RelativeDir"foo/bar".isEmpty
  12. doAssert RelativeDir"".isEmpty
  13. when defined(windows):
  14. let nasty = string(AbsoluteDir(r"C:\Users\rumpf\projects\nim\tests\nimble\nimbleDir\linkedPkgs\pkgB-#head\../../simplePkgs/pkgB-#head/") / RelativeFile"pkgA/module.nim")
  15. doAssert nasty.replace('/', '\\') == r"C:\Users\rumpf\projects\nim\tests\nimble\nimbleDir\simplePkgs\pkgB-#head\pkgA\module.nim"