* Fix os.unixToNativePath proc returns wrong result(#8179) * Add tests for unixToNativePath
This commit is contained in:
parent
2c98b4943e
commit
c79f488027
2 changed files with 42 additions and 1 deletions
|
|
@ -468,7 +468,7 @@ proc unixToNativePath*(path: string, drive=""): string {.
|
||||||
elif path[0] == '.' and (path.len == 1 or path[1] == '/'):
|
elif path[0] == '.' and (path.len == 1 or path[1] == '/'):
|
||||||
# current directory
|
# current directory
|
||||||
result = $CurDir
|
result = $CurDir
|
||||||
start = 2
|
start = when doslikeFileSystem: 1 else: 2
|
||||||
else:
|
else:
|
||||||
result = ""
|
result = ""
|
||||||
start = 0
|
start = 0
|
||||||
|
|
|
||||||
41
tests/stdlib/tospaths.nim
Normal file
41
tests/stdlib/tospaths.nim
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
discard """
|
||||||
|
file: "tospaths.nim"
|
||||||
|
output: ""
|
||||||
|
"""
|
||||||
|
# test the ospaths module
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
doAssert unixToNativePath("") == ""
|
||||||
|
doAssert unixToNativePath(".") == $CurDir
|
||||||
|
doAssert unixToNativePath("..") == $ParDir
|
||||||
|
doAssert isAbsolute(unixToNativePath("/"))
|
||||||
|
doAssert isAbsolute(unixToNativePath("/", "a"))
|
||||||
|
doAssert isAbsolute(unixToNativePath("/a"))
|
||||||
|
doAssert isAbsolute(unixToNativePath("/a", "a"))
|
||||||
|
doAssert isAbsolute(unixToNativePath("/a/b"))
|
||||||
|
doAssert isAbsolute(unixToNativePath("/a/b", "a"))
|
||||||
|
doAssert unixToNativePath("a/b") == joinPath("a", "b")
|
||||||
|
|
||||||
|
when defined(macos):
|
||||||
|
doAssert unixToNativePath("./") == ":"
|
||||||
|
doAssert unixToNativePath("./abc") == ":abc"
|
||||||
|
doAssert unixToNativePath("../abc") == "::abc"
|
||||||
|
doAssert unixToNativePath("../../abc") == ":::abc"
|
||||||
|
doAssert unixToNativePath("/abc", "a") == "abc"
|
||||||
|
doAssert unixToNativePath("/abc/def", "a") == "abc:def"
|
||||||
|
elif doslikeFileSystem:
|
||||||
|
doAssert unixToNativePath("./") == ".\\"
|
||||||
|
doAssert unixToNativePath("./abc") == ".\\abc"
|
||||||
|
doAssert unixToNativePath("../abc") == "..\\abc"
|
||||||
|
doAssert unixToNativePath("../../abc") == "..\\..\\abc"
|
||||||
|
doAssert unixToNativePath("/abc", "a") == "a:\\abc"
|
||||||
|
doAssert unixToNativePath("/abc/def", "a") == "a:\\abc\\def"
|
||||||
|
else:
|
||||||
|
#Tests for unix
|
||||||
|
doAssert unixToNativePath("./") == "./"
|
||||||
|
doAssert unixToNativePath("./abc") == "./abc"
|
||||||
|
doAssert unixToNativePath("../abc") == "../abc"
|
||||||
|
doAssert unixToNativePath("../../abc") == "../../abc"
|
||||||
|
doAssert unixToNativePath("/abc", "a") == "/abc"
|
||||||
|
doAssert unixToNativePath("/abc/def", "a") == "/abc/def"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue