summary refs log tree commit diff stats
path: root/tests/accept/run
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-04-01 15:07:16 +0200
committerAraq <rumpf_a@web.de>2011-04-01 15:07:16 +0200
commit4741e8f9a1d1148d58e129626952219e14ede255 (patch)
treedb2eca2249ccc3230dc6c0a7359986198cab4048 /tests/accept/run
parentdc669155e39007f1b584eef247dff90523f836bf (diff)
downloadNim-4741e8f9a1d1148d58e129626952219e14ede255.tar.gz
ugh, maybe broke git
Diffstat (limited to 'tests/accept/run')
-rw-r--r--tests/accept/run/tfielditerator.nim46
-rw-r--r--tests/accept/run/tkoeniglookup.nim17
2 files changed, 63 insertions, 0 deletions
diff --git a/tests/accept/run/tfielditerator.nim b/tests/accept/run/tfielditerator.nim
new file mode 100644
index 000000000..2919aab41
--- /dev/null
+++ b/tests/accept/run/tfielditerator.nim
@@ -0,0 +1,46 @@
+discard """
+  output: '''
+a char: true
+a char: false
+an int: 5
+an int: 6
+a string: abc
+false
+true
+true
+false
+true
+a: a
+b: b
+x: 5
+y: 6
+z: abc
+'''
+"""
+
+type
+  TMyTuple = tuple[a, b: char, x, y: int, z: string]
+
+proc p(x: char) = echo "a char: ", x <= 'a'
+proc p(x: int) = echo "an int: ", x
+proc p(x: string) = echo "a string: ", x
+
+var x: TMyTuple = ('a', 'b', 5, 6, "abc")
+var y: TMyTuple = ('A', 'b', 5, 9, "abc")
+
+for f in fields(x): 
+  p f
+
+for a, b in fields(x, y):
+  echo a == b
+
+for key, val in fieldPairs(x):
+  echo key, ": ", val
+
+assert x != y
+assert x == x
+assert(not (x < x))
+assert x <= x
+assert y < x
+assert y <= x
+
diff --git a/tests/accept/run/tkoeniglookup.nim b/tests/accept/run/tkoeniglookup.nim
new file mode 100644
index 000000000..07c5b46be
--- /dev/null
+++ b/tests/accept/run/tkoeniglookup.nim
@@ -0,0 +1,17 @@
+discard """
+  output: '''x: 0 y: 0'''
+"""
+
+proc ToString*[T](x: T): string = return $x
+
+
+type
+  TMyObj = object
+    x, y: int
+
+proc `$`*(a: TMyObj): bool = 
+  result = "x: " & a.x & " y: " & a.y
+
+var a: TMyObj
+echo toString(a)
+