Created
December 30, 2013 17:25
-
-
Save Varriount/8185073 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os, sequtils | |
| const doslike = defined(windows) or defined(OS2) or defined(DOS) | |
| proc u2np(path: string): string = | |
| return unixToNativePath(path) | |
| proc testUnixToNativePath() = | |
| # Have input and output example paths for each system. | |
| # Depending on the system, run the input path and compare against | |
| # the output path. | |
| let inputPaths = @[ | |
| r"/user/tester/nimrod" | |
| ] | |
| var outputPaths: seq[string] | |
| when defined(macos): | |
| outputPaths = @[ | |
| r"user:tester:nimrod:" | |
| ] | |
| elif doslike: | |
| outputPaths = @[ | |
| r"C:\user\tester\nimrod" | |
| ] | |
| elif defined(PalmOS) or defined(MorphOS): | |
| outputPaths = @[ | |
| r"/user/tester/nimrod" | |
| ] | |
| elif defined(RISCOS): | |
| outputPaths = @[ | |
| r"user.tester.nimrod" | |
| ] | |
| else: | |
| outputPaths = @[ | |
| r"/usr/tester/nimrod" | |
| ] | |
| for pathPair in zip(inputPaths, outputPaths): | |
| var (iPath, oPath) = pathPair | |
| echo("Input: " & iPath & " -> Output: " & unixToNativePath(iPath) & " -> Expected: " & oPath) | |
| assert unixToNativePath(iPath) == oPath | |
| proc testExists(path: string, a, b, c: bool) = | |
| echo("Testing whether '" & path & "' exists.") | |
| assert(existsDir(path) == a) | |
| assert(existsFile(path) == b) | |
| assert(existsSymlink(path) == c) | |
| proc testExistsProcs() = | |
| # Create a folder, file, symlink to folder, symlink to file | |
| block checkTargetExists: | |
| createDir(u2np"testExistsProcs") | |
| testExists(u2np"testExistsProcs", true, false, false) | |
| createDir(u2np"testExistsProcs/testDir") | |
| testExists(u2np"testExistsProcs/testDir", true, false, false) | |
| close(open(u2np"testExistsProcs/testFile.txt", fmReadWrite)) | |
| testExists(u2np"testExistsProcs/testFile.txt", false, true, false) | |
| makeSymlink(u2np"testExistsProcs/testFile.txt", u2np"testFileLink") | |
| testExists(u2np"testFileLink", false, true, true) | |
| makeSymlink(u2np"testExistsProcs/testDir", u2np"testDirLink") | |
| testExists(u2np"testDirLink", true, false, true) | |
| var comp = pcfile | |
| case comp | |
| of pcfile..pcLinkToDir: echo("Hi") | |
| block checkTargetNotExists: | |
| removeDir(u2np"testExistsProcs/testDir") | |
| testExists(u2np"testExistsProcs/testDir", false, false, false) | |
| removeFile(u2np"testExistsProcs/testFile.txt") | |
| testExists(u2np"testExistsProcs/testFile.txt", false, false, false) | |
| removeDir(u2np"testExistsProcs") | |
| testExists(u2np"testExistsProcs", false, false, false) | |
| removeFile(u2np"testFileLink") | |
| testExists(u2np"testFileLink", false, false, false) | |
| removeDir(u2np"testDirLink") | |
| testExists(u2np"testDirLink", false, false, false) | |
| when defined(isMainModule): | |
| testUnixToNativePath() | |
| testExistsProcs() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment