Skip to content

Commit

Permalink
fix bug: isAbsolutePath now works with -d:js; add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Feb 22, 2020
1 parent 28c2724 commit a854c9f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/pure/os.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/js/tos.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 1 addition & 0 deletions tests/stdlib/tos.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a854c9f

Please sign in to comment.