aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/web-util/server.scm
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/web-util/server.scm')
-rw-r--r--tests/unit/web-util/server.scm31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/unit/web-util/server.scm b/tests/unit/web-util/server.scm
new file mode 100644
index 00000000..c81abba3
--- /dev/null
+++ b/tests/unit/web-util/server.scm
@@ -0,0 +1,31 @@
+;;; Commentary:
+;; Tests parse-endpoint-string, used for defining server routes.
+;;; Code:
+
+(define-module (test server)
+ :use-module (srfi srfi-64)
+ :use-module (srfi srfi-71)
+ :use-module (srfi srfi-88)
+ :use-module ((web http make-routes)
+ :select (parse-endpoint-string)))
+
+(test-assert "Check that parsing doesn't crash"
+ (parse-endpoint-string "/static/:dir/:file"))
+
+;; Checks that parsing produces correct results
+(test-group
+ "Simple parameters"
+ (let ((path args (parse-endpoint-string "/static/:dir/:file")))
+ (test-equal "Path" "/static/([^/.]+)/([^/.]+)" path)
+ (test-equal "Parameters" '(dir file) args)))
+
+;; Checks that parsing with custom regex works
+;; along with literal periods.
+(test-group
+ "Custom regex for parameters"
+ (let ((path args (parse-endpoint-string "/static/:filename{.*}.:ext")))
+ (test-equal "Path" "/static/(.*)\\.([^/.]+)" path)
+ (test-equal "Parameters" '(filename ext) args)))
+
+
+'((web http make-routes))