From c79f488027239d1a43582cc52f0688b23cf504fb Mon Sep 17 00:00:00 2001 From: Tomohiro Date: Tue, 3 Jul 2018 00:14:26 +0900 Subject: [PATCH] Fix os.unixToNativePath proc returns wrong result(#8179) (#8181) * Fix os.unixToNativePath proc returns wrong result(#8179) * Add tests for unixToNativePath --- lib/pure/ospaths.nim | 2 +- tests/stdlib/tospaths.nim | 41 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/stdlib/tospaths.nim diff --git a/lib/pure/ospaths.nim b/lib/pure/ospaths.nim index d9097d4192..96996bba7c 100644 --- a/lib/pure/ospaths.nim +++ b/lib/pure/ospaths.nim @@ -468,7 +468,7 @@ proc unixToNativePath*(path: string, drive=""): string {. elif path[0] == '.' and (path.len == 1 or path[1] == '/'): # current directory result = $CurDir - start = 2 + start = when doslikeFileSystem: 1 else: 2 else: result = "" start = 0 diff --git a/tests/stdlib/tospaths.nim b/tests/stdlib/tospaths.nim new file mode 100644 index 0000000000..0ac7729d92 --- /dev/null +++ b/tests/stdlib/tospaths.nim @@ -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"