HS: as HTML (NodeList elements via outerHTML) + as Fragment (+4 tests)
hs-coerce HTML list case: use outerHTML for element items, not str. hs-coerce Fragment case: actually build a DocumentFragment — element items are appended directly; strings are parsed via a temp div. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -415,6 +415,52 @@ MANUAL_TEST_BODIES = {
|
||||
' (hs-activate! _el))',
|
||||
' (assert (nil? caught))))',
|
||||
],
|
||||
# asExpression: NodeList as HTML — each element serialised via outerHTML
|
||||
"converts a NodeList into HTML": [
|
||||
' (let ((_frag (host-call (dom-document) "createDocumentFragment")))',
|
||||
' (let ((_d (dom-create-element "div")))',
|
||||
' (do',
|
||||
' (host-set! _d "id" "first")',
|
||||
' (host-set! _d "innerText" "With Text")',
|
||||
' (dom-append _frag _d)',
|
||||
' (let ((_span (dom-create-element "span")))',
|
||||
' (do',
|
||||
' (host-set! _span "id" "second")',
|
||||
' (dom-append _frag _span)',
|
||||
' (let ((_i (dom-create-element "i")))',
|
||||
' (do',
|
||||
' (host-set! _i "id" "third")',
|
||||
' (dom-append _frag _i)',
|
||||
' (let ((_nodeList (host-get _frag "childNodes")))',
|
||||
' (assert=',
|
||||
' (eval-hs-locals "nodeList as HTML" (list (list (quote nodeList) _nodeList)))',
|
||||
' "<div id=\\"first\\">With Text</div><span id=\\"second\\"></span><i id=\\"third\\"></i>")))))))))',
|
||||
],
|
||||
# asExpression: array of [element, html-string] as Fragment
|
||||
"converts arrays into fragments": [
|
||||
' (let ((_p (dom-create-element "p")))',
|
||||
' (let ((_arr (list _p "<p></p>")))',
|
||||
' (let ((_r (eval-hs-locals "value as Fragment" (list (list (quote value) _arr)))))',
|
||||
' (do',
|
||||
' (assert= (len (host-get _r "children")) 2)',
|
||||
' (assert= (host-get (nth (host-get _r "children") 0) "tagName") "P")',
|
||||
' (assert= (host-get (nth (host-get _r "children") 1) "tagName") "P")))))',
|
||||
],
|
||||
# asExpression: single element as Fragment wraps it in a DocumentFragment
|
||||
"converts elements into fragments": [
|
||||
' (let ((_p (dom-create-element "p")))',
|
||||
' (let ((_r (eval-hs-locals "value as Fragment" (list (list (quote value) _p)))))',
|
||||
' (do',
|
||||
' (assert= (len (host-get _r "children")) 1)',
|
||||
' (assert= (host-get (first (host-get _r "children")) "tagName") "P"))))',
|
||||
],
|
||||
# asExpression: HTML string as Fragment — parses and wraps children
|
||||
"converts strings into fragments": [
|
||||
' (let ((_r (eval-hs-locals "value as Fragment" (list (list (quote value) "<p></p>")))))',
|
||||
' (do',
|
||||
' (assert= (len (host-get _r "children")) 1)',
|
||||
' (assert= (host-get (first (host-get _r "children")) "tagName") "P")))',
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user