Files
rose-ash/lib/tests/test-freeze.sx
giles f3f70cc00b Move stdlib out of spec — clean spec/library boundary
spec/ now contains only the language definition (5 files):
  evaluator.sx, parser.sx, primitives.sx, render.sx, special-forms.sx

lib/ contains code written IN the language (8 files):
  stdlib.sx, types.sx, freeze.sx, content.sx,
  bytecode.sx, compiler.sx, vm.sx, callcc.sx

Test files follow source: spec/tests/ for core language tests,
lib/tests/ for library tests (continuations, freeze, types, vm).

Updated all consumers:
- JS/Python/OCaml bootstrappers: added lib/ to source search paths
- OCaml bridge: spec_dir for parser/render, lib_dir for compiler/freeze
- JS test runner: scans spec/tests/ (always) + lib/tests/ (--full)
- OCaml test runner: scans spec/tests/, lib tests via explicit request
- Docker dev mounts: added ./lib:/app/lib:ro

Tests: 1041 JS standard, 1322 JS full, 1101 OCaml — all pass

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 23:18:30 +00:00

76 lines
2.6 KiB
Plaintext

;; ==========================================================================
;; test-freeze.sx — Freeze scope and content addressing tests
;; ==========================================================================
(defsuite "freeze-scope"
(deftest "freeze captures signal values"
(let ((s (signal 42)))
(freeze-scope "t1" (fn ()
(freeze-signal "val" s)))
(let ((frozen (cek-freeze-scope "t1")))
(assert-equal "t1" (get frozen "name"))
(assert-equal 42 (get (get frozen "signals") "val")))))
(deftest "thaw restores signal values"
(let ((s (signal 10)))
(freeze-scope "t2" (fn ()
(freeze-signal "x" s)))
(let ((sx (freeze-to-sx "t2")))
(reset! s 999)
(assert-equal 999 (deref s))
(thaw-from-sx sx)
(assert-equal 10 (deref s)))))
(deftest "multiple signals in scope"
(let ((a (signal "hello"))
(b (signal 42))
(c (signal true)))
(freeze-scope "t3" (fn ()
(freeze-signal "a" a)
(freeze-signal "b" b)
(freeze-signal "c" c)))
(let ((frozen (cek-freeze-scope "t3")))
(assert-equal "hello" (get (get frozen "signals") "a"))
(assert-equal 42 (get (get frozen "signals") "b"))
(assert-equal true (get (get frozen "signals") "c")))))
(deftest "freeze-to-sx round trip"
(let ((s (signal "data")))
(freeze-scope "t4" (fn ()
(freeze-signal "s" s)))
(let ((sx (freeze-to-sx "t4")))
(assert-true (string? sx))
(assert-true (contains? sx "data"))
(reset! s "changed")
(thaw-from-sx sx)
(assert-equal "data" (deref s))))))
(defsuite "content-addressing"
(deftest "content-hash deterministic"
(assert-equal (content-hash "hello") (content-hash "hello")))
(deftest "content-hash different for different input"
(assert-false (= (content-hash "hello") (content-hash "world"))))
(deftest "content-put and get"
(let ((cid (content-put "test data")))
(assert-equal "test data" (content-get cid))))
(deftest "freeze-to-cid round trip"
(let ((s (signal 77)))
(freeze-scope "t5" (fn ()
(freeze-signal "v" s)))
(let ((cid (freeze-to-cid "t5")))
(assert-true (string? cid))
(reset! s 0)
(assert-true (thaw-from-cid cid))
(assert-equal 77 (deref s)))))
(deftest "same state same cid"
(let ((s (signal 42)))
(freeze-scope "t6" (fn ()
(freeze-signal "n" s)))
(let ((cid1 (freeze-to-cid "t6"))
(cid2 (freeze-to-cid "t6")))
(assert-equal cid1 cid2)))))