fixed some tests

This commit is contained in:
Araq
2011-11-19 12:23:03 +01:00
parent 62aa8bed3b
commit d0772feb08
15 changed files with 135 additions and 128 deletions

View File

@@ -110,7 +110,7 @@ proc executeCgi(server: var TServer, client: TSocket, path, query: string,
if L.startsWith("content-length:"):
var i = len("content-length:")
while L[i] in Whitespace: inc(i)
contentLength = parseInt(copy(L, i))
contentLength = parseInt(substr(L, i))
if contentLength < 0:
badRequest(client)
@@ -176,7 +176,7 @@ proc acceptRequest(server: var TServer, client: TSocket) =
# extract path
if q >= 0:
# strip "?..." from path, this may be found in both POST and GET
path = data[1].copy(0, q-1)
path = data[1].substr(0, q-1)
else:
path = data[1]
# path starts with "/", by adding "." in front of it we serve files from cwd
@@ -187,7 +187,7 @@ proc acceptRequest(server: var TServer, client: TSocket) =
if cmpIgnoreCase(data[0], "GET") == 0:
if q >= 0:
cgi = true
query = data[1].copy(q+1)
query = data[1].substr(q+1)
elif cmpIgnoreCase(data[0], "POST") == 0:
cgi = true
meth = reqPost

View File

@@ -7,56 +7,56 @@
# distribution, for details about the copyright.
#
## This module contains simple high-level procedures for dealing with the
## web. Use cases:
##
## * requesting URLs
## * sending and retrieving emails
## * sending and retrieving files from an FTP server
##
## Currently only requesting URLs is implemented. The implementation depends
## on the libcurl library!
##
## **Deprecated since version 0.8.8:** Use the ``httpclient`` module instead.
##
{.deprecated.}
import libcurl, streams
proc curlwrapperWrite(p: pointer, size, nmemb: int,
data: pointer): int {.cdecl.} =
var stream = cast[PStream](data)
stream.writeData(stream, p, size*nmemb)
return size*nmemb
proc URLretrieveStream*(url: string): PStream =
## retrieves the given `url` and returns a stream which one can read from to
## obtain the contents. Returns nil if an error occurs.
result = newStringStream()
var hCurl = easy_init()
if hCurl == nil: return nil
if easy_setopt(hCurl, OPT_URL, url) != E_OK: return nil
if easy_setopt(hCurl, OPT_WRITEFUNCTION,
curlwrapperWrite) != E_OK: return nil
if easy_setopt(hCurl, OPT_WRITEDATA, result) != E_OK: return nil
if easy_perform(hCurl) != E_OK: return nil
easy_cleanup(hCurl)
proc URLretrieveString*(url: string): TaintedString =
## retrieves the given `url` and returns the contents. Returns nil if an
## error occurs.
var stream = newStringStream()
var hCurl = easy_init()
if hCurl == nil: return
if easy_setopt(hCurl, OPT_URL, url) != E_OK: return
if easy_setopt(hCurl, OPT_WRITEFUNCTION,
curlwrapperWrite) != E_OK: return
if easy_setopt(hCurl, OPT_WRITEDATA, stream) != E_OK: return
if easy_perform(hCurl) != E_OK: return
easy_cleanup(hCurl)
result = stream.data.TaintedString
when isMainModule:
echo URLretrieveString("http://nimrod.ethexor.com/")
## This module contains simple high-level procedures for dealing with the
## web. Use cases:
##
## * requesting URLs
## * sending and retrieving emails
## * sending and retrieving files from an FTP server
##
## Currently only requesting URLs is implemented. The implementation depends
## on the libcurl library!
##
## **Deprecated since version 0.8.8:** Use the ``httpclient`` module instead.
##
{.deprecated.}
import libcurl, streams
proc curlwrapperWrite(p: pointer, size, nmemb: int,
data: pointer): int {.cdecl.} =
var stream = cast[PStream](data)
stream.writeData(p, size*nmemb)
return size*nmemb
proc URLretrieveStream*(url: string): PStream =
## retrieves the given `url` and returns a stream which one can read from to
## obtain the contents. Returns nil if an error occurs.
result = newStringStream()
var hCurl = easy_init()
if hCurl == nil: return nil
if easy_setopt(hCurl, OPT_URL, url) != E_OK: return nil
if easy_setopt(hCurl, OPT_WRITEFUNCTION,
curlwrapperWrite) != E_OK: return nil
if easy_setopt(hCurl, OPT_WRITEDATA, result) != E_OK: return nil
if easy_perform(hCurl) != E_OK: return nil
easy_cleanup(hCurl)
proc URLretrieveString*(url: string): TaintedString =
## retrieves the given `url` and returns the contents. Returns nil if an
## error occurs.
var stream = newStringStream()
var hCurl = easy_init()
if hCurl == nil: return
if easy_setopt(hCurl, OPT_URL, url) != E_OK: return
if easy_setopt(hCurl, OPT_WRITEFUNCTION,
curlwrapperWrite) != E_OK: return
if easy_setopt(hCurl, OPT_WRITEDATA, stream) != E_OK: return
if easy_perform(hCurl) != E_OK: return
easy_cleanup(hCurl)
result = stream.data.TaintedString
when isMainModule:
echo URLretrieveString("http://nimrod.ethexor.com/")

View File

@@ -140,11 +140,11 @@ proc executeCgi(client: TSocket, path, query: string, meth: TRequestMethod) =
dealloc(buf)
OSError()
var inp = process.inputStream
inp.writeData(inp, buf, contentLength)
inp.writeData(buf, contentLength)
dealloc(buf)
var outp = process.outputStream
while running(process) or not outp.atEnd(outp):
while running(process) or not atEnd(outp):
var line = outp.readLine()
send(client, line.string)
send(client, wwwNL)

View File

@@ -7,7 +7,7 @@ var
i: int
params = paramCount()
i = 0
writeln(stdout, "This exe: " & getApplicationFilename())
writeln(stdout, "This exe: " & getAppFilename())
writeln(stdout, "Number of parameters: " & $params)
while i <= params:
writeln(stdout, paramStr(i))

View File

@@ -1,5 +1,5 @@
import os
# TODO: Rename this module to ``utils``
type
TStatusEnum* = enum
sUnknown = -1, sBuildFailure, sBuildInProgress, sBuildSuccess,
@@ -51,5 +51,5 @@ proc `$`*(status: TStatusEnum): string =
return "unknown"
proc makeCommitPath*(platform, hash: string): string =
return platform / "nimrod_" & hash.copy(0, 11) # 11 Chars.
return platform / "nimrod_" & hash.substr(0, 11) # 11 Chars.

View File

@@ -1,6 +0,0 @@
var
a {.deprecated.}: array[0..11, int]
a[8] = 1

View File

@@ -1,7 +1,7 @@
#
import times, os
var start = getStartMilsecs()
var start = epochTime()
os.sleep(1000)
echo getStartMilsecs() - start #OUT 1000
echo epochTime() - start #OUT 1000

View File

@@ -52,7 +52,7 @@ var testseq: seq[string] = @[
echo(repr(testseq))
var dummy = "hello"
echo(copy(dummy, 2, 3))
echo(substr(dummy, 2, 3))
echo($meC)

View File

@@ -1,7 +1,7 @@
# Test wether the bindings at least compile...
import
unicode, cgi, terminal, libcurl, web,
unicode, cgi, terminal, libcurl,
parsexml, parseopt, parsecfg,
osproc, complex,
sdl, smpeg, sdl_gfx, sdl_net, sdl_mixer, sdl_ttf,

View File

@@ -3,19 +3,21 @@
import
times
{.warning: "This is only a test warning!".}
#{.warning: "This is only a test warning!".}
const
case2 = true
case3 = true
{.define: case2.}
{.define: case3.}
when defined(case1):
{.hint: "Case 1".}
when defined(case3):
when case3:
{.hint: "Case 1.3".}
elif defined(case2):
elif case2:
{.hint: "Case 2".}
when defined(case3):
when case3:
{.hint: "Case 2.3".}
elif defined(case3):
elif case3:
{.hint: "Case 3".}
else:
{.hint: "unknown case".}

View File

@@ -2,24 +2,24 @@ discard """
file: "tcopy.nim"
output: "TEMP=C:\\Programs\\xyz\\bin"
"""
# tests the copy proc
import
strutils
proc main() =
const
example = r"TEMP=C:\Programs\xyz\bin"
var
a, b: string
p: int
p = find(example, "=")
a = copy(example, 0, p-1)
b = copy(example, p+1)
writeln(stdout, a & '=' & b)
#writeln(stdout, b)
main()
#OUT TEMP=C:\Programs\xyz\bin
# tests the substr proc
import
strutils
proc main() =
const
example = r"TEMP=C:\Programs\xyz\bin"
var
a, b: string
p: int
p = find(example, "=")
a = substr(example, 0, p-1)
b = substr(example, p+1)
writeln(stdout, a & '=' & b)
#writeln(stdout, b)
main()
#OUT TEMP=C:\Programs\xyz\bin

View File

@@ -6,32 +6,32 @@ discard """
import strutils
iterator tokenize2(s: string, seps: set[char] = Whitespace): tuple[
token: string, isSep: bool] =
var i = 0
while i < s.len:
var j = i
if s[j] in seps:
iterator tokenize2(s: string, seps: set[char] = Whitespace): tuple[
token: string, isSep: bool] =
var i = 0
while i < s.len:
var j = i
if s[j] in seps:
while j < s.len and s[j] in seps: inc(j)
if j > i:
yield (copy(s, i, j-1), true)
if j > i:
yield (substr(s, i, j-1), true)
else:
while j < s.len and s[j] notin seps: inc(j)
if j > i:
yield (copy(s, i, j-1), false)
if j > i:
yield (substr(s, i, j-1), false)
i = j
for word, isSep in tokenize2("ta da", whiteSpace):
var titer2TestVar = 0
stdout.write(titer2TestVar)
stdout.write(titer2TestVar)
proc wordWrap2(s: string, maxLineWidth = 80,
splitLongWords = true,
seps: set[char] = whitespace,
newLine = "\n"): string =
result = ""
proc wordWrap2(s: string, maxLineWidth = 80,
splitLongWords = true,
seps: set[char] = whitespace,
newLine = "\n"): string =
result = ""
for word, isSep in tokenize2(s, seps):
var w = 0
var w = 0

View File

@@ -749,7 +749,7 @@ proc rawMatch*(s: string, p: TPeg, start: int, c: var TCaptures): int {.
var (a, b) = c.matches[p.index]
var n: TPeg
n.kind = succ(pkTerminal, ord(p.kind)-ord(pkBackRef))
n.term = s.copy(a, b)
n.term = s.substr(a, b)
result = rawMatch(s, n, start, c)
of pkStartAnchor:
if c.origStart == start: result = 0
@@ -767,7 +767,7 @@ proc match*(s: string, pattern: TPeg, matches: var openarray[string],
result = rawMatch(s, pattern, start, c) == len(s) -start
if result:
for i in 0..c.ml-1:
matches[i] = copy(s, c.matches[i][0], c.matches[i][1])
matches[i] = substr(s, c.matches[i][0], c.matches[i][1])
proc match*(s: string, pattern: TPeg,
start = 0): bool {.rtl, extern: "npegs$1".} =
@@ -787,7 +787,7 @@ proc matchLen*(s: string, pattern: TPeg, matches: var openarray[string],
result = rawMatch(s, pattern, start, c)
if result >= 0:
for i in 0..c.ml-1:
matches[i] = copy(s, c.matches[i][0], c.matches[i][1])
matches[i] = substr(s, c.matches[i][0], c.matches[i][1])
proc matchLen*(s: string, pattern: TPeg,
start = 0): int {.rtl, extern: "npegs$1".} =
@@ -916,7 +916,7 @@ proc replacef*(s: string, sub: TPeg, by: string): string {.
else:
addf(result, by, caps)
inc(i, x)
add(result, copy(s, i))
add(result, substr(s, i))
proc replace*(s: string, sub: TPeg, by = ""): string {.
rtl, extern: "npegs$1".} =
@@ -933,7 +933,7 @@ proc replace*(s: string, sub: TPeg, by = ""): string {.
else:
addf(result, by, caps)
inc(i, x)
add(result, copy(s, i))
add(result, substr(s, i))
proc parallelReplace*(s: string, subs: openArray[
tuple[pattern: TPeg, repl: string]]): string {.
@@ -954,7 +954,7 @@ proc parallelReplace*(s: string, subs: openArray[
add(result, s[i])
inc(i)
# copy the rest:
add(result, copy(s, i))
add(result, substr(s, i))
proc transformFile*(infile, outfile: string,
subs: openArray[tuple[pattern: TPeg, repl: string]]) {.
@@ -1003,7 +1003,7 @@ iterator split*(s: string, sep: TPeg): string =
x = matchLen(s, sep, last)
if x > 0: break
if first < last:
yield copy(s, first, last-1)
yield substr(s, first, last-1)
proc split*(s: string, sep: TPeg): seq[string] {.
rtl, extern: "npegs$1".} =
@@ -1701,7 +1701,7 @@ when isMainModule:
assert rawMatch(s, expr.rule, 0, c) == len(s)
var a = ""
for i in 0..c.ml-1:
a.add(copy(s, c.matches[i][0], c.matches[i][1]))
a.add(substr(s, c.matches[i][0], c.matches[i][1]))
assert a == "abcdef"
#echo expr.rule

View File

@@ -106,17 +106,17 @@ proc TimeConstruction(depth: int) =
iNumIters = NumIters(depth)
echo("Creating " & $iNumIters & " trees of depth " & $depth)
t = getStartMilsecs()
t = epochTime()
for i in 0..iNumIters-1:
new(tempTree)
Populate(depth, tempTree)
tempTree = nil
echo("\tTop down construction took " & $(getStartMilsecs() - t) & "msecs")
t = getStartMilsecs()
echo("\tTop down construction took " & $(epochTime() - t) & "msecs")
t = epochTime()
for i in 0..iNumIters-1:
tempTree = MakeTree(depth)
tempTree = nil
echo("\tBottom up construction took " & $(getStartMilsecs() - t) & "msecs")
echo("\tBottom up construction took " & $(epochTime() - t) & "msecs")
type
tMyArray = seq[float]
@@ -130,7 +130,7 @@ proc main() =
echo("Garbage Collector Test")
echo(" Stretching memory with a binary tree of depth " & $kStretchTreeDepth)
PrintDiagnostics()
t = getStartMilsecs()
t = epochTime()
# Stretch the memory space quickly
tempTree = MakeTree(kStretchTreeDepth)
@@ -160,7 +160,7 @@ proc main() =
# fake reference to LongLivedTree
# and array to keep them from being optimized away
var elapsed = getStartMilsecs() - t
var elapsed = epochTime() - t
PrintDiagnostics()
echo("Completed in " & $elapsed & "ms. Success!")

11
tests/reject/tdeprecated.nim Executable file
View File

@@ -0,0 +1,11 @@
discard """
line: 9
errmsg: "'a' is deprecated [Deprecated]"
"""
var
a {.deprecated.}: array[0..11, int]
a[8] = 1