diff options
author | Araq <rumpf_a@web.de> | 2011-11-19 12:23:03 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2011-11-19 12:23:03 +0100 |
commit | d0772feb08baaea12bfdad0a7c20a41733f977bd (patch) | |
tree | 706734d78ba5463e12614a5cad5dd3981b33f49f | |
parent | 62aa8bed3b6472e8acae530f7014e7e5b0c755b5 (diff) | |
download | Nim-d0772feb08baaea12bfdad0a7c20a41733f977bd.tar.gz |
fixed some tests
-rwxr-xr-x | examples/httpserver2.nim | 6 | ||||
-rwxr-xr-x | lib/impure/web.nim | 106 | ||||
-rwxr-xr-x | lib/pure/httpserver.nim | 4 | ||||
-rwxr-xr-x | tests/accept/compile/tcmdline.nim | 2 | ||||
-rwxr-xr-x | tests/accept/compile/tcodegenbug1.nim | 4 | ||||
-rwxr-xr-x | tests/accept/compile/tdeprecated.nim | 6 | ||||
-rwxr-xr-x | tests/accept/compile/tgetstartmilsecs.nim | 4 | ||||
-rwxr-xr-x | tests/accept/compile/thallo.nim | 2 | ||||
-rwxr-xr-x | tests/accept/compile/tlibs.nim | 2 | ||||
-rwxr-xr-x | tests/accept/compile/tprep.nim | 16 | ||||
-rwxr-xr-x | tests/accept/run/tcopy.nim | 38 | ||||
-rwxr-xr-x | tests/accept/run/titer6.nim | 34 | ||||
-rwxr-xr-x | tests/accept/run/tpegs.nim | 16 | ||||
-rwxr-xr-x | tests/gc/gcbench.nim | 12 | ||||
-rwxr-xr-x | tests/reject/tdeprecated.nim | 11 |
15 files changed, 135 insertions, 128 deletions
diff --git a/examples/httpserver2.nim b/examples/httpserver2.nim index 0604e6a83..56bd630ad 100755 --- a/examples/httpserver2.nim +++ b/examples/httpserver2.nim @@ -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 diff --git a/lib/impure/web.nim b/lib/impure/web.nim index f4009ba80..19372f466 100755 --- a/lib/impure/web.nim +++ b/lib/impure/web.nim @@ -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/") + diff --git a/lib/pure/httpserver.nim b/lib/pure/httpserver.nim index 8e95db024..b47af97fa 100755 --- a/lib/pure/httpserver.nim +++ b/lib/pure/httpserver.nim @@ -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) diff --git a/tests/accept/compile/tcmdline.nim b/tests/accept/compile/tcmdline.nim index f43aecafa..f4ee20d31 100755 --- a/tests/accept/compile/tcmdline.nim +++ b/tests/accept/compile/tcmdline.nim @@ -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)) diff --git a/tests/accept/compile/tcodegenbug1.nim b/tests/accept/compile/tcodegenbug1.nim index 4ceaf6ebf..909101db1 100755 --- a/tests/accept/compile/tcodegenbug1.nim +++ b/tests/accept/compile/tcodegenbug1.nim @@ -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. diff --git a/tests/accept/compile/tdeprecated.nim b/tests/accept/compile/tdeprecated.nim deleted file mode 100755 index e287da3f9..000000000 --- a/tests/accept/compile/tdeprecated.nim +++ /dev/null @@ -1,6 +0,0 @@ -var - a {.deprecated.}: array[0..11, int] - -a[8] = 1 - - diff --git a/tests/accept/compile/tgetstartmilsecs.nim b/tests/accept/compile/tgetstartmilsecs.nim index 340c78af1..5a3368e0f 100755 --- a/tests/accept/compile/tgetstartmilsecs.nim +++ b/tests/accept/compile/tgetstartmilsecs.nim @@ -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 diff --git a/tests/accept/compile/thallo.nim b/tests/accept/compile/thallo.nim index 8cbe10bd5..ff90c5c0a 100755 --- a/tests/accept/compile/thallo.nim +++ b/tests/accept/compile/thallo.nim @@ -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) diff --git a/tests/accept/compile/tlibs.nim b/tests/accept/compile/tlibs.nim index d4080eafd..5dd70b0e8 100755 --- a/tests/accept/compile/tlibs.nim +++ b/tests/accept/compile/tlibs.nim @@ -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, diff --git a/tests/accept/compile/tprep.nim b/tests/accept/compile/tprep.nim index 999b2f57f..4ef9e2543 100755 --- a/tests/accept/compile/tprep.nim +++ b/tests/accept/compile/tprep.nim @@ -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".} diff --git a/tests/accept/run/tcopy.nim b/tests/accept/run/tcopy.nim index 3c7ccae4b..5feb0d6b3 100755 --- a/tests/accept/run/tcopy.nim +++ b/tests/accept/run/tcopy.nim @@ -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 diff --git a/tests/accept/run/titer6.nim b/tests/accept/run/titer6.nim index fa58e9a6c..dceace0e0 100755 --- a/tests/accept/run/titer6.nim +++ b/tests/accept/run/titer6.nim @@ -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 diff --git a/tests/accept/run/tpegs.nim b/tests/accept/run/tpegs.nim index c3ca7c9ab..64c547b24 100755 --- a/tests/accept/run/tpegs.nim +++ b/tests/accept/run/tpegs.nim @@ -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 diff --git a/tests/gc/gcbench.nim b/tests/gc/gcbench.nim index f10e5d57d..66164a9e9 100755 --- a/tests/gc/gcbench.nim +++ b/tests/gc/gcbench.nim @@ -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!") diff --git a/tests/reject/tdeprecated.nim b/tests/reject/tdeprecated.nim new file mode 100755 index 000000000..372fe155e --- /dev/null +++ b/tests/reject/tdeprecated.nim @@ -0,0 +1,11 @@ +discard """ + line: 9 + errmsg: "'a' is deprecated [Deprecated]" +""" + +var + a {.deprecated.}: array[0..11, int] + +a[8] = 1 + + |