summary refs log tree commit diff stats
path: root/tests/run
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-11-15 01:27:25 +0100
committerAraq <rumpf_a@web.de>2012-11-15 01:27:25 +0100
commit814fcb263939e8127eb89c379c448f481df14dbd (patch)
treeffbe247e03da9373caad8d1d079e21b314bf4cb1 /tests/run
parentc439010d5275e4f6c41573f2679a298e73d128cc (diff)
downloadNim-814fcb263939e8127eb89c379c448f481df14dbd.tar.gz
bugfix: stack traces; first class iterators almost working
Diffstat (limited to 'tests/run')
-rw-r--r--tests/run/titer8.nim33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/run/titer8.nim b/tests/run/titer8.nim
new file mode 100644
index 000000000..ae82c7d3c
--- /dev/null
+++ b/tests/run/titer8.nim
@@ -0,0 +1,33 @@
+discard """
+  output: '''tada
+ta da'''
+"""
+# Test first class iterator:
+
+import strutils
+
+iterator tokenize2(s: string, seps: set[char] = Whitespace): tuple[
+  token: string, isSep: bool] {.closure.} =
+  var i = 0
+  while i < s.len:
+    var j = i
+    if s[j] in seps:
+      while j < s.len and s[j] in seps: inc(j)
+      if j > i:
+        yield (substr(s, i, j-1), true)
+    else:
+      while j < s.len and s[j] notin seps: inc(j)
+      if j > i:
+        yield (substr(s, i, j-1), false)
+    i = j
+
+for word, isSep in tokenize2("ta da", whiteSpace):
+  if not isSep:
+    stdout.write(word)
+echo ""
+
+proc inProc() =
+  for word, isSep in tokenize2("ta da", whiteSpace):
+    stdout.write(word)
+
+inProc()