summary refs log tree commit diff stats
path: root/tests/stdlib/tstrscans.nim
diff options
context:
space:
mode:
authorMiran <narimiran@disroot.org>2020-12-03 17:34:30 +0100
committerGitHub <noreply@github.com>2020-12-03 17:34:30 +0100
commit2220aaeaef74cb6018f4689af8f280db22cb30dd (patch)
treede6d959299fff78f435a082f4ce3c0b3a5e2a6b5 /tests/stdlib/tstrscans.nim
parent545c406cbeb9d312e29f7363727c0eb9b37b7da7 (diff)
downloadNim-2220aaeaef74cb6018f4689af8f280db22cb30dd.tar.gz
add support for parsing chars in `scanf` macro (#16240)
Diffstat (limited to 'tests/stdlib/tstrscans.nim')
-rw-r--r--tests/stdlib/tstrscans.nim19
1 files changed, 18 insertions, 1 deletions
diff --git a/tests/stdlib/tstrscans.nim b/tests/stdlib/tstrscans.nim
index 9d6f51025..8ca167837 100644
--- a/tests/stdlib/tstrscans.nim
+++ b/tests/stdlib/tstrscans.nim
@@ -2,7 +2,7 @@ discard """
   output: ""
 """
 
-import strscans
+import strscans, strutils
 
 block ParsePasswd:
   proc parsePasswd(content: string): seq[string] =
@@ -210,3 +210,20 @@ block:
   var a: int
   discard scanf(test(), ",$i", a)
   doAssert count == 1
+
+
+block:
+  let input = """1-3 s: abc
+15-18 9: def
+15-18 A: ghi
+15-18 _: jkl
+"""
+  var
+    lo, hi: int
+    w: string
+    c: char
+    res: int
+  for line in input.splitLines:
+    if line.scanf("$i-$i $c: $w", lo, hi, c, w):
+      inc res
+  doAssert res == 4