summary refs log tree commit diff stats
path: root/tests/misc/thallo.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/misc/thallo.nim')
-rw-r--r--tests/misc/thallo.nim87
1 files changed, 87 insertions, 0 deletions
diff --git a/tests/misc/thallo.nim b/tests/misc/thallo.nim
new file mode 100644
index 000000000..8dac56023
--- /dev/null
+++ b/tests/misc/thallo.nim
@@ -0,0 +1,87 @@
+discard """
+action: compile
+"""
+
+# noted this seems to be an old test file designed for manual testing.
+
+import
+  os, strutils, macros
+
+type
+  TMyEnum = enum
+    meA, meB, meC, meD
+
+when true:
+  {.hint: "this is the main file".}
+
+proc fac[T](x: T): T =
+  # test recursive generic procs
+  if x <= 1: return 1
+  else: return x.`*`(fac(x-1))
+
+macro macrotest(n: varargs[untyped]): untyped =
+  let n = callsite()
+  expectKind(n, nnkCall)
+  expectMinLen(n, 2)
+  result = newNimNode(nnkStmtList, n)
+  for i in 2..n.len-1:
+    result.add(newCall("write", n[1], n[i]))
+  result.add(newCall("writeLine", n[1], newStrLitNode("")))
+
+macro debug(n: untyped): untyped =
+  let n = callsite()
+  result = newNimNode(nnkStmtList, n)
+  for i in 1..n.len-1:
+    result.add(newCall("write", newIdentNode("stdout"), toStrLit(n[i])))
+    result.add(newCall("write", newIdentNode("stdout"), newStrLitNode(": ")))
+    result.add(newCall("writeLine", newIdentNode("stdout"), n[i]))
+
+macrotest(stdout, "finally", 4, 5, "variable", "argument lists")
+macrotest(stdout)
+
+#GC_disable()
+
+echo("This was compiled by Nim version " & system.NimVersion)
+writeLine(stdout, "Hello", " World", "!")
+
+echo(["a", "b", "c", "d"].len)
+for x in items(["What's", "your", "name", "?", ]):
+  echo(x)
+var `name` = readLine(stdin)
+echo("Hi " & thallo.name & "!\n")
+debug(name)
+
+var testseq: seq[string] = @[
+  "a", "b", "c", "d", "e"
+]
+echo(repr(testseq))
+
+var dummy = "hello"
+echo(substr(dummy, 2, 3))
+
+echo($meC)
+
+# test tuples:
+for x, y in items([(1, 2), (3, 4), (6, 1), (5, 2)]):
+  echo x
+  echo y
+
+proc simpleConst(): int = return 34
+
+# test constant evaluation:
+const
+  constEval3 = simpleConst()
+  constEval = "abc".contains('b')
+  constEval2 = fac(7)
+
+echo(constEval3)
+echo(constEval)
+echo(constEval2)
+echo(1.`+`(2))
+
+for i in 2..6:
+  for j in countdown(i+4, 2):
+    echo(fac(i * j))
+
+when true:
+  {.hint: "this is the main file".}