diff --git a/lib/content/conformance.sh b/lib/content/conformance.sh index 7158b62b..4c4ab5b5 100755 --- a/lib/content/conformance.sh +++ b/lib/content/conformance.sh @@ -15,7 +15,7 @@ if [ ! -x "$SX_SERVER" ]; then fi fi -SUITES=(block doc render api meta page page-full markdown text section compose stats table data validate store snapshot crdt crdt-store sync md-import md-doc fed) +SUITES=(block doc render api meta page page-full markdown text section compose stats table data wire validate store snapshot crdt crdt-store sync md-import md-doc fed) OUT_JSON="lib/content/scoreboard.json" OUT_MD="lib/content/scoreboard.md" @@ -49,6 +49,7 @@ run_suite() { (load "lib/content/stats.sx") (load "lib/content/table.sx") (load "lib/content/data.sx") +(load "lib/content/wire.sx") (load "lib/content/page.sx") (load "lib/content/page-full.sx") (load "lib/content/markdown.sx") diff --git a/lib/content/scoreboard.json b/lib/content/scoreboard.json index adee7c9d..6a90f654 100644 --- a/lib/content/scoreboard.json +++ b/lib/content/scoreboard.json @@ -14,6 +14,7 @@ "stats": {"pass": 17, "fail": 0}, "table": {"pass": 15, "fail": 0}, "data": {"pass": 21, "fail": 0}, + "wire": {"pass": 11, "fail": 0}, "validate": {"pass": 23, "fail": 0}, "store": {"pass": 29, "fail": 0}, "snapshot": {"pass": 20, "fail": 0}, @@ -24,7 +25,7 @@ "md-doc": {"pass": 12, "fail": 0}, "fed": {"pass": 20, "fail": 0} }, - "total_pass": 523, + "total_pass": 534, "total_fail": 0, - "total": 523 + "total": 534 } diff --git a/lib/content/scoreboard.md b/lib/content/scoreboard.md index f144b600..9497efba 100644 --- a/lib/content/scoreboard.md +++ b/lib/content/scoreboard.md @@ -18,6 +18,7 @@ _Generated by `lib/content/conformance.sh`_ | stats | 17 | 0 | 17 | | table | 15 | 0 | 15 | | data | 21 | 0 | 21 | +| wire | 11 | 0 | 11 | | validate | 23 | 0 | 23 | | store | 29 | 0 | 29 | | snapshot | 20 | 0 | 20 | @@ -27,4 +28,4 @@ _Generated by `lib/content/conformance.sh`_ | md-import | 38 | 0 | 38 | | md-doc | 12 | 0 | 12 | | fed | 20 | 0 | 20 | -| **Total** | **523** | **0** | **523** | +| **Total** | **534** | **0** | **534** | diff --git a/lib/content/tests/wire.sx b/lib/content/tests/wire.sx new file mode 100644 index 00000000..afa289f0 --- /dev/null +++ b/lib/content/tests/wire.sx @@ -0,0 +1,63 @@ +;; Extension — on-the-wire serialization (to-wire / from-wire). + +(st-bootstrap-classes!) +(content/bootstrap!) +(content-bootstrap-text!) +(content-bootstrap-section!) +(content-bootstrap-table!) + +(define + d + (doc-with-meta + (doc-append + (doc-append (doc-empty "post") (mk-heading "h" 1 "Title")) + (mk-text "p" "Body text")) + {:title "T" :tags (list "x" "y")})) + +;; ── to-wire produces a string ── +(content-test "to-wire is string" (string? (content/to-wire d)) true) + +;; ── parse(to-wire) == data form ── +(content-test + "wire parses to data" + (parse (content/to-wire d)) + (content/to-data d)) + +;; ── round-trip preserves everything ── +(define rt (content/wire-round-trip d)) +(content-test "rt id" (doc-id rt) "post") +(content-test "rt title" (doc-title rt) "T") +(content-test "rt tags" (doc-tags rt) (list "x" "y")) +(content-test "rt ids" (doc-ids rt) (list "h" "p")) +(content-test "rt render" (asHTML rt) (asHTML d)) + +;; ── nested + table survive the wire ── +(define + dn + (doc-append + (doc-append + (doc-empty "d") + (mk-section "s" (list (mk-text "a" "deep")))) + (mk-table "t" (list "A") (list (list "1"))))) +(content-test + "wire nested render" + (asHTML (content/wire-round-trip dn)) + (asHTML dn)) +(content-test + "wire nested tree-ids" + (doc-tree-ids (content/wire-round-trip dn)) + (doc-tree-ids dn)) + +;; ── empty doc ── +(content-test + "wire empty" + (doc-ids (content/from-wire (content/to-wire (doc-empty "e")))) + (list)) + +;; ── from-wire of an externally-built wire string ── +(content-test + "from-wire external" + (asHTML + (content/from-wire + "{:id \"x\" :blocks ({:id \"h\" :type \"heading\" :fields {:level 2 :text \"Hi\"}})}")) + "