Files
rose-ash/spec/tests/test-let-match.sx
giles 59adee0d2b W14: C9 eliminate empty suite labels (test-only) — section E complete
The finding ("spec suites print with empty suite label") was six files
wide: test-chars (43 suite-less top-level deftests), test-import-bind
(14), test-ports (12), test-let-match (8), test-math (deftests NESTED in
deftests — every test reported as " > sin"), and 4 stray deftests between
suites in test-hyperscript-conformance.

Fixes: file-level defsuite wraps for the four flat files (mechanical wrap,
sx_validate-checked); test-math restructured deftest->defsuite ("math >
string->number"); hs strays wrapped in suites named for their section
comments (hs-compat-blockLiteral/cookies/some/where). The two
baseline-visible identities are renamed in spec/tests/known-failures.txt
in this same commit — the F10 gate enforces exactly this coupling.

Full baseline gate validated GREEN: 5798p/273f, fail set identical
(the -2 passes are the two wrapper deftests that no longer self-report
a vacuous PASS around their children).

Test-only: no semantics edits, no push.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-04 04:39:23 +00:00

52 lines
1.5 KiB
Plaintext

(defsuite "let-match"
;; Tests for let-match — CEK special form and bytecode compiler desugaring
;; let-match destructures a dict: (let-match {:key var} expr body...)
(deftest "let-match destructures dict"
(let-match {:name n :age a} (dict :name "alice" :age 30)
(assert= n "alice")
(assert= a 30)))
(deftest "let-match inside let"
(let ((data (dict :status "ok" :value 42)))
(let-match {:status s :value v} data
(assert= s "ok")
(assert= v 42))))
(deftest "let-match missing key gives nil"
(let-match {:present p :missing m} (dict :present "yes")
(assert= p "yes")
(assert= m nil)))
(deftest "let-match body evaluates all expressions"
(let ((result nil))
(let-match {:a a} (dict :a 1)
(set! result a)
(assert= result 1))))
;; In function body — tests bytecode compiler desugaring path
(define lm-add (fn (d) (let-match {:x x :y y} d (+ x y))))
(deftest "let-match in compiled function"
(assert= (lm-add (dict :x 3 :y 7)) 10))
(define lm-format (fn (input) (let-match {:type t :value v} input (str t ":" v))))
(deftest "let-match variant 2 in compiled function"
(assert= (lm-format (dict :type "num" :value 5)) "num:5"))
;; Nested let-match
(deftest "nested let-match"
(let-match {:outer o} (dict :outer (dict :inner 99))
(let-match {:inner i} o
(assert= i 99))))
;; let-match with computed expression
(deftest "let-match with function call as expr"
(let-match {:a a :b b} (dict :a (+ 1 2) :b (* 3 4))
(assert= a 3)
(assert= b 12)))
)