diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6126349..b8a85ef 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,7 +5,7 @@ on: - '*.*.*' env: APP_NAME: 'tim' - NIM_VERSION: 'stable' + NIM_VERSION: '2.0.0' MAINTAINER: 'OpenPeeps' jobs: build-artifact: diff --git a/tests/test1.nim b/tests/test1.nim index 5bec53c..b5730d2 100644 --- a/tests/test1.nim +++ b/tests/test1.nim @@ -1,4 +1,4 @@ -import std/[unittest, htmlparser, xmltree, strtabs, sequtils] +import std/[unittest, os, htmlparser, xmltree, strtabs, sequtils] import ../src/tim var t = newTim("./app/templates", "./app/storage", @@ -32,6 +32,9 @@ proc toHtml(id, code: string): (Parser, HtmlCompiler) = result[0] = parseSnippet(id, code) result[1] = newCompiler(result[0].getAst, false) +proc load(x: string): string = + readFile(currentSourcePath().parentDir / "snippets" / x & ".timl") + test "assignment var": const code = """ var a = 123 @@ -42,13 +45,8 @@ var b = {} check x[0].hasErrors == false check x[1].hasErrors == false -test "assignment const": - let code = """ -const x = 123 -h1: $x -$x = 321 - """ - let x = toHtml("test_var", code) +test "invalid timl code": + let x = toHtml("invalid", load("invalid")) check x[0].hasErrors == false check x[1].hasErrors == true @@ -84,9 +82,10 @@ if 1 != 1: elif 1 > 1: span.just-some-basic-stuff: "this is basic" else: - span""" + span.none + """ assert tim.toHtml("test_if", code) == - """""" + """""" test "loops for": let code = """ @@ -156,4 +155,50 @@ while $i != 0: dec($i) span: "Remained: " & $i.toString""" assert tim.toHtml("test_while_dec", code) == - """Remained: 0""" \ No newline at end of file + """Remained: 0""" + +test "function return string": + let code = """ +fn hello(x: string): string = + return $x +h1: hello("Tim is awesome!") + """ + assert tim.toHtml("test_function", code) == + """

Tim is awesome!

""" + +test "function return int": + let code = """ +fn hello(x: int): int = + return $x + 10 +h1: hello(7) + """ + assert tim.toHtml("test_function", code) == + """

17

""" + +test "objects anonymous function": + let code = """ +@import "std/strings" +@import "std/os" + +var x = { + getHello: + fn(x: string): string { + return toUpper($x & " World") + } +} +h1: $x.getHello("Hello") + """ + assert tim.toHtml("anonymous_function", code) == + """

HELLO WORLD

""" + +test "std/strings": + let x = toHtml("std_strings", load("std_strings")) + assert x[1].hasErrors == false + +test "std/arrays": + let x = toHtml("std_arrays", load("std_arrays")) + assert x[1].hasErrors == false + +test "std/objects": + let x = toHtml("std_objects", load("std_objects")) + assert x[1].hasErrors == false \ No newline at end of file