From a854c9fa1a7c7bad53235acc5b270a8483e74821 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Sat, 22 Feb 2020 01:02:36 -0800 Subject: [PATCH] fix bug: isAbsolutePath now works with -d:js; add tests --- lib/pure/os.nim | 4 +++- tests/js/tos.nim | 5 +++++ tests/stdlib/tos.nim | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/pure/os.nim b/lib/pure/os.nim index 7317fc377cb11..5d0d2916a8990 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -277,8 +277,10 @@ proc isAbsolute*(path: string): bool {.rtl, noSideEffect, extern: "nos$1", raise result = path[0] != ':' elif defined(RISCOS): result = path[0] == '$' - elif defined(posix): + elif defined(posix) or defined(js): result = path[0] == '/' + else: + doAssert false # if ever hits here, adapt as needed when FileSystemCaseSensitive: template `!=?`(a, b: char): bool = a != b diff --git a/tests/js/tos.nim b/tests/js/tos.nim index 7395a0ad7a99d..d1744e85eb6c6 100644 --- a/tests/js/tos.nim +++ b/tests/js/tos.nim @@ -5,3 +5,8 @@ import os block: doAssert "./foo//./bar/".normalizedPath == "foo/bar" doAssert relativePath(".//foo/bar", "foo") == "bar" + doAssert "/".isAbsolute + doAssert relativePath(getCurrentDir()) == "." + doAssert relativePath(getCurrentDir() / "foo", "bar") == "../foo" + doAssert relativePath("", "bar") == "" + doAssert normalizedPath(".///foo//./") == "foo" diff --git a/tests/stdlib/tos.nim b/tests/stdlib/tos.nim index 07e8a172ff1d4..3d6fa0fcddf6a 100644 --- a/tests/stdlib/tos.nim +++ b/tests/stdlib/tos.nim @@ -342,6 +342,7 @@ block ospaths: doAssert relativePath("", "foo") == "" doAssert relativePath("././/foo", "foo//./") == "." + doAssert relativePath(getCurrentDir()) == "." doAssert relativePath(getCurrentDir() / "bar") == "bar" doAssert relativePath(getCurrentDir() / "bar", "foo") == "../bar".unixToNativePath doAssert relativePath("bar", getCurrentDir() / "foo") == "../bar".unixToNativePath