summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xtests/mbind3.nim9
-rwxr-xr-xtests/mbind4.nim9
-rwxr-xr-xtests/t99bott.nim28
-rwxr-xr-xtests/tbind3.nim5
-rwxr-xr-xtests/tbind4.nim6
-rwxr-xr-xtests/tconsteval.nim26
-rwxr-xr-xtests/tconvert.nim38
-rwxr-xr-xtests/tdumpast.nim35
-rwxr-xr-xtests/tenuminh.nim10
-rwxr-xr-xtests/tfinally.nim10
-rwxr-xr-xtests/thintoff.nim6
-rwxr-xr-xtests/tnestprc.nim10
-rwxr-xr-xtests/tquotewords.nim19
13 files changed, 211 insertions, 0 deletions
diff --git a/tests/mbind3.nim b/tests/mbind3.nim
new file mode 100755
index 000000000..586222eb8
--- /dev/null
+++ b/tests/mbind3.nim
@@ -0,0 +1,9 @@
+# Module A
+var 
+  lastId = 0
+
+template genId*: expr =
+  inc(bind lastId)
+  lastId
+
+
diff --git a/tests/mbind4.nim b/tests/mbind4.nim
new file mode 100755
index 000000000..53b8331cd
--- /dev/null
+++ b/tests/mbind4.nim
@@ -0,0 +1,9 @@
+# Module A
+var 
+  lastId = 0
+
+template genId*: expr =
+  inc(lastId)
+  lastId
+
+
diff --git a/tests/t99bott.nim b/tests/t99bott.nim
new file mode 100755
index 000000000..4dfb11701
--- /dev/null
+++ b/tests/t99bott.nim
@@ -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."
+
+
diff --git a/tests/tbind3.nim b/tests/tbind3.nim
new file mode 100755
index 000000000..f7fb4865b
--- /dev/null
+++ b/tests/tbind3.nim
@@ -0,0 +1,5 @@
+# Module B
+import mbind3
+
+echo genId() #OUT 1
+
diff --git a/tests/tbind4.nim b/tests/tbind4.nim
new file mode 100755
index 000000000..d0b5fc062
--- /dev/null
+++ b/tests/tbind4.nim
@@ -0,0 +1,6 @@
+# Module B
+import mbind4
+
+echo genId() #ERROR_MSG instantiation from here
+
+
diff --git a/tests/tconsteval.nim b/tests/tconsteval.nim
new file mode 100755
index 000000000..2bda0651d
--- /dev/null
+++ b/tests/tconsteval.nim
@@ -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]
+
+
diff --git a/tests/tconvert.nim b/tests/tconvert.nim
new file mode 100755
index 000000000..b23afde74
--- /dev/null
+++ b/tests/tconvert.nim
@@ -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()
+
diff --git a/tests/tdumpast.nim b/tests/tdumpast.nim
new file mode 100755
index 000000000..fb31af0ec
--- /dev/null
+++ b/tests/tdumpast.nim
@@ -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
+
+
diff --git a/tests/tenuminh.nim b/tests/tenuminh.nim
new file mode 100755
index 000000000..02c71613b
--- /dev/null
+++ b/tests/tenuminh.nim
@@ -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
diff --git a/tests/tfinally.nim b/tests/tfinally.nim
new file mode 100755
index 000000000..102444e82
--- /dev/null
+++ b/tests/tfinally.nim
@@ -0,0 +1,10 @@
+# Test return in try statement:
+
+proc main: int = 
+  try:
+    return 1
+  finally: 
+    echo "came here"
+    
+echo main()
+
diff --git a/tests/thintoff.nim b/tests/thintoff.nim
new file mode 100755
index 000000000..7aff283d6
--- /dev/null
+++ b/tests/thintoff.nim
@@ -0,0 +1,6 @@
+
+{.hint[XDeclaredButNotUsed]: off.}
+var
+  x: int
+  
+echo x #OUT 0
diff --git a/tests/tnestprc.nim b/tests/tnestprc.nim
new file mode 100755
index 000000000..b7326e032
--- /dev/null
+++ b/tests/tnestprc.nim
@@ -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
+
diff --git a/tests/tquotewords.nim b/tests/tquotewords.nim
new file mode 100755
index 000000000..462293b40
--- /dev/null
+++ b/tests/tquotewords.nim
@@ -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
+