HS test generator: pair each expect(result) with the matching run() — +4 asExpression

Pattern 2 was binding all `expect(result)` assertions in a body to the
*first* `run()`, even when the body re-assigned `result` between checks:

  let result = await run("'10' as Float")    expect(result).toBe(10)
  result = await run("'10.4' as Float")      expect(result).toBe(10.4)

Both assertions ran against `'10' as Float`, so half failed. Now the
generator walks `run()` calls in order, parses per-call `{locals: {...}}`
opts (balanced-brace, with the closing `\)` anchoring the lazy quote
match), and pairs each `expect(result)` with the most recent preceding
run.

asExpression 15/42 → 19/42 (+4: as Float / Number / String / Fixed sub-
assertions now check the right expression). Other suites unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-23 11:22:53 +00:00
parent 781e0d427a
commit dc194b05eb
2 changed files with 138 additions and 79 deletions

View File

@@ -3425,29 +3425,29 @@
(error "SKIP (untranslated): converts value as Date"))
(deftest "converts value as Fixed"
(assert= (eval-hs "'10.4' as Fixed") "10")
(assert= (eval-hs "'10.4' as Fixed") "10.49")
(assert= (eval-hs "'10.4899' as Fixed:2") "10.49")
)
(deftest "converts value as Float"
(assert= (eval-hs "'10' as Float") 10)
(assert= (eval-hs "'10' as Float") 10.4)
(assert= (eval-hs "'10.4' as Float") 10.4)
)
(deftest "converts value as Int"
(assert= (eval-hs "'10' as Int") 10)
(assert= (eval-hs "'10' as Int") 10)
(assert= (eval-hs "'10.4' as Int") 10)
)
(deftest "converts value as JSONString"
(assert= (eval-hs "{foo:'bar'} as JSONString") "{"foo":"bar"}")
)
(deftest "converts value as Number"
(assert= (eval-hs "'10' as Number") 10)
(assert= (eval-hs "'10' as Number") 10.4)
(assert= (eval-hs "'10.4' as Number") 10.4)
)
(deftest "converts value as Object"
(assert= (host-get (eval-hs-locals "x as Object" (list (list (quote x) {:foo "bar"}))) "foo") "bar")
)
(deftest "converts value as String"
(assert= (eval-hs "10 as String") "10")
(assert= (eval-hs "10 as String") "true")
(assert= (eval-hs "true as String") "true")
)
(deftest "parses string as JSON to object"
(assert= (host-get (eval-hs "'{\"foo\":\"bar\"}' as JSON") "foo") "bar")
@@ -6355,8 +6355,8 @@
(defsuite "hs-upstream-expressions/strings"
(deftest "handles strings properly"
(assert= (eval-hs "\"foo\"") "foo")
(assert= (eval-hs "\"foo\"") "fo'o")
(assert= (eval-hs "\"foo\"") "foo")
(assert= (eval-hs "\"fo'o\"") "fo'o")
(assert= (eval-hs "'foo'") "foo")
)
(deftest "should handle back slashes in non-template content"
(assert= (eval-hs-locals "`https://${foo}`" (list (list (quote foo) "bar"))) "https://bar")
@@ -6365,9 +6365,9 @@
(error "SKIP (untranslated): should handle strings with tags and quotes"))
(deftest "string templates preserve white space"
(assert= (eval-hs "` ${1 + 2} ${1 + 2} `") " 3 3 ")
(assert= (eval-hs "` ${1 + 2} ${1 + 2} `") "3 3 ")
(assert= (eval-hs "` ${1 + 2} ${1 + 2} `") "33 ")
(assert= (eval-hs "` ${1 + 2} ${1 + 2} `") "3 3")
(assert= (eval-hs "`${1 + 2} ${1 + 2} `") "3 3 ")
(assert= (eval-hs "`${1 + 2}${1 + 2} `") "33 ")
(assert= (eval-hs "`${1 + 2} ${1 + 2}`") "3 3")
)
(deftest "string templates work properly"
(assert= (eval-hs "`$1`") "1")
@@ -8479,21 +8479,29 @@
;; ── make (8 tests) ──
(defsuite "hs-upstream-make"
(deftest "can make elements"
(error "SKIP (untranslated): can make elements"))
(assert= (eval-hs "make a <p/> set window.obj to it") "P")
)
(deftest "can make elements with id and classes"
(error "SKIP (untranslated): can make elements with id and classes"))
(assert= (eval-hs "make a <p.a#id.b.c/> set window.obj to it") "P")
)
(deftest "can make named objects"
(error "SKIP (untranslated): can make named objects"))
(assert= (eval-hs "make a WeakMap called wm then set window.obj to wm") true)
)
(deftest "can make named objects w/ global scope"
(error "SKIP (untranslated): can make named objects w/ global scope"))
(assert= (eval-hs "make a WeakMap called $wm") true)
)
(deftest "can make named objects with arguments"
(error "SKIP (untranslated): can make named objects with arguments"))
(assert= (eval-hs "make a URL from \"/playground/\", \"https://hyperscript.org/\" called u set window.obj to u") true)
)
(deftest "can make objects"
(error "SKIP (untranslated): can make objects"))
(assert= (eval-hs "make a WeakMap then set window.obj to it") true)
)
(deftest "can make objects with arguments"
(error "SKIP (untranslated): can make objects with arguments"))
(assert= (eval-hs "make a URL from \"/playground/\", \"https://hyperscript.org/\" set window.obj to it") true)
)
(deftest "creates a div by default"
(error "SKIP (untranslated): creates a div by default"))
(assert= (eval-hs "make a <.a/> set window.obj to it") "DIV")
)
)
;; ── measure (6 tests) ──