Permalink
Browse files

Move closure test to separate file

  • Loading branch information...
1 parent 309eb25 commit 60b042a1ceb5de1c48070ea044d79a16a0206c82 @nigredo-tori nigredo-tori committed Aug 5, 2016
Showing with 110 additions and 108 deletions.
  1. +98 −104 tests/alltest.nim
  2. +12 −0 tests/closures.nim
  3. +0 −4 tests/tester.nim
View
@@ -2,109 +2,103 @@
# MIT License - Look at license.txt for details.
import jester, asyncdispatch, strutils, random, os, asyncnet, re
-proc configJester(closureVal: string) =
- settings:
- port = Port(5454)
- appName = "/foo"
- bindAddr = "127.0.0.1"
-
- routes:
- get "/":
- resp "Hello World"
-
- get "/resp":
- if true:
- resp "This should be the response"
- resp "This should NOT be the response"
-
- get "/halt":
- halt Http502, "I'm sorry, this page has been halted."
- resp "test"
-
- get "/halt":
- resp "<h1>Not halted!</h1>"
-
- get "/guess/@who":
- if @"who" != "Frank": pass()
- resp "You've found me!"
-
- get "/guess/@_":
- resp "Haha. You will never find me!"
-
- get "/redirect/@url/?":
- redirect(uri(@"url"))
-
- get "/win":
- cond random(5) < 3
- resp "<b>You won!</b>"
-
- get "/win":
- resp "<b>Try your luck again, loser.</b>"
-
- get "/profile/@id/@value?/?":
- var html = ""
- html.add "<b>Msg: </b>" & @"id" &
- "<br/><b>Name: </b>" & @"value"
- html.add "<br/>"
- html.add "<b>Params: </b>" & $request.params
-
- resp html
-
- get "/attachment":
- attachment "public/root/index.html"
- resp "blah"
-
- get "/error":
- proc blah = raise newException(ESynch, "BLAH BLAH BLAH")
- blah()
-
- get "/live":
- await response.sendHeaders()
- for i in 0 .. 10:
- await response.send("The number is: " & $i & "</br>")
- await sleepAsync(1000)
- response.client.close()
-
- # curl -v -F file='blah' http://dom96.co.cc:5000
- # curl -X POST -d 'test=56' localhost:5000/post
-
- post "/post":
- body.add "Received: <br/>"
- body.add($request.formData)
- body.add "<br/>\n"
- body.add($request.params)
-
- status = Http200
-
- get "/post":
- resp """
- <form name="input" action="$1" method="post">
- First name: <input type="text" name="FirstName" value="Mickey" /><br />
- Last name: <input type="text" name="LastName" value="Mouse" /><br />
- <input type="submit" value="Submit" />
- </form>""" % [uri("/post", absolute = false)]
-
- get "/file":
- resp """
- <form action="/post" method="post"
- enctype="multipart/form-data">
- <label for="file">Filename:</label>
- <input type="file" name="file" id="file" />
- <br />
- <input type="submit" name="submit" value="Submit" />
- </form>"""
-
- get re"^\/([0-9]{2})\.html$":
- resp request.matches[0]
-
- patch "/patch":
- body.add "Received: "
- body.add($request.body)
- status = Http200
-
- get "/closures":
- resp closureVal
-
-configJester("This value is in closure")
+settings:
+ port = Port(5454)
+ appName = "/foo"
+ bindAddr = "127.0.0.1"
+
+routes:
+ get "/":
+ resp "Hello World"
+
+ get "/resp":
+ if true:
+ resp "This should be the response"
+ resp "This should NOT be the response"
+
+ get "/halt":
+ halt Http502, "I'm sorry, this page has been halted."
+ resp "test"
+
+ get "/halt":
+ resp "<h1>Not halted!</h1>"
+
+ get "/guess/@who":
+ if @"who" != "Frank": pass()
+ resp "You've found me!"
+
+ get "/guess/@_":
+ resp "Haha. You will never find me!"
+
+ get "/redirect/@url/?":
+ redirect(uri(@"url"))
+
+ get "/win":
+ cond random(5) < 3
+ resp "<b>You won!</b>"
+
+ get "/win":
+ resp "<b>Try your luck again, loser.</b>"
+
+ get "/profile/@id/@value?/?":
+ var html = ""
+ html.add "<b>Msg: </b>" & @"id" &
+ "<br/><b>Name: </b>" & @"value"
+ html.add "<br/>"
+ html.add "<b>Params: </b>" & $request.params
+
+ resp html
+
+ get "/attachment":
+ attachment "public/root/index.html"
+ resp "blah"
+
+ get "/error":
+ proc blah = raise newException(ESynch, "BLAH BLAH BLAH")
+ blah()
+
+ get "/live":
+ await response.sendHeaders()
+ for i in 0 .. 10:
+ await response.send("The number is: " & $i & "</br>")
+ await sleepAsync(1000)
+ response.client.close()
+
+ # curl -v -F file='blah' http://dom96.co.cc:5000
+ # curl -X POST -d 'test=56' localhost:5000/post
+
+ post "/post":
+ body.add "Received: <br/>"
+ body.add($request.formData)
+ body.add "<br/>\n"
+ body.add($request.params)
+
+ status = Http200
+
+ get "/post":
+ resp """
+ <form name="input" action="$1" method="post">
+ First name: <input type="text" name="FirstName" value="Mickey" /><br />
+ Last name: <input type="text" name="LastName" value="Mouse" /><br />
+ <input type="submit" value="Submit" />
+ </form>""" % [uri("/post", absolute = false)]
+
+ get "/file":
+ resp """
+ <form action="/post" method="post"
+ enctype="multipart/form-data">
+ <label for="file">Filename:</label>
+ <input type="file" name="file" id="file" />
+ <br />
+ <input type="submit" name="submit" value="Submit" />
+ </form>"""
+
+ get re"^\/([0-9]{2})\.html$":
+ resp request.matches[0]
+
+ patch "/patch":
+ body.add "Received: "
+ body.add($request.body)
+ status = Http200
runForever()
View
@@ -0,0 +1,12 @@
+# Issue #63
+
+import jester, asyncdispatch
+
+proc configRoutes(closureVal: string) =
+ routes:
+ get "/":
+ # should respond "This value is in closure"
+ resp closureVal
+
+configRoutes("This value is in closure")
+runForever()
View
@@ -34,7 +34,3 @@ test "regex":
test "resp":
let resp = waitFor client.get("http://localhost:" & $port & "/foo/resp")
check resp.body == "This should be the response"
-
-test "closures":
- let resp = waitFor client.get("http://localhost:" & $port & "/foo/closures")
- check resp.body == "This value is in closure"

0 comments on commit 60b042a

Please sign in to comment.