diff --git a/console/tests/main.ark b/console/tests/main.ark index f26fffa..6e310e3 100644 --- a/console/tests/main.ark +++ b/console/tests/main.ark @@ -2,21 +2,21 @@ # no tests to do as this is only visual and cosmetics -(console:color "grey") (print "text color: grey") (console:color "reset") -(console:color "red") (print "text color: red") (console:color "reset") -(console:color "green") (print "text color: green") (console:color "reset") -(console:color "yellow") (print "text color: yellow") (console:color "reset") -(console:color "blue") (print "text color: blue") (console:color "reset") -(console:color "magenta") (print "text color: magenta") (console:color "reset") -(console:color "cyan") (print "text color: cyan") (console:color "reset") -(console:color "white") (print "text color: white") (console:color "reset") -(console:color "bright_grey") (print "text color: bright_grey") (console:color "reset") -(console:color "bright_red") (print "text color: bright_red") (console:color "reset") -(console:color "bright_green") (print "text color: bright_green") (console:color "reset") -(console:color "bright_yellow") (print "text color: bright_yellow") (console:color "reset") -(console:color "bright_blue") (print "text color: bright_blue") (console:color "reset") -(console:color "bright_magenta") (print "text color: bright_magenta") (console:color "reset") -(console:color "bright_cyan") (print "text color: bright_cyan") (console:color "reset") -(console:color "bright_white") (print "text color: bright_white") (console:color "reset") +(console:color "grey") (print "text color: grey") +(console:color "red") (print "text color: red") +(console:color "green") (print "text color: green") +(console:color "yellow") (print "text color: yellow") +(console:color "blue") (print "text color: blue") +(console:color "magenta") (print "text color: magenta") +(console:color "cyan") (print "text color: cyan") +(console:color "white") (print "text color: white") +(console:color "on_grey") (print "bg color: grey") +(console:color "on_red") (print "bg color: red") +(console:color "on_green") (print "bg color: green") +(console:color "on_yellow") (print "bg color: yellow") +(console:color "on_blue") (print "bg color: blue") +(console:color "on_magenta") (print "bg color: magenta") +(console:color "on_cyan") (print "bg color: cyan") +(console:color "on_white") (print "bg color: white") (console:color "reset") \ No newline at end of file diff --git a/http/tests/main.ark b/http/tests/main.ark index 579916c..1921e4e 100644 --- a/http/tests/main.ark +++ b/http/tests/main.ark @@ -1,4 +1,35 @@ -# TODO add real tests -(let do_nothing nil) +(import "http.arkm") -(print "HTTP tests done") +(http:server:create) + +(http:server:get "/hi" (fun (matches body params) { + [ + 200 + (if (empty? body) + "hello world" + (+ "hello, " body)) + "text/plain" + ] +})) + +(http:server:get "/numbers/(\\d+)" (fun (matches body params) { + (let number (toNumber (@ matches 0))) + + [200 (toString (+ 12 number)) "text/plain"] +})) + +(http:server:get "/stop" (fun (matches body params) { + (http:server:stop) + [200 "stopped" "text/plain"] +})) + +(let handler (fun (matches body params) { + (let str_params (if (nil? str_params) "nil" (toString (http:params:toList params)))) + [200 (+ (toString matches) "-" body "-" str_params) "text/plain"] +})) + +(http:server:post "/post" handler) +(http:server:put "/put" handler) +(http:server:delete "/delete" handler) + +(http:server:listen "localhost" 8080) diff --git a/http/tests/run b/http/tests/run index 22f346e..2139bbe 100644 --- a/http/tests/run +++ b/http/tests/run @@ -3,5 +3,53 @@ ARKSCRIPT=$1 ARKLIB=$2 -# todo, see #50 -$ARKSCRIPT main.ark --lib $ARKLIB +($ARKSCRIPT main.ark --lib $ARKLIB &) + +echo "GET /hi" +res=$(curl -s -X GET http://localhost:8080/hi) +if [[ $res != "hello world" ]]; then + echo "Got $res" + exit 1 +fi + +echo "GET /hi john" +res=$(curl -s -X GET --data 'john' http://localhost:8080/hi) +if [[ $res != "hello, john" ]]; then + echo "Got $res" + exit 1 +fi + +echo "GET /numbers/4" +res=$(curl -s -X GET http://localhost:8080/numbers/4) +if [[ $res != "16" ]]; then + echo "Got $res" + exit 1 +fi + +echo "POST /post john" +res=$(curl -s -X POST --data 'john' http://localhost:8080/post) +if [[ $res != "nil-john-nil" ]]; then + echo "Got $res" + exit 1 +fi + +echo "PUT /put john" +res=$(curl -s -X PUT --data 'john' http://localhost:8080/put) +if [[ $res != "nil-john-nil" ]]; then + echo "Got $res" + exit 1 +fi + +echo "DELETE /delete john" +res=$(curl -s -X DELETE --data 'john' http://localhost:8080/delete) +if [[ $res != "nil-john-nil" ]]; then + echo "Got $res" + exit 1 +fi + +echo "GET /stop" +res=$(curl -s -X GET http://localhost:8080/stop) +if [[ $res != "stopped" ]]; then + echo "Got $res" + exit 1 +fi \ No newline at end of file