diff options
Diffstat (limited to 'tests/template')
-rw-r--r-- | tests/template/annotate.nim | 2 | ||||
-rw-r--r-- | tests/template/mtempl5.nim | 6 | ||||
-rw-r--r-- | tests/template/otests.nim | 438 | ||||
-rw-r--r-- | tests/template/thygienictempl.nim | 4 | ||||
-rw-r--r-- | tests/template/tmodulealias.nim | 4 | ||||
-rw-r--r-- | tests/template/tstempl.nim | 2 | ||||
-rw-r--r-- | tests/template/ttempl.nim | 4 | ||||
-rw-r--r-- | tests/template/ttempl3.nim | 12 | ||||
-rw-r--r-- | tests/template/twrongopensymchoice.nim | 6 |
9 files changed, 239 insertions, 239 deletions
diff --git a/tests/template/annotate.nim b/tests/template/annotate.nim index fa58030dc..5f395557b 100644 --- a/tests/template/annotate.nim +++ b/tests/template/annotate.nim @@ -110,4 +110,4 @@ when isMainModule: echo styles echo body echo info - echo shader \ No newline at end of file + echo shader diff --git a/tests/template/mtempl5.nim b/tests/template/mtempl5.nim index 51e8461b8..3c2881764 100644 --- a/tests/template/mtempl5.nim +++ b/tests/template/mtempl5.nim @@ -1,10 +1,10 @@ -var +var gx = 88 gy = 44 - + template templ*(): int = bind gx, gy gx + gy - + diff --git a/tests/template/otests.nim b/tests/template/otests.nim index c885e23df..120146343 100644 --- a/tests/template/otests.nim +++ b/tests/template/otests.nim @@ -1,219 +1,219 @@ -# Fields -const x = 5 - - -# Test substring -static: - assert "test".substring(3) == "t" - assert "test".substring(2,1) == "s" - assert "test".substring(3,2) == "t" - assert "test".substring(1,2) == "es" - - -# Various parsing tests -when true: - - block: #no_substitution - proc actual: string = tmpli html""" - <p>Test!</p> - """ - const expected = html""" - <p>Test!</p> - """ - doAssert actual() == expected - - block: #basic - proc actual: string = tmpli html""" - <p>Test $$x</p> - $x - """ - const expected = html""" - <p>Test $x</p> - 5 - """ - doAssert actual() == expected - - block: #expression - proc actual: string = tmpli html""" - <p>Test $$(x * 5)</p> - $(x * 5) - """ - const expected = html""" - <p>Test $(x * 5)</p> - 25 - """ - doAssert actual() == expected - - block: #escape - proc actual: string = tmpli js""" - [{ - "hello world" - }] - """ - const expected = js""" - [{ - "hello world" - }] - """ - doAssert actual() == expected - - block: #forIn - proc actual: string = tmpli html""" - <p>Test for</p> - <ul> - $for y in 0..2 { - <li>$y</li> - } - </ul> - """ - const expected = html""" - <p>Test for</p> - <ul> - <li>0</li> - <li>1</li> - <li>2</li> - </ul> - """ - doAssert actual() == expected - - block: #while - proc actual: string = tmpli html""" - <p>Test while/stmt</p> - <ul> - ${ var y = 0 } - $while y < 4 { - <li>$y</li> - ${ inc(y) } - } - </ul> - """ - const expected = html""" - <p>Test while/stmt</p> - <ul> - <li>0</li> - <li>1</li> - <li>2</li> - <li>3</li> - </ul> - """ - doAssert actual() == expected - - block: #ifElifElse - proc actual: string = tmpli html""" - <p>Test if/elif/else</p> - $if x == 8 { - <div>x is 8!</div> - } - $elif x == 7 { - <div>x is 7!</div> - } - $else { - <div>x is neither!</div> - } - """ - const expected = html""" - <p>Test if/elif/else</p> - <div>x is neither!</div> - """ - doAssert actual() == expected - - block: #multiLineStatements - proc actual: string = tmpli html""" - <p>Test multiline statements</p> - ${ - var x = 5 - var y = 7 - } - <span>$x</span><span>$y</span> - """ - const expected = html""" - <p>Test multiline statements</p> - <span>5</span><span>7</span> - """ - doAssert actual() == expected - - block: #caseOfElse - proc actual: string = tmpli html""" - <p>Test case</p> - $case x - $of 5 { - <div>x == 5</div> - } - $of 6 { - <div>x == 6</div> - } - $else {} - """ - const expected = html""" - <p>Test case</p> - <div>x == 5</div> - """ - doAssert actual() == expected - - - -when true: #embeddingTest - proc no_substitution: string = tmpli html""" - <h1>Template test!</h1> - """ - - # # Single variable substitution - proc substitution(who = "nobody"): string = tmpli html""" - <div id="greeting">hello $who!</div> - """ - - # Expression template - proc test_expression(nums: openarray[int] = []): string = - var i = 2 - tmpli html""" - $(no_substitution()) - $(substitution("Billy")) - <div id="age">Age: $($nums[i] & "!!")</div> - """ - - proc test_statements(nums: openarray[int] = []): string = - tmpli html""" - $(test_expression(nums)) - $if true { - <ul> - $for i in nums { - <li>$(i * 2)</li> - } - </ul> - } - """ - - var actual = test_statements([0,1,2]) - const expected = html""" - <h1>Template test!</h1> - <div id="greeting">hello Billy!</div> - <div id="age">Age: 2!!</div> - <ul> - <li>0</li> - <li>2</li> - <li>4</li> - </ul> - """ - doAssert actual == expected - - -when defined(future): - block: #tryCatch - proc actual: string = tmpli html""" - <p>Test try/catch</p> - <div> - $try { - <div>Lets try this!</div> - } - $except { - <div>Uh oh!</div> - } - </div> - """ - const expected = html""" - <p>Test try/catch</p> - <div> - <div>Lets try this!</div> - </div> - """ - doAssert actual() == expected \ No newline at end of file +# Fields +const x = 5 + + +# Test substring +static: + assert "test".substring(3) == "t" + assert "test".substring(2,1) == "s" + assert "test".substring(3,2) == "t" + assert "test".substring(1,2) == "es" + + +# Various parsing tests +when true: + + block: #no_substitution + proc actual: string = tmpli html""" + <p>Test!</p> + """ + const expected = html""" + <p>Test!</p> + """ + doAssert actual() == expected + + block: #basic + proc actual: string = tmpli html""" + <p>Test $$x</p> + $x + """ + const expected = html""" + <p>Test $x</p> + 5 + """ + doAssert actual() == expected + + block: #expression + proc actual: string = tmpli html""" + <p>Test $$(x * 5)</p> + $(x * 5) + """ + const expected = html""" + <p>Test $(x * 5)</p> + 25 + """ + doAssert actual() == expected + + block: #escape + proc actual: string = tmpli js""" + [{ + "hello world" + }] + """ + const expected = js""" + [{ + "hello world" + }] + """ + doAssert actual() == expected + + block: #forIn + proc actual: string = tmpli html""" + <p>Test for</p> + <ul> + $for y in 0..2 { + <li>$y</li> + } + </ul> + """ + const expected = html""" + <p>Test for</p> + <ul> + <li>0</li> + <li>1</li> + <li>2</li> + </ul> + """ + doAssert actual() == expected + + block: #while + proc actual: string = tmpli html""" + <p>Test while/stmt</p> + <ul> + ${ var y = 0 } + $while y < 4 { + <li>$y</li> + ${ inc(y) } + } + </ul> + """ + const expected = html""" + <p>Test while/stmt</p> + <ul> + <li>0</li> + <li>1</li> + <li>2</li> + <li>3</li> + </ul> + """ + doAssert actual() == expected + + block: #ifElifElse + proc actual: string = tmpli html""" + <p>Test if/elif/else</p> + $if x == 8 { + <div>x is 8!</div> + } + $elif x == 7 { + <div>x is 7!</div> + } + $else { + <div>x is neither!</div> + } + """ + const expected = html""" + <p>Test if/elif/else</p> + <div>x is neither!</div> + """ + doAssert actual() == expected + + block: #multiLineStatements + proc actual: string = tmpli html""" + <p>Test multiline statements</p> + ${ + var x = 5 + var y = 7 + } + <span>$x</span><span>$y</span> + """ + const expected = html""" + <p>Test multiline statements</p> + <span>5</span><span>7</span> + """ + doAssert actual() == expected + + block: #caseOfElse + proc actual: string = tmpli html""" + <p>Test case</p> + $case x + $of 5 { + <div>x == 5</div> + } + $of 6 { + <div>x == 6</div> + } + $else {} + """ + const expected = html""" + <p>Test case</p> + <div>x == 5</div> + """ + doAssert actual() == expected + + + +when true: #embeddingTest + proc no_substitution: string = tmpli html""" + <h1>Template test!</h1> + """ + + # # Single variable substitution + proc substitution(who = "nobody"): string = tmpli html""" + <div id="greeting">hello $who!</div> + """ + + # Expression template + proc test_expression(nums: openarray[int] = []): string = + var i = 2 + tmpli html""" + $(no_substitution()) + $(substitution("Billy")) + <div id="age">Age: $($nums[i] & "!!")</div> + """ + + proc test_statements(nums: openarray[int] = []): string = + tmpli html""" + $(test_expression(nums)) + $if true { + <ul> + $for i in nums { + <li>$(i * 2)</li> + } + </ul> + } + """ + + var actual = test_statements([0,1,2]) + const expected = html""" + <h1>Template test!</h1> + <div id="greeting">hello Billy!</div> + <div id="age">Age: 2!!</div> + <ul> + <li>0</li> + <li>2</li> + <li>4</li> + </ul> + """ + doAssert actual == expected + + +when defined(future): + block: #tryCatch + proc actual: string = tmpli html""" + <p>Test try/catch</p> + <div> + $try { + <div>Lets try this!</div> + } + $except { + <div>Uh oh!</div> + } + </div> + """ + const expected = html""" + <p>Test try/catch</p> + <div> + <div>Lets try this!</div> + </div> + """ + doAssert actual() == expected diff --git a/tests/template/thygienictempl.nim b/tests/template/thygienictempl.nim index 3cdbac40e..5e4f534f8 100644 --- a/tests/template/thygienictempl.nim +++ b/tests/template/thygienictempl.nim @@ -1,7 +1,7 @@ - + var e = "abc" - + raise newException(EIO, e & "ha!") template t() = echo(foo) diff --git a/tests/template/tmodulealias.nim b/tests/template/tmodulealias.nim index a7d155e51..6681379fb 100644 --- a/tests/template/tmodulealias.nim +++ b/tests/template/tmodulealias.nim @@ -8,10 +8,10 @@ else: import posix when defined(Windows): - template orig: expr = + template orig: expr = winlean else: - template orig: expr = + template orig: expr = posix proc socket(domain, typ, protocol: int): int = diff --git a/tests/template/tstempl.nim b/tests/template/tstempl.nim index f8e57abbb..649082041 100644 --- a/tests/template/tstempl.nim +++ b/tests/template/tstempl.nim @@ -6,7 +6,7 @@ levB''' # tstempl.nim import strutils -type +type TLev = enum levA, levB diff --git a/tests/template/ttempl.nim b/tests/template/ttempl.nim index 2c4785325..5f1341990 100644 --- a/tests/template/ttempl.nim +++ b/tests/template/ttempl.nim @@ -15,10 +15,10 @@ const var i = 0 -for item in items(tabs): +for item in items(tabs): var content = $i var file: TFile - if open(file, changeFileExt(item[1], "html"), fmWrite): + if open(file, changeFileExt(item[1], "html"), fmWrite): write(file, sunsetTemplate(current=item[1], ticker="", content=content, tabs=tabs)) close(file) diff --git a/tests/template/ttempl3.nim b/tests/template/ttempl3.nim index c5d78d414..56daf9fe6 100644 --- a/tests/template/ttempl3.nim +++ b/tests/template/ttempl3.nim @@ -11,18 +11,18 @@ template withOpenFile(f: expr, filename: string, mode: TFileMode, close(f) else: quit("cannot open for writing: " & filename) - + withOpenFile(txt, "ttempl3.txt", fmWrite): writeLine(txt, "line 1") txt.writeLine("line 2") - + var myVar: array[0..1, int] -# Test zero argument template: +# Test zero argument template: template ha: expr = myVar[0] - -ha = 1 + +ha = 1 echo(ha) @@ -37,7 +37,7 @@ template typedef(name: expr, typ: typeDesc) {.immediate, dirty.} = type `T name`* = typ `P name`* = ref `T name` - + typedef(myint, int) var x: PMyInt diff --git a/tests/template/twrongopensymchoice.nim b/tests/template/twrongopensymchoice.nim index 5a02a813c..360c92037 100644 --- a/tests/template/twrongopensymchoice.nim +++ b/tests/template/twrongopensymchoice.nim @@ -4,11 +4,11 @@ discard """ # bug #940 -type - Foo* = ref object +type + Foo* = ref object b*: int -proc new*(this: var Foo) = +proc new*(this: var Foo) = assert this != nil this.b = 10 |