(defsuite "canonical-serialize" (deftest "nil" (assert= (canonical-serialize nil) "nil")) (deftest "booleans" (assert= (canonical-serialize true) "true") (assert= (canonical-serialize false) "false")) (deftest "integers" (assert= (canonical-serialize 0) "0") (assert= (canonical-serialize 42) "42") (assert= (canonical-serialize -7) "-7")) (deftest "strings" (assert= (canonical-serialize "hello") "\"hello\"") (assert= (canonical-serialize "") "\"\"") (assert= (canonical-serialize "a\"b") "\"a\\\"b\"")) (deftest "symbols" (assert= (canonical-serialize (quote deref)) "deref") (assert= (canonical-serialize (quote swap!)) "swap!")) (deftest "keywords" (assert= (canonical-serialize (make-keyword "class")) ":class") (assert= (canonical-serialize (make-keyword "arity")) ":arity")) (deftest "empty list" (assert= (canonical-serialize (list)) "()")) (deftest "flat list" (assert= (canonical-serialize (list 1 2 3)) "(1 2 3)")) (deftest "nested list" (assert= (canonical-serialize (list (quote div) (make-keyword "class") "flex" (list (quote h2) "title"))) "(div :class \"flex\" (h2 \"title\"))")) (deftest "dict keys sorted" (let ((d {:zebra 1 :middle 3 :alpha 2})) (assert= (canonical-serialize d) "{:alpha 2 :middle 3 :zebra 1}"))) (deftest "dict with nested values" (let ((d {:b "hello" :a (list 1 2)})) (assert= (canonical-serialize d) "{:a (1 2) :b \"hello\"}")))) (defsuite "content-id" (deftest "same expression same CID" (assert= (content-id (list 1 2 3)) (content-id (list 1 2 3)))) (deftest "different expression different CID" (assert (not (= (content-id (list 1 2 3)) (content-id (list 1 2 4)))))) (deftest "CID is a hex string" (let ((cid (content-id 42))) (assert (string? cid)) (assert= (len cid) 64))) (deftest "short CID is 16 chars" (let ((cid (content-id-short 42))) (assert= (len cid) 16))) (deftest "short CID is prefix of full CID" (let ((full (content-id 42)) (short (content-id-short 42))) (assert= short (slice full 0 16))))) (defsuite "bytecode-module" (deftest "make and query" (let ((m (make-bytecode-module 1 "abc123" (list 1 2 3)))) (assert (bytecode-module? m)) (assert= (bytecode-module-version m) 1) (assert= (bytecode-module-source-hash m) "abc123"))) (deftest "non-module fails predicate" (assert (not (bytecode-module? (list 1 2 3)))) (assert (not (bytecode-module? "hello"))))) (defsuite "provenance" (deftest "make provenance record" (let ((p (make-provenance "src-cid" "bc-cid" "v1" "js"))) (assert= (first p) (quote provenance)) (assert= (nth p 2) "src-cid") (assert= (nth p 4) "bc-cid"))))