@ -195,7 +195,7 @@ Predicate for functions that handle @racket[_txexpr-attrs]. Covers values that a
(validate-txexpr
(validate-txexpr
[possible-txexpr any/c])
[possible-txexpr any/c])
txexpr?]
txexpr?]
Like @racket[txexpr?], but raise a descriptive error if @racket[_possible-txexpr] is invalid, and otherwise return @racket[_possible-txexpr] itself.
Like @racket[txexpr?], but raise a descriptive error pinpointing the first problem encountered if @racket[_possible-txexpr] is invalid, and otherwise return @racket[_possible-txexpr] itself.
@examples[#:eval my-eval
@examples[#:eval my-eval
(validate-txexpr 'root)
(validate-txexpr 'root)
@ -204,6 +204,8 @@ Like @racket[txexpr?], but raise a descriptive error if @racket[_possible-txexpr
"validate-txexpr: tag must be a symbol\n tag: \"p\"\n in: '(\"p\"\"foo\"\"bar\")")
;; Invalid element
(check-validate-exn-msg
'(p"foo""bar"((key"value")))
"validate-txexpr: element not a valid element (= txexpr, string, symbol, XML char, or cdata)\n element: '((key \"value\"))\n in: '(p \"foo\"\"bar\" ((key \"value\")))")
;; Malformed attribute list
(check-validate-exn-msg
'(p((key"val")"foo""bar")"hi")
"validate-txexpr: attribute is not a list of the form '(symbol \"string\")\n attribute: \"foo\"\n in: '(p ((key \"val\") \"foo\"\"bar\") \"hi\")")
;; Invalid attribute key
(check-validate-exn-msg
'(root((id"top")(class42)))
"validate-txexpr: attribute value is not a string\n attribute value: 42\n in: '(root ((id \"top\") (class 42)))")
;; Invalid attribute value
(check-validate-exn-msg
'(root((id"top")("class"42)))
"validate-txexpr: attribute key is not a symbol\n attribute key: \"class\"\n in: '(root ((id \"top\") (\"class\" 42)))")
;; Invalid element type
(check-validate-exn-msg
`(root,(void))
"validate-txexpr: element not a valid element (= txexpr, string, symbol, XML char, or cdata)\n element: #<void>\n in: '(root #<void>)")
;; (Deeply nested) No name: error should pinpoint element in 'div txexpr
"validate-txexpr: element not a valid element (= txexpr, string, symbol, XML char, or cdata)\n element: '(\"p\"\"foo\"\"bar\")\n in: '(div (br) (\"p\"\"foo\"\"bar\"))")
;; (Deeply nested) Invalid element: error should pinpoint element in 'p txexpr
"validate-txexpr: element not a valid element (= txexpr, string, symbol, XML char, or cdata)\n element: '((key \"value\"))\n in: '(p \"foo\"\"bar\" ((key \"value\")))")
;; (Deeply nested) Malformed attribute list: error should pinpoint attr in 'p txexpr