added missing tests
This commit is contained in:
parent
e254741541
commit
bfef392460
13 changed files with 211 additions and 0 deletions
9
tests/mbind3.nim
Executable file
9
tests/mbind3.nim
Executable file
|
|
@ -0,0 +1,9 @@
|
||||||
|
# Module A
|
||||||
|
var
|
||||||
|
lastId = 0
|
||||||
|
|
||||||
|
template genId*: expr =
|
||||||
|
inc(bind lastId)
|
||||||
|
lastId
|
||||||
|
|
||||||
|
|
||||||
9
tests/mbind4.nim
Executable file
9
tests/mbind4.nim
Executable file
|
|
@ -0,0 +1,9 @@
|
||||||
|
# Module A
|
||||||
|
var
|
||||||
|
lastId = 0
|
||||||
|
|
||||||
|
template genId*: expr =
|
||||||
|
inc(lastId)
|
||||||
|
lastId
|
||||||
|
|
||||||
|
|
||||||
28
tests/t99bott.nim
Executable file
28
tests/t99bott.nim
Executable file
|
|
@ -0,0 +1,28 @@
|
||||||
|
## 99 Bottles of Beer
|
||||||
|
## http://www.99-bottles-of-beer.net/
|
||||||
|
## Nimrod version
|
||||||
|
|
||||||
|
## Author: Philippe Lhoste <PhiLho(a)GMX.net> http://Phi.Lho.free.fr
|
||||||
|
# 2009-11-25
|
||||||
|
# Loosely based on my old Lua version... Updated to current official lyrics.
|
||||||
|
|
||||||
|
proc GetBottleNumber(n: int): string =
|
||||||
|
var bs: string
|
||||||
|
if n == 0:
|
||||||
|
bs = "No more bottles"
|
||||||
|
elif n == 1:
|
||||||
|
bs = "1 bottle"
|
||||||
|
else:
|
||||||
|
bs = $n & " bottles"
|
||||||
|
return bs & " of beer"
|
||||||
|
|
||||||
|
for bn in countdown(99, 1):
|
||||||
|
const cur = GetBottleNumber(bn) #ERROR_MSG constant expression expected
|
||||||
|
echo(cur, " on the wall, ", cur, ".")
|
||||||
|
echo("Take one down and pass it around, ", GetBottleNumber(bn-1),
|
||||||
|
" on the wall.\n")
|
||||||
|
|
||||||
|
echo "No more bottles of beer on the wall, no more bottles of beer."
|
||||||
|
echo "Go to the store and buy some more, 99 bottles of beer on the wall."
|
||||||
|
|
||||||
|
|
||||||
5
tests/tbind3.nim
Executable file
5
tests/tbind3.nim
Executable file
|
|
@ -0,0 +1,5 @@
|
||||||
|
# Module B
|
||||||
|
import mbind3
|
||||||
|
|
||||||
|
echo genId() #OUT 1
|
||||||
|
|
||||||
6
tests/tbind4.nim
Executable file
6
tests/tbind4.nim
Executable file
|
|
@ -0,0 +1,6 @@
|
||||||
|
# Module B
|
||||||
|
import mbind4
|
||||||
|
|
||||||
|
echo genId() #ERROR_MSG instantiation from here
|
||||||
|
|
||||||
|
|
||||||
26
tests/tconsteval.nim
Executable file
26
tests/tconsteval.nim
Executable file
|
|
@ -0,0 +1,26 @@
|
||||||
|
|
||||||
|
const
|
||||||
|
HelpText = """
|
||||||
|
+-----------------------------------------------------------------+
|
||||||
|
| Maintenance program for Nimrod |
|
||||||
|
| Version $1|
|
||||||
|
| (c) 2009 Andreas Rumpf |
|
||||||
|
+-----------------------------------------------------------------+
|
||||||
|
Compiled at: $2, $3
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
koch.py [options] command [options for command]
|
||||||
|
Options:
|
||||||
|
--force, -f, -B, -b forces rebuild
|
||||||
|
--help, -h shows this help and quits
|
||||||
|
Possible Commands:
|
||||||
|
boot [options] bootstraps with given command line options
|
||||||
|
clean cleans Nimrod project; removes generated files
|
||||||
|
web generates the website
|
||||||
|
csource [options] builds the C sources for installation
|
||||||
|
zip builds the installation ZIP package
|
||||||
|
inno builds the Inno Setup installer
|
||||||
|
""" % [NimrodVersion & repeatChar(44-len(NimrodVersion)),
|
||||||
|
CompileDate, CompileTime]
|
||||||
|
|
||||||
|
|
||||||
38
tests/tconvert.nim
Executable file
38
tests/tconvert.nim
Executable file
|
|
@ -0,0 +1,38 @@
|
||||||
|
import
|
||||||
|
Cairo
|
||||||
|
|
||||||
|
converter FloatConversion64(x: int): float64 = return toFloat(x)
|
||||||
|
converter FloatConversion32(x: int): float32 = return toFloat(x)
|
||||||
|
converter FloatConversionPlain(x: int): float = return toFloat(x)
|
||||||
|
|
||||||
|
const width = 500
|
||||||
|
const height = 500
|
||||||
|
const outFile = "CairoTest.png"
|
||||||
|
|
||||||
|
var surface = Cairo_ImageSurfaceCreate(CAIRO_FORMAT_RGB24, width, height)
|
||||||
|
var ç = Cairo_Create(surface)
|
||||||
|
|
||||||
|
ç.Cairo_SetSourceRGB(1, 1, 1)
|
||||||
|
ç.Cairo_Paint()
|
||||||
|
|
||||||
|
ç.Cairo_SetLineWidth(10)
|
||||||
|
ç.Cairo_SetLineCap(CAIRO_LINE_CAP_ROUND)
|
||||||
|
|
||||||
|
const count = 12
|
||||||
|
var winc = width / count
|
||||||
|
var hinc = width / count
|
||||||
|
for i in 1 .. count-1:
|
||||||
|
var amount = i / count
|
||||||
|
ç.Cairo_SetSourceRGB(0, 1 - amount, amount)
|
||||||
|
ç.Cairo_MoveTo(i * winc, hinc)
|
||||||
|
ç.Cairo_LineTo(width - i * winc, height - hinc)
|
||||||
|
ç.Cairo_Stroke()
|
||||||
|
|
||||||
|
ç.Cairo_SetSourceRGB(1 - amount, 0, amount)
|
||||||
|
ç.Cairo_MoveTo(winc, i * hinc)
|
||||||
|
ç.Cairo_LineTo(width - winc, height - i * hinc)
|
||||||
|
ç.Cairo_Stroke()
|
||||||
|
|
||||||
|
echo(surface.Cairo_SurfaceWriteToPNG(outFile))
|
||||||
|
surface.Cairo_SurfaceDestroy()
|
||||||
|
|
||||||
35
tests/tdumpast.nim
Executable file
35
tests/tdumpast.nim
Executable file
|
|
@ -0,0 +1,35 @@
|
||||||
|
# Dump the contents of a PNimrodNode
|
||||||
|
|
||||||
|
import macros
|
||||||
|
|
||||||
|
proc dumpit(n: PNimrodNode): string {.compileTime.} =
|
||||||
|
if n == nil: return "nil"
|
||||||
|
result = $n.kind
|
||||||
|
add(result, "(")
|
||||||
|
case n.kind
|
||||||
|
of nnkEmpty: nil # same as nil node in this representation
|
||||||
|
of nnkNilLit: add(result, "nil")
|
||||||
|
of nnkCharLit..nnkInt64Lit: add(result, $n.intVal)
|
||||||
|
of nnkFloatLit..nnkFloat64Lit: add(result, $n.floatVal)
|
||||||
|
of nnkStrLit..nnkTripleStrLit: add(result, $n.strVal)
|
||||||
|
of nnkIdent: add(result, $n.ident)
|
||||||
|
of nnkSym, nnkNone: assert false
|
||||||
|
else:
|
||||||
|
add(result, dumpit(n[0]))
|
||||||
|
for j in 1..n.len-1:
|
||||||
|
add(result, ", ")
|
||||||
|
add(result, dumpit(n[j]))
|
||||||
|
add(result, ")")
|
||||||
|
|
||||||
|
macro dumpAST(n: stmt): stmt =
|
||||||
|
# dump AST as a side-effect and return the inner node
|
||||||
|
echo dumpit(n)
|
||||||
|
result = n[1]
|
||||||
|
|
||||||
|
dumpAST:
|
||||||
|
proc add(x, y: int): int =
|
||||||
|
return x + y
|
||||||
|
|
||||||
|
proc sub(x, y: int): int = return x - y
|
||||||
|
|
||||||
|
|
||||||
10
tests/tenuminh.nim
Executable file
10
tests/tenuminh.nim
Executable file
|
|
@ -0,0 +1,10 @@
|
||||||
|
type
|
||||||
|
TCardPts = enum
|
||||||
|
North, West, South, East
|
||||||
|
|
||||||
|
TCardPts2 = enum of TCardPts
|
||||||
|
N, W, S, E
|
||||||
|
|
||||||
|
# If I do:
|
||||||
|
var y = W
|
||||||
|
echo($y & "=" & $ord(y)) #OUT W=5
|
||||||
10
tests/tfinally.nim
Executable file
10
tests/tfinally.nim
Executable file
|
|
@ -0,0 +1,10 @@
|
||||||
|
# Test return in try statement:
|
||||||
|
|
||||||
|
proc main: int =
|
||||||
|
try:
|
||||||
|
return 1
|
||||||
|
finally:
|
||||||
|
echo "came here"
|
||||||
|
|
||||||
|
echo main()
|
||||||
|
|
||||||
6
tests/thintoff.nim
Executable file
6
tests/thintoff.nim
Executable file
|
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
{.hint[XDeclaredButNotUsed]: off.}
|
||||||
|
var
|
||||||
|
x: int
|
||||||
|
|
||||||
|
echo x #OUT 0
|
||||||
10
tests/tnestprc.nim
Executable file
10
tests/tnestprc.nim
Executable file
|
|
@ -0,0 +1,10 @@
|
||||||
|
# Test nested procs without closures
|
||||||
|
|
||||||
|
proc Add3(x: int): int =
|
||||||
|
proc add(x, y: int): int {.noconv.} =
|
||||||
|
result = x + y
|
||||||
|
|
||||||
|
result = add(x, 3)
|
||||||
|
|
||||||
|
echo Add3(7) #OUT 10
|
||||||
|
|
||||||
19
tests/tquotewords.nim
Executable file
19
tests/tquotewords.nim
Executable file
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Test an idea I recently had:
|
||||||
|
|
||||||
|
import macros
|
||||||
|
|
||||||
|
macro quoteWords(n: expr): expr =
|
||||||
|
result = newNimNode(nnkBracket, n)
|
||||||
|
for i in 1..n.len-1:
|
||||||
|
expectKind(n[i], nnkIdent)
|
||||||
|
result.add(toStrLit(n[i]))
|
||||||
|
|
||||||
|
const
|
||||||
|
myWordList = quoteWords(this, an, example)
|
||||||
|
|
||||||
|
var s = ""
|
||||||
|
for w in items(myWordList):
|
||||||
|
s.add(w)
|
||||||
|
|
||||||
|
echo s #OUT thisanexample
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue