Add computed+HO tests, remove duplicate pretext-layout-lines define
- 7 new tests in computed-ho-forms suite: computed with map, reduce, for-each, nested map, dict creation, signal updates. All pass on OCaml and WASM sandbox. - Removed standalone pretext-position-line and pretext-layout-lines from pretext-demo.sx — now in text-layout library only - Root cause of island error: pretext-demo.sx had old define with (reduce + 0 lwid) that the server serialized into component defs, overriding the library's sum-loop version Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -598,3 +598,87 @@
|
||||
(assert-equal
|
||||
"hello world"
|
||||
(bind (str (context :first) " " (context :second))))))))
|
||||
|
||||
(defsuite
|
||||
"computed-ho-forms"
|
||||
(deftest
|
||||
"computed with map"
|
||||
(let
|
||||
((s (signal 10))
|
||||
(c
|
||||
(computed (fn () (map (fn (x) (* x (deref s))) (list 1 2 3))))))
|
||||
(assert-equal (list 10 20 30) (deref c))))
|
||||
(deftest
|
||||
"computed with map then reduce"
|
||||
(let
|
||||
((s (signal 10))
|
||||
(c
|
||||
(computed
|
||||
(fn
|
||||
()
|
||||
(let
|
||||
((widths (map (fn (x) (* x (deref s))) (list 1 2 3))))
|
||||
(reduce + 0 widths))))))
|
||||
(assert-equal 60 (deref c))))
|
||||
(deftest
|
||||
"computed with map+reduce updates on signal change"
|
||||
(let
|
||||
((s (signal 10))
|
||||
(c
|
||||
(computed
|
||||
(fn
|
||||
()
|
||||
(reduce + 0 (map (fn (x) (* x (deref s))) (list 1 2 3)))))))
|
||||
(assert-equal 60 (deref c))
|
||||
(reset! s 5)
|
||||
(assert-equal 30 (deref c))))
|
||||
(deftest
|
||||
"computed with for-each and mutation"
|
||||
(let
|
||||
((s (signal 2))
|
||||
(c
|
||||
(computed
|
||||
(fn
|
||||
()
|
||||
(let
|
||||
((acc (list)))
|
||||
(for-each
|
||||
(fn (x) (append! acc (* x (deref s))))
|
||||
(list 10 20 30))
|
||||
acc)))))
|
||||
(assert-equal (list 20 40 60) (deref c))))
|
||||
(deftest
|
||||
"computed with nested map"
|
||||
(let
|
||||
((s (signal 1))
|
||||
(c
|
||||
(computed
|
||||
(fn
|
||||
()
|
||||
(map
|
||||
(fn (row) (map (fn (x) (+ x (deref s))) row))
|
||||
(list (list 1 2) (list 3 4)))))))
|
||||
(assert-equal (list (list 2 3) (list 4 5)) (deref c))))
|
||||
(deftest
|
||||
"computed with map producing dicts"
|
||||
(let
|
||||
((s (signal 10))
|
||||
(c
|
||||
(computed (fn () (map (fn (w) {:width (* (len w) (deref s)) :word w}) (list "hi" "there"))))))
|
||||
(let
|
||||
((result (deref c)))
|
||||
(assert-equal 2 (len result))
|
||||
(assert-equal "hi" (get (first result) :word))
|
||||
(assert-equal 20 (get (first result) :width)))))
|
||||
(deftest
|
||||
"computed with map+dict then sum widths"
|
||||
(let
|
||||
((s (signal 10))
|
||||
(c
|
||||
(computed
|
||||
(fn
|
||||
()
|
||||
(let
|
||||
((items (map (fn (w) {:width (* (len w) (deref s)) :word w}) (list "hi" "there" "world"))))
|
||||
(reduce + 0 (map (fn (item) (get item :width)) items)))))))
|
||||
(assert-equal 120 (deref c)))))
|
||||
|
||||
Reference in New Issue
Block a user