summary refs log tree commit diff stats
path: root/lib/pure/collections/tables.nim
diff options
context:
space:
mode:
authorflywind <xzsflywind@gmail.com>2021-06-03 12:09:04 +0800
committerGitHub <noreply@github.com>2021-06-02 21:09:04 -0700
commitbbce3d2da919bef2900e4061b9b8a99cb84fdf57 (patch)
tree357a528fe35e3ba96c4e528f502232a7ea51854a /lib/pure/collections/tables.nim
parentf27f3f65df0bab567cc416cd1332a502833bd12f (diff)
downloadNim-bbce3d2da919bef2900e4061b9b8a99cb84fdf57.tar.gz
[std/tables] remove unnecessary `do: ` (#18160)
Diffstat (limited to 'lib/pure/collections/tables.nim')
-rw-r--r--lib/pure/collections/tables.nim26
1 files changed, 16 insertions, 10 deletions
diff --git a/lib/pure/collections/tables.nim b/lib/pure/collections/tables.nim
index b71bb0845..d617e06e4 100644
--- a/lib/pure/collections/tables.nim
+++ b/lib/pure/collections/tables.nim
@@ -594,17 +594,17 @@ template withValue*[A, B](t: var Table[A, B], key: A, value, body: untyped) =
     let u = User(name: "Hello", uid: 99)
     t[1] = u
 
-    t.withValue(1, value) do:
+    t.withValue(1, value):
       # block is executed only if `key` in `t`
       value.name = "Nim"
       value.uid = 1314
 
-    t.withValue(2, value) do:
+    t.withValue(2, value):
       value.name = "No"
       value.uid = 521
 
-    doAssert t[1].name == "Nim"
-    doAssert t[1].uid == 1314
+    assert t[1].name == "Nim"
+    assert t[1].uid == 1314
 
   mixin rawGet
   var hc: Hash
@@ -629,16 +629,22 @@ template withValue*[A, B](t: var Table[A, B], key: A,
     let u = User(name: "Hello", uid: 99)
     t[1] = u
 
-    t.withValue(1, value) do:
+    t.withValue(1, value):
       # block is executed only if `key` in `t`
       value.name = "Nim"
       value.uid = 1314
-    # do:
-    #   # block is executed when `key` not in `t`
-    #   raise newException(KeyError, "Key not found")
 
-    doAssert t[1].name == "Nim"
-    doAssert t[1].uid == 1314
+    t.withValue(521, value):
+      doAssert false
+    do:
+      # block is executed when `key` not in `t`
+      t[1314] = User(name: "exist", uid: 521)
+
+    assert t[1].name == "Nim"
+    assert t[1].uid == 1314
+    assert t[1314].name == "exist"
+    assert t[1314].uid == 521
+
   mixin rawGet
   var hc: Hash
   var index = rawGet(t, key, hc)