Skip to content

Commit

Permalink
add more tests | fix debugEcho
Browse files Browse the repository at this point in the history
Signed-off-by: George Lemon <[email protected]>
  • Loading branch information
georgelemon committed Apr 20, 2024
1 parent 468b947 commit 2c7f338
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/tim/engine/ast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,9 @@ proc `$`*(x: Ast): string =
else:
toJson(x)

proc debugEcho*(node: Node) =
echo pretty(toJson(node), 2)
when not defined release:
proc debugEcho*(node: Node) =
echo pretty(toJson(node), 2)

#
# AST Generators
Expand Down
31 changes: 30 additions & 1 deletion tests/test1.nim
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,35 @@ test "check layout":
check meta[1].attrs.hasKey("name")
check meta[1].attrs.hasKey("content")


let title = html.findAll("title").toSeq
check title.len == 1
check title[0].innerText == "Tim Engine is Awesome!"
check title[0].innerText == "Tim Engine is Awesome!"

import std/sequtils
import ../src/tim/engine/[logging, parser, compilers/html]

proc toHtml(id, code: string): (Parser, HtmlCompiler) =
result[0] = parseSnippet(id, code)
result[1] = newCompiler(result[0].getAst, false)

test "language test var":
const code = """
var a = 123
h1: $a
var b = {}
"""
let x = toHtml("test_var", code)
check x[0].hasErrors == false
check x[1].hasErrors == false

test "language test const":
const code = """
const x = 123
h1: $x
$x = 321
"""
let x = toHtml("test_var", code)
check x[0].hasErrors == false
check x[1].hasErrors == true
# echo x[1].logger.errors.toSeq()
2 changes: 1 addition & 1 deletion tim.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
version = "0.1.2"
author = "OpenPeeps"
description = "A super fast template engine for cool kids!"
license = "MIT"
license = "LGPLv3"
srcDir = "src"
skipDirs = @["example", "editors", "bindings"]
installExt = @["nim"]
Expand Down

0 comments on commit 2c7f338

Please sign in to comment.