summary refs log tree commit diff stats
path: root/tests/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'tests/stdlib')
-rw-r--r--tests/stdlib/tmget.nim141
-rw-r--r--tests/stdlib/tmitems.nim2
2 files changed, 142 insertions, 1 deletions
diff --git a/tests/stdlib/tmget.nim b/tests/stdlib/tmget.nim
new file mode 100644
index 000000000..5792b6282
--- /dev/null
+++ b/tests/stdlib/tmget.nim
@@ -0,0 +1,141 @@
+discard """
+  output: '''Can't access 6
+10
+11
+Can't access 6
+10
+11
+Can't access 6
+10
+11
+Can't access 6
+10
+11
+Can't access 6
+10
+11
+Can't access 6
+10
+11
+Can't access 6
+5
+Can't access 6
+10
+11
+Can't access 6
+10
+11'''
+"""
+
+import tables
+
+block:
+  var x = initTable[int, int]()
+  x[5] = 10
+  try:
+    echo x[6]
+  except KeyError:
+    echo "Can't access 6"
+  echo x[5]
+  x[5] += 1
+  var c = x[5]
+  echo c
+
+block:
+  var x = newTable[int, int]()
+  x[5] = 10
+  try:
+    echo x[6]
+  except KeyError:
+    echo "Can't access 6"
+  echo x[5]
+  x[5] += 1
+  var c = x[5]
+  echo c
+
+block:
+  var x = initOrderedTable[int, int]()
+  x[5] = 10
+  try:
+    echo x[6]
+  except KeyError:
+    echo "Can't access 6"
+  echo x[5]
+  x[5] += 1
+  var c = x[5]
+  echo c
+
+block:
+  var x = newOrderedTable[int, int]()
+  x[5] = 10
+  try:
+    echo x[6]
+  except KeyError:
+    echo "Can't access 6"
+  echo x[5]
+  x[5] += 1
+  var c = x[5]
+  echo c
+
+block:
+  var x = initCountTable[int]()
+  x[5] = 10
+  try:
+    echo x[6]
+  except KeyError:
+    echo "Can't access 6"
+  echo x[5]
+  x[5] += 1
+  var c = x[5]
+  echo c
+
+block:
+  var x = newCountTable[int]()
+  x[5] = 10
+  try:
+    echo x[6]
+  except KeyError:
+    echo "Can't access 6"
+  echo x[5]
+  x[5] += 1
+  var c = x[5]
+  echo c
+
+import sets
+
+block:
+  var x = initSet[int]()
+  x.incl 5
+  try:
+    echo x[6]
+  except KeyError:
+    echo "Can't access 6"
+  echo x[5]
+
+import critbits
+
+block:
+  var x: CritBitTree[int]
+  x["5"] = 10
+  try:
+    echo x["6"]
+  except KeyError:
+    echo "Can't access 6"
+  echo x["5"]
+  x["5"] += 1
+  var c = x["5"]
+  echo c
+
+import strtabs
+
+block:
+  var x = newStringTable()
+  x["5"] = "10"
+  try:
+    echo x["6"]
+  except KeyError:
+    echo "Can't access 6"
+  echo x["5"]
+  x["5"][1] = '1'
+  var c = x["5"]
+  echo c
diff --git a/tests/stdlib/tmitems.nim b/tests/stdlib/tmitems.nim
index 2c0a0392a..f2307aeb3 100644
--- a/tests/stdlib/tmitems.nim
+++ b/tests/stdlib/tmitems.nim
@@ -132,5 +132,5 @@ block:
   </Students>""")
   for x in d.mitems:
     x = <>Student(Name=x.attrs["Name"] & "foo")
-  d.mget(1).attrs["Name"] = "bar"
+  d[1].attrs["Name"] = "bar"
   echo d