content: render boundary (asHTML/asSx polymorphic) + 29 tests
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 48s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 48s
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
73
lib/content/tests/render.sx
Normal file
73
lib/content/tests/render.sx
Normal file
@@ -0,0 +1,73 @@
|
||||
;; Phase 1 — render boundary. asHTML / asSx are polymorphic message sends on
|
||||
;; blocks and the document.
|
||||
|
||||
(st-bootstrap-classes!)
|
||||
(content-bootstrap-blocks!)
|
||||
(content-bootstrap-doc!)
|
||||
(content-bootstrap-render!)
|
||||
|
||||
(define h (mk-heading "h" 2 "Title"))
|
||||
(define p (mk-text "p" "Hello"))
|
||||
(define code (mk-code "c" "sx" "(+ 1 2)"))
|
||||
(define q (mk-quote "q" "Ada" "to err"))
|
||||
(define img (mk-image "i" "/c.png" "cat"))
|
||||
(define em (mk-embed "e" "https://v/1" "vimeo"))
|
||||
(define dv (mk-divider "d"))
|
||||
(define ul (mk-list "u" false (list "a" "b")))
|
||||
(define ol (mk-list "o" true (list "x" "y")))
|
||||
|
||||
;; ── per-block asHTML ──
|
||||
(content-test "heading html" (asHTML h) "<h2>Title</h2>")
|
||||
(content-test "text html" (asHTML p) "<p>Hello</p>")
|
||||
(content-test
|
||||
"code html"
|
||||
(asHTML code)
|
||||
"<pre><code class=\"language-sx\">(+ 1 2)</code></pre>")
|
||||
(content-test "quote html" (asHTML q) "<blockquote>to err</blockquote>")
|
||||
(content-test "image html" (asHTML img) "<img src=\"/c.png\" alt=\"cat\">")
|
||||
(content-test "embed html" (asHTML em) "<iframe src=\"https://v/1\"></iframe>")
|
||||
(content-test "divider html" (asHTML dv) "<hr>")
|
||||
(content-test "ul html" (asHTML ul) "<ul><li>a</li><li>b</li></ul>")
|
||||
(content-test "ol html" (asHTML ol) "<ol><li>x</li><li>y</li></ol>")
|
||||
|
||||
;; ── per-block asSx ──
|
||||
(content-test "heading sx" (asSx h) "(h2 \"Title\")")
|
||||
(content-test "text sx" (asSx p) "(p \"Hello\")")
|
||||
(content-test "code sx" (asSx code) "(pre (code \"(+ 1 2)\"))")
|
||||
(content-test "quote sx" (asSx q) "(blockquote \"to err\")")
|
||||
(content-test "image sx" (asSx img) "(img :src \"/c.png\" :alt \"cat\")")
|
||||
(content-test "embed sx" (asSx em) "(iframe :src \"https://v/1\")")
|
||||
(content-test "divider sx" (asSx dv) "(hr)")
|
||||
(content-test "ul sx" (asSx ul) "(ul (li \"a\")(li \"b\"))")
|
||||
(content-test "ol sx" (asSx ol) "(ol (li \"x\")(li \"y\"))")
|
||||
|
||||
;; ── document folds children (pure message dispatch) ──
|
||||
(define d (doc-append (doc-append (doc-append (doc-empty "doc") h) p) dv))
|
||||
(content-test "doc html" (asHTML d) "<h2>Title</h2><p>Hello</p><hr>")
|
||||
(content-test "doc sx" (asSx d) "(article (h2 \"Title\")(p \"Hello\")(hr))")
|
||||
(content-test "empty doc html" (asHTML (doc-empty "e")) "")
|
||||
(content-test "empty doc sx" (asSx (doc-empty "e")) "(article )")
|
||||
|
||||
;; ── render-* / block-* aliases ──
|
||||
(content-test "render-html alias" (render-html d) (asHTML d))
|
||||
(content-test "render-sx alias" (render-sx d) (asSx d))
|
||||
(content-test "block-html alias" (block-html h) "<h2>Title</h2>")
|
||||
|
||||
;; ── render reflects edits (immutability: each render is of a version) ──
|
||||
(define d2 (doc-update d "p" "text" "Edited"))
|
||||
(content-test
|
||||
"render after update"
|
||||
(asHTML d2)
|
||||
"<h2>Title</h2><p>Edited</p><hr>")
|
||||
(content-test
|
||||
"original render unchanged"
|
||||
(asHTML d)
|
||||
"<h2>Title</h2><p>Hello</p><hr>")
|
||||
(content-test
|
||||
"render after move"
|
||||
(asHTML (doc-move d "h" 2))
|
||||
"<p>Hello</p><hr><h2>Title</h2>")
|
||||
(content-test
|
||||
"render after delete"
|
||||
(asHTML (doc-delete d "p"))
|
||||
"<h2>Title</h2><hr>")
|
||||
Reference in New Issue
Block a user