Wed Feb 10 08:27:56 UTC 2010 pix@kepibu.org
* Serialize returned tags so it's easier to see what was returned
diff -rN -u old-Oh, Ducks!/tests.lisp new-Oh, Ducks!/tests.lisp
--- old-Oh, Ducks!/tests.lisp 2014-01-24 21:54:14.000000000 +0000
+++ new-Oh, Ducks!/tests.lisp 2014-01-24 21:54:14.000000000 +0000
@@ -41,81 +41,115 @@
"
I do not like cheese.
I like cheese.
")
(values i span)))
-(match (#T(html (:model dom)
- ("i" . #t(list ?j ?i))
- ("span>i" . ?span))
- "I do not like cheese.
I like cheese.
")
- (values i span))
-
-(match (#T(html (:model dom)
- ("div:first-child" . ?div)
- ("i:nth-child(1)" . ?i))
- "I do not like cheese.
I like cheese.
")
- (values div i))
-
-(match (#T(html (:model dom)
- ("div:nth-last-child(1)" . ?div)
- ("div:last-child" . ?d2))
- "I do not like cheese.
I like cheese.
")
- (values div d2))
-
-(match (#t(html (:model dom)
- (":nth-last-of-type(2)" . ?first)
- (":nth-of-type(2)" . ?last))
- "1i2i
")
- (values first last))
+(defun make-dom-document (child-node)
+ (make-instance 'rune-dom::document :children (rune-dom::make-node-list (list child-node))))
-(match (#T(html (:model dom)
- ("i:only-child" . ?i)
- ("i:only-of-type" . ?i-type))
- "I do not like cheese.
I like cheese.
")
- (values i i-type))
+(defun serialize (object)
+ (let ((document
+ (etypecase object
+ (rune-dom::document object)
+ (rune-dom::element (make-dom-document object))
+ (chtml:pt object)
+ (list object))))
+ (etypecase document
+ (rune-dom::document
+ (dom:map-document (cxml:make-string-sink :omit-xml-declaration-p t)
+ document))
+ (chtml:pt
+ (chtml:serialize-pt document (chtml:make-string-sink)))
+ (list (mapcar #'serialize document)))))
+
+(defmacro serialize-values (form)
+ `(let ((values (multiple-value-list ,form)))
+ (values-list (mapcar #'serialize values))))
+
+(equal '("cheese" "cheese")
+ (serialize-values
+ (match (#T(html (:model dom)
+ ("i" . #t(list ?j ?i))
+ ("span>i" . ?span))
+ "I do not like cheese.
I like cheese.
")
+ (values i span))))
+
+(serialize-values
+ (match (#T(html (:model dom)
+ ("div:first-child" . ?div)
+ ("i:nth-child(1)" . ?i))
+ "I do not like cheese.
I like cheese.
")
+ (values div i)))
+
+(serialize-values
+ (match (#T(html (:model dom)
+ ("div:nth-last-child(1)" . ?div)
+ ("div:last-child" . ?d2))
+ "I do not like cheese.
I like cheese.
")
+ (values div d2)))
+
+(serialize-values
+ (match (#t(html (:model dom)
+ (":nth-last-of-type(2)" . ?first)
+ (":nth-of-type(2)" . ?last))
+ "1i2i
")
+ (values first last)))
-;; throws 'unification-failure
(match (#T(html (:model dom)
("q" . ?div))
- "I do not like cheese.
I like cheese.
")
+ "I do not like cheese.
I like cheese.
")
(values div))
-(match (#T(html (:model dom)
- ("b + i" . ?i))
- "I really like cheese. Do you not dislike cheese?
")
- (values i))
-
-(match (#T(html (:model dom)
- ("b ~ i" . ?i))
- "I really like cheese. Do you not dislike cheese?
")
- (values i))
-
-(match (#T(html (:model pt)
- ("body :empty" . ?empty))
- "")
- (values empty))
+;; throws 'unification-failure
+(serialize-values
+ (match (#T(html (:model dom)
+ ("i:only-child" . ?i)
+ ("i:only-of-type" . ?i-type))
+ "I do not like cheese.
I like cheese.
")
+ (values i i-type)))
+
+(serialize-values
+ (match (#T(html (:model dom)
+ ("b + i" . ?i))
+ "I really like cheese. Do you not dislike cheese?
")
+ (values i)))
+
+(serialize-values
+ (match (#T(html (:model dom)
+ ("b ~ i" . ?i))
+ "I really like cheese. Do you not dislike cheese?
")
+ (values i)))
+
+(serialize-values
+ (match (#T(html (:model pt)
+ ("body :empty" . ?empty))
+ "")
+ (values empty)))
;; Sometimes, you want to match a thing inside a thing, in which case
;; combinators should implicitly assume an unspecified right side means
;; "whatever element I gave you".
-(match (#T(html (:model dom)
- ("q" . ?q))
- "ham foo bar baz
quuz spam
")
- (match (#t(html ("> i" . ?i))
- (first q))
- i))
+(serialize-values
+ (match (#T(html (:model dom)
+ ("q" . ?q))
+ "ham foo bar baz
quuz spam
")
+ (match (#t(html ("> i" . ?i))
+ (first q))
+ i)))
;; siblings will also match, thanks to a bit of ugly code
-(match (#T(html (:model dom)
- ("q" . ?q))
- "ham foo bar baz
quuz spamnot match
")
- (match (#t(html ("+ i" . ?i))
- (first q))
- i))
-
-(match (#T(html (:model dom)
- ("q" . ?q))
- " foo outer q baz inner q
quuz
")
- (match (#t(html ("q" . ?i))
- (first q))
- i))
+(serialize-values
+ (match (#T(html (:model dom)
+ ("q" . ?q))
+ "ham foo bar baz
quuz spamnot match
")
+ (match (#t(html ("+ i" . ?i))
+ (first q))
+ i)))
+
+(serialize-values
+ (match (#T(html (:model dom)
+ ("q" . ?q))
+ " foo outer q baz inner q
quuz
")
+ (match (#t(html ("q" . ?i))
+ (first q))
+ i)))
#+LATER?