tos.nim 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. static: doAssert defined(nodejs)
  2. import os
  3. block:
  4. doAssert "./foo//./bar/".normalizedPath == "foo/bar"
  5. doAssert relativePath(".//foo/bar", "foo") == "bar"
  6. doAssert "/".isAbsolute
  7. doAssert not "".isAbsolute
  8. doAssert not ".".isAbsolute
  9. doAssert not "foo".isAbsolute
  10. doAssert relativePath("", "bar") == ""
  11. doAssert normalizedPath(".///foo//./") == "foo"
  12. let cwd = getCurrentDir()
  13. let isWindows = '\\' in cwd
  14. # defined(windows) doesn't work with -d:nodejs but should
  15. # these actually break because of that (see https://github.com/nim-lang/Nim/issues/13469)
  16. if not isWindows:
  17. doAssert cwd.isAbsolute
  18. doAssert relativePath(getCurrentDir() / "foo", "bar") == "../foo"
  19. import std/sequtils
  20. template main =
  21. putEnv("foo", "bar")
  22. doAssert getEnv("foo") == "bar"
  23. doAssert existsEnv("foo")
  24. putEnv("foo", "")
  25. doAssert existsEnv("foo")
  26. putEnv("foo", "bar2")
  27. doAssert getEnv("foo") == "bar2"
  28. when nimvm:
  29. discard
  30. else:
  31. # need support in vmops: envPairs, delEnv
  32. let s = toSeq(envPairs())
  33. doAssert ("foo", "bar2") in s
  34. doAssert ("foo", "bar") notin s
  35. delEnv("foo")
  36. doAssert not existsEnv("foo")
  37. static: main()
  38. main()