Add attribute-equal selector
Annotate for file /tests.lisp
2009-11-18 pix 1 (in-package #:oh-ducks)
2010-02-10 pix 2 (named-readtables:in-readtable template-readtable)
2009-11-16 pix 3 ;; FIXME: the switch to chtml:pt nodes means our #'equalp no longer
08:14:42 ' 4 ;; works.
2009-11-13 pix 5
2009-11-18 pix 6 #+(or) (setq *default-parser* 'pt)
10:23:05 ' 7
2009-11-13 pix 8 (equalp '(:div ((:id "id")) "I " (:i () "like") " cheese.")
2009-11-21 pix 9 (match (#T(html (:model lhtml) ("#id" . ?div))
2010-02-10 pix 10 "<div id=\"id\">I <i>like</i> cheese.</div>")
2009-11-13 pix 11 ;; FIXME: learn to distinguish between when there should only be one
01:43:02 ' 12 ;; result and when there should be many?
' 13 (car div)))
' 14
' 15 (equalp '((:div ((:class "red fish")) "one fish")
' 16 (:div ((:class "blue fish")) "two fish"))
2009-11-21 pix 17 (match (#T(html (:model lhtml)
16:12:13 ' 18 (".fish" . ?divs)
2009-11-16 pix 19 (".pig" . ?pig))
2009-11-13 pix 20 "<div class='pig'>bricklayer</div><div class='red fish'>one fish</div><div class='blue fish'>two fish</div>")
01:43:02 ' 21 ;; pig doesn't affect the equalp...but does show separate things are separate
' 22 (values divs pig)))
' 23
' 24 (equalp '((:i () "not") (:i () "cheese"))
2010-01-04 pix 25 (match (#T(html (:model lhtml)
07:11:36 ' 26 ("div" ("i" . ?i)))
' 27 "<div>I do <i>not</i> like cheese.</div><div>I like <i>cheese</i>.</div>")
2009-11-13 pix 28 i))
01:43:02 ' 29
' 30 (equalp '((:i () "not"))
2010-01-04 pix 31 (match (#T(html (:model lhtml)
2009-11-21 pix 32 ("div>i" . ?i))
2010-01-04 pix 33 "<div>I do <i>not</i> like cheese.</div><div><span>I like <i>cheese</i>.</span></div>")
2009-11-13 pix 34 i))
01:43:02 ' 35
' 36 (equalp '((:i () "not"))
2010-01-04 pix 37 (match (#T(html (:model lhtml)
2009-11-21 pix 38 ("div" (">i" . ?i)
18:31:09 ' 39 ;("i" . #t(list ?j ?i))
' 40 ("span>i" . ?span)))
2010-01-04 pix 41 "<div>I do <i>not</i> like cheese.</div><div><span>I like <i>cheese</i>.</span></div>")
2009-11-16 pix 42 (values i span)))
2010-02-10 pix 43 (defun make-dom-document (child-node)
08:27:56 ' 44 (make-instance 'rune-dom::document :children (rune-dom::make-node-list (list child-node))))
2009-11-21 pix 45
2010-02-10 pix 46 (defun serialize (object)
08:27:56 ' 47 (let ((document
' 48 (etypecase object
' 49 (rune-dom::document object)
' 50 (rune-dom::element (make-dom-document object))
' 51 (chtml:pt object)
' 52 (list object))))
' 53 (etypecase document
' 54 (rune-dom::document
' 55 (dom:map-document (cxml:make-string-sink :omit-xml-declaration-p t)
' 56 document))
' 57 (chtml:pt
' 58 (chtml:serialize-pt document (chtml:make-string-sink)))
' 59 (list (mapcar #'serialize document)))))
2009-11-23 pix 60
2010-02-10 pix 61 (defmacro serialize-values (form)
08:27:56 ' 62 `(let ((values (multiple-value-list ,form)))
' 63 (values-list (mapcar #'serialize values))))
2010-01-04 pix 64
2010-02-10 pix 65 (equal '("<i>cheese</i>" "<i>cheese</i>")
08:27:56 ' 66 (serialize-values
' 67 (match (#T(html (:model dom)
' 68 ("i" . #t(list ?j ?i))
' 69 ("span>i" . ?span))
' 70 "<div>I do <i>not</i> like cheese.</div><div><span>I like <i>cheese</i>.</span></div>")
' 71 (values i span))))
2010-01-04 pix 72
2010-02-10 pix 73 (serialize-values
08:27:56 ' 74 (match (#T(html (:model dom)
' 75 ("div:first-child" . ?div)
' 76 ("i:nth-child(1)" . ?i))
' 77 "<div>I do <i>not</i> <i>like</i> cheese.</div><div><span>I like <i>cheese</i>.</span></div>")
' 78 (values div i)))
' 79
' 80 (serialize-values
' 81 (match (#T(html (:model dom)
' 82 ("div:nth-last-child(1)" . ?div)
' 83 ("div:last-child" . ?d2))
' 84 "<div>I do <i>not</i> <i>like</i> cheese.</div><div><span>I like <i>cheese</i>.</span></div>")
' 85 (values div d2)))
' 86
' 87 (serialize-values
' 88 (match (#t(html (:model dom)
' 89 (":nth-last-of-type(2)" . ?first)
' 90 (":nth-of-type(2)" . ?last))
' 91 "<div><span>1</span><i>i</i><span>2</span><i>i</i></div>")
' 92 (values first last)))
2010-01-04 pix 93
2009-11-23 pix 94 (match (#T(html (:model dom)
13:14:45 ' 95 ("q" . ?div))
2010-02-10 pix 96 "<div>I do <i>not</i> <i>like</i> cheese.</div><div><span>I like <i>cheese</i>.</span></div>")
2009-11-23 pix 97 (values div))
13:14:45 ' 98
2010-02-10 pix 99 ;; throws 'unification-failure
08:27:56 ' 100 (serialize-values
' 101 (match (#T(html (:model dom)
' 102 ("i:only-child" . ?i)
' 103 ("i:only-of-type" . ?i-type))
' 104 "<div>I do <i>not</i> <i>like</i> cheese.</div><div><span><i>I</i> like <i>cheese</i>.</span></div>")
' 105 (values i i-type)))
2009-12-03 pix 106
2010-02-10 pix 107 (serialize-values
08:27:56 ' 108 (match (#T(html (:model dom)
' 109 ("b + i" . ?i))
' 110 "<div>I <b>really</b> <i>like</i> cheese. Do you not <i>dislike</i> cheese?</div>")
' 111 (values i)))
' 112
' 113 (serialize-values
' 114 (match (#T(html (:model dom)
' 115 ("b ~ i" . ?i))
' 116 "<div>I <i>really</i> <b>like</b> cheese. Do you <i>not</i> <i>dislike</i> cheese?</div>")
' 117 (values i)))
2009-12-03 pix 118
2010-02-10 pix 119 (serialize-values
08:27:56 ' 120 (match (#T(html (:model pt)
' 121 ("body :empty" . ?empty))
' 122 "<div><p><br></p><p>testing<i>i</i>testing</p></div>")
' 123 (values empty)))
2010-01-04 pix 124
2009-12-04 pix 125 ;; Sometimes, you want to match a thing inside a thing, in which case
04:47:58 ' 126 ;; combinators should implicitly assume an unspecified right side means
' 127 ;; "whatever element I gave you".
2010-02-10 pix 128 (serialize-values
08:27:56 ' 129 (match (#T(html (:model dom)
' 130 ("q" . ?q))
' 131 "<div><i>ham</i> foo <q>bar <i>baz</i></q> quuz <i>spam</i></div>")
' 132 (match (#t(html ("> i" . ?i))
' 133 (first q))
' 134 i)))
2009-12-04 pix 135
2009-12-05 pix 136 ;; siblings will also match, thanks to a bit of ugly code
2010-02-10 pix 137 (serialize-values
08:27:56 ' 138 (match (#T(html (:model dom)
' 139 ("q" . ?q))
' 140 "<div><i>ham</i> foo <q>bar <i>baz</i></q> quuz <i>spam</i><q></q><i>not match</i></div>")
' 141 (match (#t(html ("+ i" . ?i))
' 142 (first q))
' 143 i)))
2009-12-04 pix 144
2010-02-10 pix 145 (serialize-values
08:27:56 ' 146 (match (#T(html (:model dom)
' 147 ("q" . ?q))
' 148 "<div> foo <q>outer q <i>baz <q>inner q</q></i></q> quuz</div>")
' 149 (match (#t(html ("q" . ?i))
' 150 (first q))
' 151 i)))
2009-12-05 pix 152
2010-02-10 pix 153 (serialize-values
08:28:34 ' 154 (match (#T(html (:model dom)
' 155 ("[id]" . ?ids))
' 156 "<div><i id=''>blank id</i>foo<b>no id</b>bar<i id='id'>id id</i></div>")
' 157 ids))
2009-12-03 pix 158
2010-02-10 pix 159 (serialize-values
08:50:16 ' 160 (match (#T(html (:model dom)
' 161 ("[id=foo]" . ?id))
' 162 "<div><i id='bar'>bar id</i><i>no id</i><i id='foo'>foo id</i></div>")
' 163 id))
' 164
2009-11-23 pix 165 #+LATER?
2009-11-21 pix 166 (match (#t(html ("div::content" . #t(regexp+ "^f(o+)" (?o))))
2009-11-13 pix 167 "<div>barbaz</div><div>fooooooobar</div>")
08:32:55 ' 168 (values o &rest))
' 169