summary refs log tree commit diff stats
path: root/tests/converter
diff options
context:
space:
mode:
Diffstat (limited to 'tests/converter')
0 files changed, 0 insertions, 0 deletions
67'>67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
discard """
  output: '''true
true
true
true
true
true
true
true
true
All:
__really_obscure_dir_name/are.x
__really_obscure_dir_name/created
__really_obscure_dir_name/dirs
__really_obscure_dir_name/files.q
__really_obscure_dir_name/some
__really_obscure_dir_name/test
__really_obscure_dir_name/testing.r
__really_obscure_dir_name/these.txt
Files:
__really_obscure_dir_name/are.x
__really_obscure_dir_name/files.q
__really_obscure_dir_name/testing.r
__really_obscure_dir_name/these.txt
Dirs:
__really_obscure_dir_name/created
__really_obscure_dir_name/dirs
__really_obscure_dir_name/some
__really_obscure_dir_name/test
false
false
false
false
false
false
false
false
false
true
true
Raises
true
true
true
true

'''
"""
# test os path creation, iteration, and deletion

import os, strutils

let files = @["these.txt", "are.x", "testing.r", "files.q"]
let dirs = @["some", "created", "test", "dirs"]

let dname = "__really_obscure_dir_name"

createDir(dname)
echo dirExists(dname)

# Test creating files and dirs
for dir in dirs:
  createDir(dname/dir)
  echo dirExists(dname/dir)

for file in files:
  let fh = open(dname/file, fmReadWrite)
  fh.close()
  echo fileExists(dname/file)

echo "All:"

template norm(x): untyped =
  (when defined(windows): x.replace('\\', '/') else: x)

for path in walkPattern(dname/"*"):
  echo path.norm

echo "Files:"

for path in walkFiles(dname/"*"):
  echo path.norm

echo "Dirs:"

for path in walkDirs(dname/"*"):
  echo path.norm

# Test removal of files dirs
for dir in dirs:
  removeDir(dname/dir)
  echo dirExists(dname/dir)

for file in files:
  removeFile(dname/file)
  echo fileExists(dname/file)

removeDir(dname)
echo dirExists(dname)

# createDir should create recursive directories
createDir(dirs[0] / dirs[1])
echo dirExists(dirs[0] / dirs[1]) # true
removeDir(dirs[0])

# createDir should properly handle trailing separator
createDir(dname / "")
echo dirExists(dname) # true
removeDir(dname)

# createDir should raise IOError if the path exists
# and is not a directory
open(dname, fmWrite).close
try:
  createDir(dname)
except IOError:
  echo "Raises"
removeFile(dname)

# test copyDir:
createDir("a/b")
open("a/b/file.txt", fmWrite).close
createDir("a/b/c")
open("a/b/c/fileC.txt", fmWrite).close

copyDir("a", "../dest/a")
removeDir("a")

echo dirExists("../dest/a/b")
echo fileExists("../dest/a/b/file.txt")

echo fileExists("../dest/a/b/c/fileC.txt")
removeDir("../dest")

# Test get/set modification times
# Should support at least microsecond resolution
import times
let tm = fromUnix(0) + 100.microseconds
writeFile("a", "")
setLastModificationTime("a", tm)

when defined(macosx):
  echo "true"
else:
  echo getLastModificationTime("a") == tm
removeFile("a")

when defined(posix):

  block normalizedPath:
    block relative:
      doAssert normalizedPath(".") == "."
      doAssert normalizedPath("..") == ".."
      doAssert normalizedPath("../") == ".."
      doAssert normalizedPath("../..") == "../.."
      doAssert normalizedPath("../a/..") == ".."
      doAssert normalizedPath("../a/../") == ".."
      doAssert normalizedPath("./") == "."

    block absolute:
      doAssert normalizedPath("/") == "/"
      doAssert normalizedPath("/.") == "/"
      doAssert normalizedPath("/..") == "/"
      doAssert normalizedPath("/../") == "/"
      doAssert normalizedPath("/../..") == "/"
      doAssert normalizedPath("/../../") == "/"
      doAssert normalizedPath("/../../../") == "/"
      doAssert normalizedPath("/a/b/../../foo") == "/foo"
      doAssert normalizedPath("/a/b/../../../foo") == "/foo"
      doAssert normalizedPath("/./") == "/"
      doAssert normalizedPath("//") == "/"
      doAssert normalizedPath("///") == "/"
      doAssert normalizedPath("/a//b") == "/a/b"
      doAssert normalizedPath("/a///b") == "/a/b"
      doAssert normalizedPath("/a/b/c/..") == "/a/b"
      doAssert normalizedPath("/a/b/c/../") == "/a/b"

else:

  block normalizedPath:
    block relative:
      doAssert normalizedPath(".") == "."
      doAssert normalizedPath("..") == ".."
      doAssert normalizedPath("..\\") == ".."
      doAssert normalizedPath("..\\..") == "..\\.."
      doAssert normalizedPath("..\\a\\..") == ".."
      doAssert normalizedPath("..\\a\\..\\") == ".."
      doAssert normalizedPath(".\\") == "."

    block absolute:
      doAssert normalizedPath("\\") == "\\"
      doAssert normalizedPath("\\.") == "\\"
      doAssert normalizedPath("\\..") == "\\"
      doAssert normalizedPath("\\..\\") == "\\"
      doAssert normalizedPath("\\..\\..") == "\\"
      doAssert normalizedPath("\\..\\..\\") == "\\"
      doAssert normalizedPath("\\..\\..\\..\\") == "\\"
      doAssert normalizedPath("\\a\\b\\..\\..\\foo") == "\\foo"
      doAssert normalizedPath("\\a\\b\\..\\..\\..\\foo") == "\\foo"
      doAssert normalizedPath("\\.\\") == "\\"
      doAssert normalizedPath("\\\\") == "\\"
      doAssert normalizedPath("\\\\\\") == "\\"
      doAssert normalizedPath("\\a\\\\b") == "\\a\\b"
      doAssert normalizedPath("\\a\\\\\\b") == "\\a\\b"
      doAssert normalizedPath("\\a\\b\\c\\..") == "\\a\\b"
      doAssert normalizedPath("\\a\\b\\c\\..\\") == "\\a\\b"