;; 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: repeat (30 tests — 20 runnable)"
    (p :style "color:#57534e;margin-bottom:1rem" "Live cards for the upstream repeat tests. 20 of 30 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-control))"
        :style "color:#7c3aed" "control"))
    (div :style "display:flex;flex-direction:column"
      (~hyperscript/hs-test-card
  :name "basic for loop works"
  :html "<div _='on click repeat for x in [1, 2, 3]                                    put x at end of me                                  end'></div>"
  :action "d1.click()"
  :check "d1.innerHTML.should.equal(\"123\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click repeat for x in [1, 2, 3]  put x at end of me end\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (assert= (dom-inner-html _el-div) \"123\")
  ))")
(~hyperscript/hs-test-card
  :name "basic for loop with null works"
  :html "<div _='on click repeat for x in null                                    put x at end of me                                  end'></div>"
  :action "d1.click()"
  :check "d1.innerHTML.should.equal(\"\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click repeat for x in null  put x at end of me end\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (assert= (dom-inner-html _el-div) \"\")
  ))")
(~hyperscript/hs-test-card
  :name "waiting in for loop works"
  :html "<div _='on click repeat for x in [1, 2, 3]\\n                                    log me                                     put x at end of me\\n                                    wait 1ms\\n                                  end'></div>"
  :action "d1.click()"
  :check "d1.innerHTML.should.equal(\"1\") && d1.innerHTML.should.equal(\"123\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click repeat for x in [1, 2, 3]  log me then put x at end of me then wait 1ms then end\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (assert= (dom-inner-html _el-div) \"123\")
  ))")
(~hyperscript/hs-test-card
  :name "basic raw for loop works"
  :html "<div _='on click for x in [1, 2, 3]                                    put x at end of me                                  end'></div>"
  :action "d1.click()"
  :check "d1.innerHTML.should.equal(\"123\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click for x in [1, 2, 3]  put x at end of me end\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (assert= (dom-inner-html _el-div) \"123\")
  ))")
(~hyperscript/hs-test-card
  :name "basic raw for loop works"
  :html "<div _='on click for x in null                                    put x at end of me                                  end'></div>"
  :action "d1.click()"
  :check "d1.innerHTML.should.equal(\"\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click for x in null  put x at end of me end\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (assert= (dom-inner-html _el-div) \"\")
  ))")
(~hyperscript/hs-test-card
  :name "waiting in raw for loop works"
  :html "<div _='on click for x in [1, 2, 3]\\n                                    put x at end of me\\n                                    wait 1ms\\n                                  end'></div>"
  :action "d1.click()"
  :check "d1.innerHTML.should.equal(\"1\") && d1.innerHTML.should.equal(\"123\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click for x in [1, 2, 3]  put x at end of me then wait 1ms then end\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (assert= (dom-inner-html _el-div) \"123\")
  ))")
(~hyperscript/hs-test-card
  :name "repeat forever works"
  :html "<script type='text/hyperscript'>  def repeatForeverWithReturn()    set retVal to 0    repeat forever       set retVal to retVal + 1       if retVal == 5 then         return retVal       end    end  end</script><div id='d1' _='on click put repeatForeverWithReturn() into my.innerHTML'></div>"
  :action "d1.click()"
  :check "d1.innerHTML.should.equal(\"5\")"
  :run-src "(fn (sandbox)
  (let ((_el-d1 (dom-create-element \"div\")))
    (dom-set-attr _el-d1 \"id\" \"d1\")
    (dom-set-attr _el-d1 \"_\" \"on click put repeatForeverWithReturn() into my.innerHTML\")
    (dom-append sandbox _el-d1)
    (hs-activate! _el-d1)
    (dom-dispatch _el-d1 \"click\" nil)
    (assert= (dom-inner-html _el-d1) \"5\")
  ))")
(~hyperscript/hs-test-card
  :name "repeat forever works w/o keyword"
  :html "<script type='text/hyperscript'>  def repeatForeverWithReturn()    set retVal to 0    repeat       set retVal to retVal + 1       if retVal == 5 then         return retVal       end    end  end</script><div id='d1' _='on click put repeatForeverWithReturn() into my.innerHTML'></div>"
  :action "d1.click()"
  :check "d1.innerHTML.should.equal(\"5\")"
  :run-src "(fn (sandbox)
  (let ((_el-d1 (dom-create-element \"div\")))
    (dom-set-attr _el-d1 \"id\" \"d1\")
    (dom-set-attr _el-d1 \"_\" \"on click put repeatForeverWithReturn() into my.innerHTML\")
    (dom-append sandbox _el-d1)
    (hs-activate! _el-d1)
    (dom-dispatch _el-d1 \"click\" nil)
    (assert= (dom-inner-html _el-d1) \"5\")
  ))")
(~hyperscript/hs-test-card
  :name "basic in loop works"
  :html "<div _='on click repeat in [1, 2, 3]                                    put it at end of me                                  end'></div>"
  :action "d1.click()"
  :check "d1.innerHTML.should.equal(\"123\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click repeat in [1, 2, 3]  put it at end of me end\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (assert= (dom-inner-html _el-div) \"123\")
  ))")
(~hyperscript/hs-test-card
  :name "index syntax works"
  :html "<div _='on click repeat for x in [\"a\", \"ab\", \"abc\"] index i                                    put x + i at end of me                                  end'></div>"
  :action "d1.click()"
  :check "d1.innerHTML.should.equal(\"a0ab1abc2\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click repeat for x in [\\\"a\\\", \\\"ab\\\", \\\"abc\\\"] index i then put x + i at end of me end\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (assert= (dom-inner-html _el-div) \"a0ab1abc2\")
  ))")
(~hyperscript/hs-test-card
  :name "indexed by syntax works"
  :html "<div _='on click repeat for x in [\"a\", \"ab\", \"abc\"] indexed by i                                    put x + i at end of me                                  end'></div>"
  :action "d1.click()"
  :check "d1.innerHTML.should.equal(\"a0ab1abc2\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click repeat for x in [\\\"a\\\", \\\"ab\\\", \\\"abc\\\"] indexed by i then put x + i at end of me end\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (assert= (dom-inner-html _el-div) \"a0ab1abc2\")
  ))")
(~hyperscript/hs-test-card
  :name "while keyword works"
  :html "<script type='text/hyperscript'>  def repeatWhileTest()    set retVal to 0    repeat while retVal < 5       set retVal to retVal + 1    end    return retVal  end</script><div id='d1' _='on click put repeatWhileTest() into my.innerHTML'></div>"
  :action "d1.click()"
  :check "d1.innerHTML.should.equal(\"5\")"
  :run-src "(fn (sandbox)
  (let ((_el-d1 (dom-create-element \"div\")))
    (dom-set-attr _el-d1 \"id\" \"d1\")
    (dom-set-attr _el-d1 \"_\" \"on click put repeatWhileTest() into my.innerHTML\")
    (dom-append sandbox _el-d1)
    (hs-activate! _el-d1)
    (dom-dispatch _el-d1 \"click\" nil)
    (assert= (dom-inner-html _el-d1) \"5\")
  ))")
(~hyperscript/hs-test-card
  :name "until keyword works"
  :html "<script type='text/hyperscript'>  def repeatUntilTest()    set retVal to 0    repeat until retVal == 5       set retVal to retVal + 1    end    return retVal  end</script><div id='d1' _='on click put repeatUntilTest() into my.innerHTML'></div>"
  :action "d1.click()"
  :check "d1.innerHTML.should.equal(\"5\")"
  :run-src "(fn (sandbox)
  (let ((_el-d1 (dom-create-element \"div\")))
    (dom-set-attr _el-d1 \"id\" \"d1\")
    (dom-set-attr _el-d1 \"_\" \"on click put repeatUntilTest() into my.innerHTML\")
    (dom-append sandbox _el-d1)
    (hs-activate! _el-d1)
    (dom-dispatch _el-d1 \"click\" nil)
    (assert= (dom-inner-html _el-d1) \"5\")
  ))")
(~hyperscript/hs-test-card
  :name "until event keyword works"
  :html "<div id='untilTest'></div> | <script type='text/hyperscript'>  def repeatUntilTest()    repeat until event click from #untilTest      wait 2ms    end    return 42  end</script>"
  :action "div.click()"
  :check "value.should.equal(42)"
  :run-src "(fn (sandbox)
  (let ((_el-untilTest (dom-create-element \"div\")))
    (dom-set-attr _el-untilTest \"id\" \"untilTest\")
    (dom-append sandbox _el-untilTest)
    (dom-dispatch _el-untilTest \"click\" nil)
    ;; SKIP check: skip value.should.equal(42)
  ))")
(~hyperscript/hs-test-card
  :name "only executes the init expression once"
  :html "<script type='text/hyperscript'>  def getArray()    set window.called to (window.called or 0) + 1    return [1, 2, 3]  end</script><div id='d1' _='on click for x in getArray() put x into my.innerHTML end'></div>"
  :action "d1.click()"
  :check "d1.innerHTML.should.equal(\"3\") && window.called.should.equal(1)"
  :run-src "(fn (sandbox)
  (let ((_el-d1 (dom-create-element \"div\")))
    (dom-set-attr _el-d1 \"id\" \"d1\")
    (dom-set-attr _el-d1 \"_\" \"on click for x in getArray() put x into my.innerHTML end\")
    (dom-append sandbox _el-d1)
    (hs-activate! _el-d1)
    (dom-dispatch _el-d1 \"click\" nil)
    (assert= (dom-inner-html _el-d1) \"3\")
    ;; SKIP check: skip window.called.should.equal(1)
  ))")
(~hyperscript/hs-test-card
  :name "can nest loops"
  :html "<script type='text/hyperscript'>  def sprayInto(elt)    for x in [1, 2, 3]      for y in [1, 2, 3]        put x * y at end of elt      end    end  end</script><div id='d1' _='on click call sprayInto(me)'></div>"
  :action "d1.click()"
  :check "d1.innerHTML.should.equal(\"123246369\")"
  :run-src "(fn (sandbox)
  (let ((_el-d1 (dom-create-element \"div\")))
    (dom-set-attr _el-d1 \"id\" \"d1\")
    (dom-set-attr _el-d1 \"_\" \"on click call sprayInto(me)\")
    (dom-append sandbox _el-d1)
    (hs-activate! _el-d1)
    (dom-dispatch _el-d1 \"click\" nil)
    (assert= (dom-inner-html _el-d1) \"123246369\")
  ))")
(~hyperscript/hs-test-card
  :name "basic times loop works"
  :html "<div _='on click repeat 3 times                                    put \"a\" at end of me                                  end'></div>"
  :action "d1.click()"
  :check "d1.innerHTML.should.equal(\"aaa\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click repeat 3 times  put \\\"a\\\" at end of me end\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (assert= (dom-inner-html _el-div) \"aaa\")
  ))")
(~hyperscript/hs-test-card
  :name "times loop with expression works"
  :html "<div _='on click repeat 3 + 3 times                                    put \"a\" at end of me                                  end'></div>"
  :action "d1.click()"
  :check "d1.innerHTML.should.equal(\"aaaaaa\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click repeat 3 + 3 times  put \\\"a\\\" at end of me end\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (assert= (dom-inner-html _el-div) \"aaaaaa\")
  ))")
(~hyperscript/hs-test-card
  :name "loop continue works"
  :html "<div _=\"on click
				repeat 2 times
					for x in ['A', 'B', 'C', 'D']
						if (x != 'D') then
							put 'success ' + x  + '. ' at end of me
							continue
							put 'FAIL!!. ' at end of me
						end
						put 'expected D. ' at end of me
					end
				end
			\"></div>"
  :action "d1.click()"
  :check "d1.innerHTML.should.equal(\"success A. success B. success C. expected D. success A. success B. success C. expected D. \")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click  repeat 2 times  for x in ['A', 'B', 'C', 'D']  if (x != 'D') then put 'success ' + x + '. ' at end of me then continue then put 'FAIL!!. ' at end of me then end  put 'expected D. ' at end of me then end  end\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (assert= (dom-inner-html _el-div) \"success A. success B. success C. expected D. success A. success B. success C. expected D. \")
  ))")
(~hyperscript/hs-test-card
  :name "loop break works"
  :html "<div _=\"on click
				repeat 2 times
					for x in ['A', 'B', 'C', 'D']
						if x is 'C'
						  break
						end
						put x at end of me
					end
				end
			\"></div>"
  :action "d1.click()"
  :check "d1.innerHTML.should.equal(\"ABAB\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click  repeat 2 times  for x in ['A', 'B', 'C', 'D']  if x is 'C' then break then end  put x at end of me then end  end\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (assert= (dom-inner-html _el-div) \"ABAB\")
  ))")
(~hyperscript/hs-test-card
  :name "basic raw for loop with null works"
  :html "<div _='on click for x in null                                    put x at end of me                                  end'></div>"
  :action "find('div').dispatchEvent('click')"
  :check "toHaveText(\"\")"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "basic property for loop works"
  :html "<div _='on click set x to {foo:1, bar:2, baz:3}                 for prop in x                    put x[prop] at end of me                 end'></div>"
  :action "find('div').dispatchEvent('click')"
  :check "toHaveText(\"123\")"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "bottom-tested repeat until"
  :html "<div _='on click set x to 0                  repeat                    set x to                  until x is 3 end                  put x into me'></div>"
  :action "find('div').dispatchEvent('click')"
  :check "toHaveText(\"3\")"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "bottom-tested repeat while"
  :html "<div _='on click set x to 0                  repeat                    set x to                  while x < 3 end                  put x into me'></div>"
  :action "find('div').dispatchEvent('click')"
  :check "toHaveText(\"3\")"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "bottom-tested loop always runs at least once"
  :html "<div _='on click set x to 0                  repeat                    set x to                  until true end                  put x into me'></div>"
  :action "find('div').dispatchEvent('click')"
  :check "toHaveText(\"1\")"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "break exits a simple repeat loop"
  :html "<div _=\"on click
				set x to 0
				repeat 10 times
					set x to x + 1
					if x is 3 break end
				end
				put x into me
			\"></div>"
  :action "find('div').dispatchEvent('click')"
  :check "toHaveText(\"3\")"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "continue skips rest of iteration in simple repeat loop"
  :html "<div _=\"on click
				repeat for x in [1, 2, 3, 4, 5]
					if x is 3 continue end
					put x at end of me
				end
			\"></div>"
  :action "find('div').dispatchEvent('click')"
  :check "toHaveText(\"1245\")"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "break exits a for-in loop"
  :html "<div _=\"on click
				repeat for x in [1, 2, 3, 4, 5]
					if x is 4 break end
					put x at end of me
				end
			\"></div>"
  :action "find('div').dispatchEvent('click')"
  :check "toHaveText(\"123\")"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "break exits a while loop"
  :html "<div _=\"on click
				set x to 0
				repeat while x < 100
					set x to x + 1
					if x is 5 break end
				end
				put x into me
			\"></div>"
  :action "find('div').dispatchEvent('click')"
  :check "toHaveText(\"5\")"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "for loop over undefined skips without error"
  :html "<div _='on click repeat for x in doesNotExist put x at end of me end then put \\\"done\\\" into me'></div>"
  :action "find('div').dispatchEvent('click')"
  :check "toHaveText(\"done\")"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))"))))
