sx-tools: WASM kernel updates, TW/CSSX rework, content refresh, new debugging tools
Build tooling: updated OCaml bootstrapper, compile-modules, bundle.sh, sx-build-all. WASM browser: rebuilt sx_browser.bc.js/wasm, sx-platform-2.js, .sxbc bytecode files. CSSX/Tailwind: reworked cssx.sx templates and tw-layout, added tw-type support. Content: refreshed essays, plans, geography, reactive islands, docs, demos, handlers. New tools: bisect_sxbc.sh, test-spa.js, render-trace.sx, morph playwright spec. Tests: added test-match.sx, test-examples.sx, updated test-tw.sx and web tests. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
65
spec/tests/test-match.sx
Normal file
65
spec/tests/test-match.sx
Normal file
@@ -0,0 +1,65 @@
|
||||
(defsuite
|
||||
"match-literals"
|
||||
(deftest
|
||||
"match number"
|
||||
(assert-equal "one" (match 1 (1 "one") (2 "two"))))
|
||||
(deftest
|
||||
"match string"
|
||||
(assert-equal "hello" (match "hi" ("hi" "hello") ("bye" "goodbye"))))
|
||||
(deftest
|
||||
"match boolean"
|
||||
(assert-equal "yes" (match true (true "yes") (false "no"))))
|
||||
(deftest
|
||||
"match nil"
|
||||
(assert-equal "nothing" (match nil (nil "nothing") (_ "something")))))
|
||||
|
||||
(defsuite
|
||||
"match-binding"
|
||||
(deftest
|
||||
"wildcard matches anything"
|
||||
(assert-equal "ok" (match 42 (_ "ok"))))
|
||||
(deftest "symbol binds value" (assert-equal 42 (match 42 (x x))))
|
||||
(deftest "binding used in body" (assert-equal 84 (match 42 (x (* x 2))))))
|
||||
|
||||
(defsuite
|
||||
"match-lists"
|
||||
(deftest
|
||||
"match list structure"
|
||||
(assert-equal 3 (match (list 1 2) ((a b) (+ a b)))))
|
||||
(deftest
|
||||
"match nested list"
|
||||
(assert-equal
|
||||
"y"
|
||||
(match (list 1 (list 2 3)) ((a (b c)) (if (= c 3) "y" "n")))))
|
||||
(deftest
|
||||
"match empty list"
|
||||
(assert-equal "empty" (match (list) (() "empty") (_ "nonempty")))))
|
||||
|
||||
(defsuite
|
||||
"match-quoted"
|
||||
(deftest
|
||||
"match quoted symbol"
|
||||
(assert-equal
|
||||
"got-foo"
|
||||
(match (quote foo) ((quote foo) "got-foo") ((quote bar) "got-bar"))))
|
||||
(deftest
|
||||
"match quoted vs binding"
|
||||
(assert-equal
|
||||
"bound: foo"
|
||||
(match (quote foo) ((quote bar) "got-bar") (x (str "bound: " x))))))
|
||||
|
||||
(defsuite
|
||||
"match-predicates"
|
||||
(deftest
|
||||
"predicate match"
|
||||
(assert-equal
|
||||
"it's a number"
|
||||
(match 42 ((? number?) "it's a number") (_ "other"))))
|
||||
(deftest
|
||||
"predicate with string"
|
||||
(assert-equal
|
||||
"text"
|
||||
(match "hello" ((? number?) "num") ((? string?) "text") (_ "other"))))
|
||||
(deftest
|
||||
"no match errors"
|
||||
(assert-throws (fn () (match 42 (0 "zero") (1 "one"))))))
|
||||
@@ -661,11 +661,54 @@
|
||||
"gap-y-2"
|
||||
(assert= (tw-resolve-layout "gap-y-2") "row-gap:0.5rem"))
|
||||
(deftest
|
||||
"space-x-4"
|
||||
(assert= (tw-resolve-layout "space-x-4") "column-gap:1rem"))
|
||||
"space-x-4 → child margin-left"
|
||||
(assert= (get (tw-resolve-layout "space-x-4") :css) "margin-left:1rem"))
|
||||
(deftest
|
||||
"space-y-2"
|
||||
(assert= (tw-resolve-layout "space-y-2") "row-gap:0.5rem")))
|
||||
"space-y-2 → child margin-top"
|
||||
(assert= (get (tw-resolve-layout "space-y-2") :css) "margin-top:0.5rem")))
|
||||
|
||||
(defsuite
|
||||
"tw-space-child-selectors"
|
||||
(deftest
|
||||
"space-y-2 returns dict with :suffix"
|
||||
(assert= (get (tw-resolve-layout "space-y-2") :suffix) ">*+*"))
|
||||
(deftest
|
||||
"space-x-4 returns dict with :suffix"
|
||||
(assert= (get (tw-resolve-layout "space-x-4") :suffix) ">*+*"))
|
||||
(deftest
|
||||
"space-y-4 css is margin-top"
|
||||
(assert= (get (tw-resolve-layout "space-y-4") :css) "margin-top:1rem"))
|
||||
(deftest
|
||||
"space-x-2 css is margin-left"
|
||||
(assert= (get (tw-resolve-layout "space-x-2") :css) "margin-left:0.5rem"))
|
||||
(deftest
|
||||
"space-y-0 css is margin-top:0px"
|
||||
(assert= (get (tw-resolve-layout "space-y-0") :css) "margin-top:0px"))
|
||||
(deftest
|
||||
"space-y-8 css is margin-top:2rem"
|
||||
(assert= (get (tw-resolve-layout "space-y-8") :css) "margin-top:2rem"))
|
||||
(deftest
|
||||
"space-y-4 full rule uses child selector"
|
||||
(let
|
||||
((result (tw-process-token "space-y-4")))
|
||||
(assert= (get result "rule") ".sx-space-y-4>*+*{margin-top:1rem}")))
|
||||
(deftest
|
||||
"space-x-2 full rule uses child selector"
|
||||
(let
|
||||
((result (tw-process-token "space-x-2")))
|
||||
(assert= (get result "rule") ".sx-space-x-2>*+*{margin-left:0.5rem}")))
|
||||
(deftest
|
||||
"gap-4 does NOT use child selector"
|
||||
(let
|
||||
((result (tw-process-token "gap-4")))
|
||||
(assert= (get result "rule") ".sx-gap-4{gap:1rem}")))
|
||||
(deftest
|
||||
"hover:space-y-2 rule includes pseudo + child selector"
|
||||
(let
|
||||
((result (tw-process-token "hover:space-y-2")))
|
||||
(assert=
|
||||
(get result "rule")
|
||||
".sx-hover-space-y-2:hover>*+*{margin-top:0.5rem}"))))
|
||||
|
||||
(defsuite
|
||||
"tw-spacing-value"
|
||||
|
||||
Reference in New Issue
Block a user