Skip to content
Snippets Groups Projects
Commit dcbe67f5 authored by João Távora's avatar João Távora
Browse files

Adapt tests to new default arg-reading rules

* snooze-tests.lisp (#:snooze-parse-uri-tests): Don't use this package.
(test-parse-uri, path-generation, path-parse-back): Adapt to new
default argument-reading rules.
parent 05ecc8df
No related branches found
No related tags found
No related merge requests found
......@@ -30,11 +30,6 @@
(signals error (cts '"text/html-typo"))))
(cl:defpackage #:snooze-parse-uri-tests
(:use :snooze :cl)
(:export #:bla #:root #:yo))
(in-package :snooze-parse-uri-tests)
(defresource bla (a b c &key &allow-other-keys))
(defroute bla (a b c &key foo snooze:fragment &allow-other-keys)
......@@ -46,8 +41,6 @@
(defresource yo.snooze (verb content-type))
(in-package :snooze-tests)
(defun parse-uri-for-tests (uri)
(multiple-value-bind (resource content-types moreuri)
(parse-resource uri)
......@@ -61,71 +54,68 @@
(deftest test-parse-uri ()
(multiple-value-bind (resource pargs kwargs)
(parse-uri-for-tests "/bla/ble/bli?foo=fonix;bar=fotrix#coisoetal")
(is (equal pargs '(:ble :bli)))
(is (equal kwargs '((:FOO . :fonix)
(:BAR . :fotrix)
(SNOOZE:FRAGMENT . :coisoetal))))
(is (eq resource #'snooze-parse-uri-tests:bla)))
(declare (ignore pargs kwargs))
(is (eq resource #'bla)))
(multiple-value-bind (resource pargs kwargs)
(let ((snooze:*resource-name-function*
(lambda (uri)
(default-resource-name (subseq uri (mismatch "/ignored" uri))))))
(parse-uri-for-tests "/ignored/bla/ble/bli?foo=fonix;bar=fotrix#coisoetal"))
(is (equal pargs '(:ble :bli)))
(is (equal kwargs '((:FOO . :fonix)
(:BAR . :fotrix)
(SNOOZE:FRAGMENT . :coisoetal))))
(is (eq resource #'snooze-parse-uri-tests:bla)))
(is (equal pargs '(ble bli)))
(is (equal kwargs '((:FOO . fonix)
(:BAR . fotrix)
(SNOOZE:FRAGMENT . coisoetal))))
(is (eq resource #'bla)))
(multiple-value-bind (resource pargs)
(parse-uri-for-tests "/bla/ble/bli")
(is (equal pargs '(:ble :bli)))
(is (eq resource #'snooze-parse-uri-tests:bla)))
(is (equal pargs '(ble bli)))
(is (eq resource #'bla)))
;; content-types in the extension
;;
(multiple-value-bind (resource pargs kwargs content-types)
(parse-uri-for-tests "/yo?foo=ok")
(declare (ignore pargs))
(is (equal kwargs '((:foo . :ok))))
(is (eq resource #'snooze-parse-uri-tests:yo))
(is (equal kwargs '((:foo . ok))))
(is (eq resource #'yo))
(is (null content-types)))
(multiple-value-bind (resource pargs kwargs content-types)
(parse-uri-for-tests "/yo.css?foo=ok")
(is (null pargs))
(is (equal kwargs '((:foo . :ok))))
(is (eq resource #'snooze-parse-uri-tests:yo))
(is (equal kwargs '((:foo . ok))))
(is (eq resource #'yo))
(is (member (find-class 'snooze-types:text/css) content-types)))
(multiple-value-bind (resource pargs kwargs content-types)
(parse-uri-for-tests "/yo/1.css?foo=ok")
(is (equal pargs '(1)))
(is (equal kwargs '((:foo . :ok))))
(is (eq resource #'snooze-parse-uri-tests:yo))
(is (equal kwargs '((:foo . ok))))
(is (eq resource #'yo))
(member (find-class 'snooze-types:text/css) content-types))
(multiple-value-bind (resource pargs kwargs content-types)
(let ((snooze:*uri-content-types-function* nil))
(parse-uri-for-tests "/yo/1.css?foo=ok"))
(is (equal pargs '(:1.css)))
(is (equal kwargs '((:foo . :ok))))
(is (eq resource #'snooze-parse-uri-tests:yo))
(is (equal pargs '(1.css)))
(is (equal kwargs '((:foo . ok))))
(is (eq resource #'yo))
(member (find-class 'snooze-types:text/css) content-types))
(multiple-value-bind (resource pargs kwargs content-types)
(parse-uri-for-tests "/yo.snooze?foo=ok")
(is (null pargs))
(is (equal kwargs '((:foo . :ok))))
(is (eq resource #'snooze-parse-uri-tests::yo.snooze))
(is (equal kwargs '((:foo . ok))))
(is (eq resource #'yo.snooze))
(is (null content-types)))
(multiple-value-bind (resource pargs kwargs content-type)
(parse-uri-for-tests "/yo/arg.unknownextension?foo=ok")
(is (equal pargs '(:arg.unknownextension)))
(is (equal kwargs '((:foo . :ok))))
(is (eq resource #'snooze-parse-uri-tests:yo))
(is (equal pargs '(arg.unknownextension)))
(is (equal kwargs '((:foo . ok))))
(is (eq resource #'yo))
(is (not content-type))))
......@@ -263,47 +253,47 @@
;;; Genpath section
;;;
(defresource book-resource (verb content-type file user &optional
(coiso :genpath-default-coiso)
(tal :genpath-default-tal)
&key fornix (yo :genpath-default-yobla))
(coiso 'genpath-default-coiso)
(tal 'genpath-default-tal)
&key fornix (yo 'genpath-default-yobla))
(:genpath book-resource-path)
(:route (:get "text/plain" file user &optional (coiso :default-coiso) (tal :default-tal) &key fornix (yo :yobla))
(:route (:get "text/plain" file user &optional (coiso 'default-coiso) (tal 'default-tal) &key fornix (yo 'yobla))
(write-to-string (list file user coiso tal fornix yo))))
(defresource manuscript-resource (verb content-type file user &key)
(:genpath manuscript-resource-path)
(:route (:get "text/plain" file user &key fornix (yo :default-yo))
(:route (:get "text/plain" file user &key fornix (yo 'default-yo))
(write-to-string (list file user fornix yo))))
(deftest path-generation ()
(is (string= (book-resource-path :yo :yeah nil nil)
(is (string= (book-resource-path 'yo 'yeah nil nil)
"/book-resource/yo/yeah?yo=genpath-default-yobla"))
(signals error (book-resource-path "yo" "yeah" nil "AHA"))
(is (string= (book-resource-path :yo :yeah "MixedCase" nil)
(is (string= (book-resource-path 'yo 'yeah "MixedCase" nil)
"/book-resource/yo/yeah/%22MixedCase%22?yo=genpath-default-yobla"))
(is (string= (book-resource-path :yo :yeah "OK" nil :yo :mama :fornix nil)
(is (string= (book-resource-path 'yo 'yeah "OK" nil :yo 'mama :fornix nil)
"/book-resource/yo/yeah/%22OK%22?yo=mama"))
(is (string= (book-resource-path :yo :yeah)
(is (string= (book-resource-path 'yo 'yeah)
"/book-resource/yo/yeah/genpath-default-coiso/genpath-default-tal?yo=genpath-default-yobla"))
(is (string= (book-resource-path "yo with a space" :yeah)
(is (string= (book-resource-path "yo with a space" 'yeah)
"/book-resource/%22yo%20with%20a%20space%22/yeah/genpath-default-coiso/genpath-default-tal?yo=genpath-default-yobla")))
(defresource joaot (verb ct one two three &key quatro)
(:genpath joaot-path))
(deftest path-parse-back ()
(with-request ((book-resource-path :yo :yeah)) (code payload)
(with-request ((book-resource-path 'yo 'yeah)) (code payload)
(is (= 200 code))
(is (equal (read-from-string payload)
'(:yo :yeah :genpath-default-coiso :genpath-default-tal nil :genpath-default-yobla))))
(with-request ((manuscript-resource-path :yo :yeah)) (code payload)
'(yo yeah genpath-default-coiso genpath-default-tal nil genpath-default-yobla))))
(with-request ((manuscript-resource-path 'yo 'yeah)) (code payload)
(is (= 200 code))
(is (equal (read-from-string payload)
'(:yo :yeah nil :default-yo))))
(with-request ((manuscript-resource-path :yo 'read-char)) (code payload)
'(yo yeah nil default-yo))))
(with-request ((manuscript-resource-path 'yo 'read-char)) (code payload)
(is (= 200 code))
(is (equal (read-from-string payload)
'(:yo cl:read-char nil :default-yo))))
'(yo cl:read-char nil default-yo))))
(let ((uri "/joaot/1/2/3?quatro=4"))
(is (string= (multiple-value-bind (resource content-types relative-uri)
(parse-resource uri)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment