;; AUTO-GENERATED from spec/tests/hyperscript-upstream-tests.json
;; DO NOT EDIT — regenerate with:
;;   python3 tests/playwright/generate-sx-tests.py --emit-pages

(defcomp ()
  (~docs/page :title "Hyperscript: def (27 tests — 7 runnable)"
    (p :style "color:#57534e;margin-bottom:1rem" "Live cards for the upstream def tests. 7 of 27 are reproducible in-browser; the remainder show their source for reference.")
    (p :style "color:#78716c;font-size:0.875rem;margin-bottom:1rem"
      "Theme: " (a :href "/sx/(applications.(hyperscript.gallery-language))"
        :style "color:#7c3aed" "language"))
    (div :style "display:flex;flex-direction:column"
      (~hyperscript/hs-test-card
  :name "can define a basic no arg function"
  :html "<script type='text/hyperscript'>def foo()   add .called to #d1 end</script> | <div _='on click call foo()'></div> | <div id='d1'></div>"
  :action "bar.click()"
  :check "div.classList.contains(\"called\").should.equal(false) && div.classList.contains(\"called\").should.equal(true)"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")) (_el-d1 (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click call foo()\")
    (dom-set-attr _el-d1 \"id\" \"d1\")
    (dom-append sandbox _el-div)
    (dom-append sandbox _el-d1)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (assert (dom-has-class? _el-div \"called\"))
  ))")
(~hyperscript/hs-test-card
  :name "can define a basic one arg function"
  :html "<script type='text/hyperscript'>def foo(str) put str into #d1.innerHTML end</script> | <div _='on click call foo(\"called\")'></div> | <div id='d1'></div>"
  :action "bar.click()"
  :check "div.innerHTML.should.equal(\"\") && div.innerHTML.should.equal(\"called\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")) (_el-d1 (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click call foo(\\\"called\\\")\")
    (dom-set-attr _el-d1 \"id\" \"d1\")
    (dom-append sandbox _el-div)
    (dom-append sandbox _el-d1)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (assert= (dom-inner-html _el-div) \"called\")
  ))")
(~hyperscript/hs-test-card
  :name "functions can be namespaced"
  :html "<script type='text/hyperscript'>def utils.foo()   add .called to #d1 end</script> | <div _='on click call utils.foo()'></div> | <div id='d1'></div>"
  :action "bar.click()"
  :check "div.classList.contains(\"called\").should.equal(false) && div.classList.contains(\"called\").should.equal(true)"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")) (_el-d1 (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click call utils.foo()\")
    (dom-set-attr _el-d1 \"id\" \"d1\")
    (dom-append sandbox _el-div)
    (dom-append sandbox _el-d1)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (assert (dom-has-class? _el-div \"called\"))
  ))")
(~hyperscript/hs-test-card
  :name "is called synchronously"
  :html "<script type='text/hyperscript'>def foo()   log meend</script> | <div _='on click call foo() then add .called to #d1'></div> | <div id='d1'></div>"
  :action "bar.click()"
  :check "div.classList.contains(\"called\").should.equal(false) && div.classList.contains(\"called\").should.equal(true)"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")) (_el-d1 (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click call foo() then add .called to #d1\")
    (dom-set-attr _el-d1 \"id\" \"d1\")
    (dom-append sandbox _el-div)
    (dom-append sandbox _el-d1)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (assert (dom-has-class? _el-div \"called\"))
  ))")
(~hyperscript/hs-test-card
  :name "can call asynchronously"
  :html "<script type='text/hyperscript'>def foo()   wait 1ms  log meend</script> | <div _='on click call foo() then add .called to #d1'></div> | <div id='d1'></div>"
  :action "bar.click()"
  :check "div.classList.contains(\"called\").should.equal(false) && div.classList.contains(\"called\").should.equal(true)"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")) (_el-d1 (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click call foo() then add .called to #d1\")
    (dom-set-attr _el-d1 \"id\" \"d1\")
    (dom-append sandbox _el-div)
    (dom-append sandbox _el-d1)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (assert (dom-has-class? _el-div \"called\"))
  ))")
(~hyperscript/hs-test-card
  :name "can return a value synchronously"
  :html "<script type='text/hyperscript'>def foo()   return \"foo\"end</script> | <div _='on click call foo() then put it into #d1.innerText'></div> | <div id='d1'></div>"
  :action "bar.click()"
  :check "div.innerText.should.equal(\"\") && div.innerText.should.equal(\"foo\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")) (_el-d1 (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click call foo() then put it into #d1.innerText\")
    (dom-set-attr _el-d1 \"id\" \"d1\")
    (dom-append sandbox _el-div)
    (dom-append sandbox _el-d1)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    ;; SKIP check: skip div.innerText.should.equal(\"\")
    ;; SKIP check: skip div.innerText.should.equal(\"foo\")
  ))")
(~hyperscript/hs-test-card
  :name "can exit"
  :html "<script type='text/hyperscript'>def foo()   exit end</script>"
  :action "(see body)"
  :check "(no explicit assertion)"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "can return a value asynchronously"
  :html "<script type='text/hyperscript'>def foo()   wait 1ms  return \"foo\"end</script> | <div _='on click call foo() then put it into #d1.innerText'></div> | <div id='d1'></div>"
  :action "bar.click()"
  :check "div.innerText.should.equal(\"\") && div.innerText.should.equal(\"foo\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")) (_el-d1 (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click call foo() then put it into #d1.innerText\")
    (dom-set-attr _el-d1 \"id\" \"d1\")
    (dom-append sandbox _el-div)
    (dom-append sandbox _el-d1)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    ;; SKIP check: skip div.innerText.should.equal(\"\")
    ;; SKIP check: skip div.innerText.should.equal(\"foo\")
  ))")
(~hyperscript/hs-test-card
  :name "can interop with javascript"
  :html "<script type='text/hyperscript'>def foo()   return \"foo\"end</script>"
  :action "(see body)"
  :check "foo().should.equal(\"foo\")"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "can interop with javascript asynchronously"
  :html "<script type='text/hyperscript'>def foo()   wait 1ms  return \"foo\"end</script>"
  :action "(see body)"
  :check "val.should.equal(\"foo\")"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "can catch exceptions"
  :html "<script type='text/hyperscript'>def foo()   throw \"bar\"catch e    set window.bar to e end</script>"
  :action "(see body)"
  :check "window.bar.should.equal(\"bar\")"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "can rethrow in catch blocks"
  :html "<script type='text/hyperscript'>def foo()   throw \"bar\"catch e    throw e end</script>"
  :action "(see body)"
  :check "true.should.equal(false) && e.should.equal(\"bar\")"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "can return in catch blocks"
  :html "<script type='text/hyperscript'>def foo()   throw \"bar\"catch e    return 42 end</script>"
  :action "(see body)"
  :check "foo().should.equal(42)"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "can catch async exceptions"
  :html "<script type='text/hyperscript'>def doh()   wait 10ms  throw \"bar\"end  def foo()   call doh()catch e    set window.bar to e end</script>"
  :action "(see body)"
  :check "window.bar.should.equal(\"bar\")"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "can catch nested async exceptions"
  :html "<script type='text/hyperscript'>def doh()   wait 10ms  throw \"bar\"end  def foo()   call doh()catch e    set window.bar to e end</script>"
  :action "(see body)"
  :check "window.bar.should.equal(\"bar\")"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "can rethrow in async catch blocks"
  :html "<script type='text/hyperscript'>def foo()   throw \"bar\"catch e    wait 10ms    throw e end</script>"
  :action "(see body)"
  :check "reason.should.equal(\"bar\")"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "can return in async catch blocks"
  :html "<script type='text/hyperscript'>def foo()   throw \"bar\"catch e    wait 10ms    return 42 end</script>"
  :action "(see body)"
  :check "val.should.equal(42)"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "can install a function on an element and use in children w/ no leak"
  :html "<div _='def func() put 42 into #d3'><div id='d1' _='on click call func()'></div><div id='d2'></div><div id='d3'></div> </div>"
  :action "(see body)"
  :check "byId(\"d3\").innerText.should.equal(\"42\")"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "can install a function on an element and use in children w/ return value"
  :html "<div _='def func() return 42'><div id='d1' _='on click put func() into me'></div><div id='d2'></div><div id='d3'></div> </div>"
  :action "(see body)"
  :check "byId(\"d1\").innerText.should.equal(\"42\")"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "can install a function on an element and use me symbol correctly"
  :html "<div _='def func() put 42 into me'><div id='d1' _='on click call func()'></div><div id='d2'></div><div id='d3'></div> </div>"
  :action "(see body)"
  :check "div.innerText.should.equal(\"42\")"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "finally blocks run normally"
  :html "<script type='text/hyperscript'>def foo()   set window.bar to 10finally    set window.bar to 20 end</script>"
  :action "(see body)"
  :check "window.bar.should.equal(20)"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "finally blocks run when an exception occurs"
  :html "<script type='text/hyperscript'>def foo()   set window.bar to 10  throw \"foo\"finally    set window.bar to 20 end</script>"
  :action "(see body)"
  :check "window.bar.should.equal(20)"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "finally blocks run when an exception expr occurs"
  :html "<script type='text/hyperscript'>def foo()   set window.bar to 10  call throwsAsyncException()finally    set window.bar to 20 end</script>"
  :action "(see body)"
  :check "window.bar.should.equal(20)"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "async finally blocks run normally"
  :html "<script type='text/hyperscript'>def foo()   wait a tick then set window.bar to 10finally    set window.bar to 20 end</script>"
  :action "(see body)"
  :check "window.bar.should.equal(20)"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "async finally blocks run when an exception occurs"
  :html "<script type='text/hyperscript'>def foo()   wait a tick then set window.bar to 10  throw \"foo\"finally    set window.bar to 20 end</script>"
  :action "(see body)"
  :check "window.bar.should.equal(20)"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "exit stops execution mid-function"
  :html "<script type='text/hyperscript'>def foo() set x to 1 then exit then set x to 2 then return x end</script>"
  :action ""
  :check ""
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "can return without a value"
  :html "<script type='text/hyperscript'>def foo()   return end</script>"
  :action ""
  :check ""
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))"))))
