(load-relative "../sxml-informal.scm") (import sxml-informal) (use sxml-transforms test) (define (test-form result form #!optional description) (test description result (pre-post-order form informal-rules))) (define (test-field result form) (test-form (cons 'li result) form (symbol->string (car form)))) (test-form '(form (@ (action "/foo") (method "POST")) ((fieldset (legend "Paste") (ol (li (label (@ (for "title")) "A Title") (input (@ (type "text") (id "title") (name "title") (value #f)))) (li (label (@ (for "name")) "Your Name") (input (@ (type "text") (id "name") (name "name") (value #f)))))))) '(informal (@ (action "/foo") (method "POST")) (fields "Paste" (string "title" label: "A Title") (string "name" label: "Your Name")))) ;; form field rules (test-field '((input (@ (type "text") (id "foo") (name "foo") (value "bar")))) '(string "foo" value: "bar")) (test-field '((input (@ (type "password") (id "foo") (name "foo") (value "bar")))) '(password "foo" value: "bar")) (test-field '((input (@ (checked "checked") (type "checkbox") (id "foo") (name "foo") (value "bar")))) '(checkbox "foo" value: "bar" checked: #t)) (test-field '((input (@ (checked "checked") (type "radio") (id "foo") (name "foo") (value "bar")))) '(radio "foo" value: "bar" checked: #t)) (test-field '((textarea (@ (id "foo") (name "foo")) "bar")) '(text "foo" value: "bar")) (test-field '((select (@ (id "foo") (name "foo")) (option (@ (value 10)) "bar") (option (@ (value 20)) "baz") (option (@ (selected "selected") (value 30)) "qux"))) '(select "foo" value: 30 options: ((10 "bar") (20 "baz") (30 "qux")))) (test-field '((input (@ (type "submit") (id "commit") (name "commit") (value "submit!")))) '(submit "submit!")) ;; special case: hidden fields aren't wrapped in an li element (test-form '(input (@ (type "hidden") (id "foo") (name "foo") (value "bar"))) '(hidden "foo" "bar") "hidden") (test-form '(form (@ (foo "bar")) (ol (li (label (@ (for "foo-bar")) "foo!") (input (@ (type "text") (id "foo-bar") (name "foo-bar") (value "baz")))))) '(informal ((prefix "foo-") (@ (foo "bar"))) (ol (string "bar" value: "baz" label: "foo!"))))