diff --git a/tests/test1.nim b/tests/test1.nim index 8469903..5bec53c 100644 --- a/tests/test1.nim +++ b/tests/test1.nim @@ -32,7 +32,7 @@ proc toHtml(id, code: string): (Parser, HtmlCompiler) = result[0] = parseSnippet(id, code) result[1] = newCompiler(result[0].getAst, false) -test "language test var": +test "assignment var": const code = """ var a = 123 h1: $a @@ -42,7 +42,7 @@ var b = {} check x[0].hasErrors == false check x[1].hasErrors == false -test "language test const": +test "assignment const": let code = """ const x = 123 h1: $x @@ -97,6 +97,21 @@ for $fruit in $fruits: assert tim.toHtml("test_loops", code) == """satsumawatermelonorange""" +test "loops for + nested elements": + let code = """ +section#main > div.my-4 > ul.text-center + for $x in ["barberbeats", "vaporwave", "aesthetic"]: + li.d-block > span.fw-bold: $x""" + assert tim.toHtml("test_loops_nested", code) == + """
""" + +test "loops for in range": + let code = """ +for $i in 0..4: + i: $i""" + assert tim.toHtml("for_inrange", code) == + """01234""" + test "loops using * multiplier": let code = """ const items = ["keyboard", "speakers", "mug"] @@ -111,3 +126,34 @@ const items = ["keyboard", "speakers", "mug"] li * $x: $items[$i]""" assert tim.toHtml("test_multiplier", code) == """
  • keyboard
  • speakers
  • mug
  • """ + +test "loops while block + inc break": + let code = """ +var i = 0 +while true: + if $i == 100: + break + inc($i) +span: "Total: " & $i.toString""" + assert tim.toHtml("test_while_inc", code) == + """Total: 100""" + +test "loops while block + dec break": + let code = """ +var i = 100 +while true: + if $i == 0: + break + dec($i) +span: "Remained: " & $i.toString""" + assert tim.toHtml("test_while_dec", code) == + """Remained: 0""" + +test "loops while block + dec": + let code = """ +var i = 100 +while $i != 0: + dec($i) +span: "Remained: " & $i.toString""" + assert tim.toHtml("test_while_dec", code) == + """Remained: 0""" \ No newline at end of file