Skip to content

Commit 109c679

Browse files
committed
update
Signed-off-by: George Lemon <[email protected]>
1 parent c233955 commit 109c679

File tree

2 files changed

+57
-12
lines changed

2 files changed

+57
-12
lines changed

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
- '*.*.*'
66
env:
77
APP_NAME: 'tim'
8-
NIM_VERSION: 'stable'
8+
NIM_VERSION: '2.0.0'
99
MAINTAINER: 'OpenPeeps'
1010
jobs:
1111
build-artifact:

tests/test1.nim

+56-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import std/[unittest, htmlparser, xmltree, strtabs, sequtils]
1+
import std/[unittest, os, htmlparser, xmltree, strtabs, sequtils]
22
import ../src/tim
33

44
var t = newTim("./app/templates", "./app/storage",
@@ -32,6 +32,9 @@ proc toHtml(id, code: string): (Parser, HtmlCompiler) =
3232
result[0] = parseSnippet(id, code)
3333
result[1] = newCompiler(result[0].getAst, false)
3434

35+
proc load(x: string): string =
36+
readFile(currentSourcePath().parentDir / "snippets" / x & ".timl")
37+
3538
test "assignment var":
3639
const code = """
3740
var a = 123
@@ -42,13 +45,8 @@ var b = {}
4245
check x[0].hasErrors == false
4346
check x[1].hasErrors == false
4447

45-
test "assignment const":
46-
let code = """
47-
const x = 123
48-
h1: $x
49-
$x = 321
50-
"""
51-
let x = toHtml("test_var", code)
48+
test "invalid timl code":
49+
let x = toHtml("invalid", load("invalid"))
5250
check x[0].hasErrors == false
5351
check x[1].hasErrors == true
5452

@@ -84,9 +82,10 @@ if 1 != 1:
8482
elif 1 > 1:
8583
span.just-some-basic-stuff: "this is basic"
8684
else:
87-
span"""
85+
span.none
86+
"""
8887
assert tim.toHtml("test_if", code) ==
89-
"""<span></span>"""
88+
"""<span class="none"></span>"""
9089

9190
test "loops for":
9291
let code = """
@@ -156,4 +155,50 @@ while $i != 0:
156155
dec($i)
157156
span: "Remained: " & $i.toString"""
158157
assert tim.toHtml("test_while_dec", code) ==
159-
"""<span>Remained: 0</span>"""
158+
"""<span>Remained: 0</span>"""
159+
160+
test "function return string":
161+
let code = """
162+
fn hello(x: string): string =
163+
return $x
164+
h1: hello("Tim is awesome!")
165+
"""
166+
assert tim.toHtml("test_function", code) ==
167+
"""<h1>Tim is awesome!</h1>"""
168+
169+
test "function return int":
170+
let code = """
171+
fn hello(x: int): int =
172+
return $x + 10
173+
h1: hello(7)
174+
"""
175+
assert tim.toHtml("test_function", code) ==
176+
"""<h1>17</h1>"""
177+
178+
test "objects anonymous function":
179+
let code = """
180+
@import "std/strings"
181+
@import "std/os"
182+
183+
var x = {
184+
getHello:
185+
fn(x: string): string {
186+
return toUpper($x & " World")
187+
}
188+
}
189+
h1: $x.getHello("Hello")
190+
"""
191+
assert tim.toHtml("anonymous_function", code) ==
192+
"""<h1>HELLO WORLD</h1>"""
193+
194+
test "std/strings":
195+
let x = toHtml("std_strings", load("std_strings"))
196+
assert x[1].hasErrors == false
197+
198+
test "std/arrays":
199+
let x = toHtml("std_arrays", load("std_arrays"))
200+
assert x[1].hasErrors == false
201+
202+
test "std/objects":
203+
let x = toHtml("std_objects", load("std_objects"))
204+
assert x[1].hasErrors == false

0 commit comments

Comments
 (0)