Use ^ instead of - in slices

This commit is contained in:
def
2015-03-27 11:49:28 +01:00
parent 2b80d75aa2
commit 64903e7050
10 changed files with 93 additions and 93 deletions

View File

@@ -7,6 +7,6 @@ discard """
proc test: string =
result = "blah"
result[1 .. -1]
result[1 .. ^1]
echo test()

View File

@@ -27,7 +27,7 @@ proc refExpr(exprNode: NimNode): string {.compileTime.} =
"expr" & $(exprNodes.len - 1)
proc derefExpr(exprRef: string): NimNode {.compileTime.} =
exprNodes[parseInt(exprRef[4 .. -1])]
exprNodes[parseInt(exprRef[4 .. ^1])]
#===============================================================================
# Define a type that allows a callable expression to be mapped onto elements

View File

@@ -36,7 +36,7 @@ echo()
var myseq = @[1, 2, 3, 4, 5, 6]
myseq[0..2] = myseq[-3.. -1]
myseq[0..2] = myseq[^3 .. ^1]
for x in items(myseq): stdout.write(x)
echo()
@@ -46,7 +46,7 @@ echo mystr
mystr[4..4] = "u"
# test full replacement
mystr[.. -2] = "egerichtet"
mystr[.. ^2] = "egerichtet"
echo mystr
@@ -54,6 +54,6 @@ mystr[0..2] = "ve"
echo mystr
var s = "abcdef"
s[1 .. -2] = "xyz"
s[1 .. ^2] = "xyz"
assert s == "axyzf"

View File

@@ -22,35 +22,35 @@ proc delNimCache() =
removeDir(nimcacheDir)
except OSError:
echo "[Warning] could not delete: ", nimcacheDir
proc runRodFiles(r: var TResults, cat: Category, options: string) =
template test(filename: expr): stmt =
testSpec r, makeTest(rodfilesDir / filename, options, cat, actionRun)
delNimCache()
# test basic recompilation scheme:
test "hallo"
test "hallo"
# test incremental type information:
test "hallo2"
delNimCache()
# test type converters:
test "aconv"
test "bconv"
delNimCache()
# test G, A, B example from the documentation; test init sections:
test "deada"
test "deada2"
delNimCache()
# test method generation:
test "bmethods"
test "bmethods2"
delNimCache()
# test generics:
test "tgeneric1"
test "tgeneric2"
@@ -79,8 +79,8 @@ proc runBasicDLLTest(c, r: var TResults, cat: Category, options: string) =
options & " --app:lib -d:createNimRtl", cat)
testSpec c, makeTest("tests/dll/server.nim",
options & " --app:lib -d:useNimRtl", cat)
when defined(Windows):
when defined(Windows):
# windows looks in the dir of the exe (yay!):
var nimrtlDll = DynlibFormat % "nimrtl"
safeCopyFile("lib" / nimrtlDll, "tests/dll" / nimrtlDll)
@@ -91,14 +91,14 @@ proc runBasicDLLTest(c, r: var TResults, cat: Category, options: string) =
putEnv("LD_LIBRARY_PATH", "lib:" & libpath)
var serverDll = DynlibFormat % "server"
safeCopyFile("tests/dll" / serverDll, "lib" / serverDll)
testSpec r, makeTest("tests/dll/client.nim", options & " -d:useNimRtl",
testSpec r, makeTest("tests/dll/client.nim", options & " -d:useNimRtl",
cat, actionRun)
proc dllTests(r: var TResults, cat: Category, options: string) =
# dummy compile result:
var c = initResults()
runBasicDLLTest c, r, cat, options
runBasicDLLTest c, r, cat, options & " -d:release"
runBasicDLLTest c, r, cat, options & " --gc:boehm"
@@ -134,7 +134,7 @@ proc gcTests(r: var TResults, cat: Category, options: string) =
test "cycleleak"
test "closureleak"
testWithoutMs "refarrayleak"
test "stackrefleak"
test "cyclecollector"
@@ -147,7 +147,7 @@ proc threadTests(r: var TResults, cat: Category, options: string) =
" -d:release", cat, actionRun)
testSpec r, makeTest("tests/threads" / filename, options &
" --tlsEmulation:on", cat, actionRun)
test "tactors"
test "tactors2"
test "threadex"
@@ -182,7 +182,7 @@ proc jsTests(r: var TResults, cat: Category, options: string) =
actionRun, targetJS)
testSpec r, makeTest(filename, options & " -d:nodejs -d:release", cat,
actionRun, targetJS)
for t in os.walkFiles("tests/js/t*.nim"):
test(t)
for testfile in ["exception/texceptions", "exception/texcpt1",
@@ -199,13 +199,13 @@ proc jsTests(r: var TResults, cat: Category, options: string) =
proc findMainFile(dir: string): string =
# finds the file belonging to ".nim.cfg"; if there is no such file
# it returns the some ".nim" file if there is only one:
# it returns the some ".nim" file if there is only one:
const cfgExt = ".nim.cfg"
result = ""
var nimFiles = 0
for kind, file in os.walkDir(dir):
if kind == pcFile:
if file.endsWith(cfgExt): return file[.. -(cfgExt.len+1)] & ".nim"
if file.endsWith(cfgExt): return file[.. ^(cfgExt.len+1)] & ".nim"
elif file.endsWith(".nim"):
if result.len == 0: result = file
inc nimFiles
@@ -236,7 +236,7 @@ type PackageFilter = enum
pfExtraOnly
pfAll
let
let
nimbleExe = findExe("nimble")
nimbleDir = getHomeDir() / ".nimble"
packageDir = nimbleDir / "pkgs"

View File

@@ -59,7 +59,7 @@ proc callCompiler(cmdTemplate, filename, options: string,
target: TTarget): TSpec =
let c = parseCmdLine(cmdTemplate % ["target", targetToCmd[target],
"options", options, "file", filename.quoteShell])
var p = startProcess(command=c[0], args=c[1.. -1],
var p = startProcess(command=c[0], args=c[1.. ^1],
options={poStdErrToStdOut, poUseShell})
let outp = p.outputStream
var suc = ""
@@ -284,7 +284,7 @@ proc main() =
let testsDir = "tests" & DirSep
for kind, dir in walkDir(testsDir):
assert testsDir.startsWith(testsDir)
let cat = dir[testsDir.len .. -1]
let cat = dir[testsDir.len .. ^1]
if kind == pcDir and cat notin ["testament", "testdata", "nimcache"]:
processCategory(r, Category(cat), p.cmdLineRest.string)
for a in AdditionalCategories: