summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authordef <dennis@felsin9.de>2015-03-31 00:04:31 +0200
committerdef <dennis@felsin9.de>2015-03-31 00:32:39 +0200
commit63f93853270d8b44ee42b34e5f52e3718b88d563 (patch)
tree06aaed9d55818872d87a93b47509bd1076369b15 /tests
parent3751019823ee78bd67b44cb27bc331913f12ff47 (diff)
downloadNim-63f93853270d8b44ee42b34e5f52e3718b88d563.tar.gz
Rename mget to `[]`
- In sets, tables, strtabs, critbits, xmltree
- This uses the new var parameter overloading
- mget variants still exist, but are deprecated in favor of `[]`
- Includes tests and fixed tests and usages of mget
- The non-var `[]` now throws an exception instead of returning binary 0
  or an empty string
Diffstat (limited to 'tests')
-rw-r--r--tests/actiontable/tactiontable.nim15
-rw-r--r--tests/collections/ttables.nim19
-rw-r--r--tests/collections/ttablesref.nim21
-rw-r--r--tests/misc/teventemitter.nim9
-rw-r--r--tests/stdlib/tmget.nim141
-rw-r--r--tests/stdlib/tmitems.nim2
6 files changed, 176 insertions, 31 deletions
diff --git a/tests/actiontable/tactiontable.nim b/tests/actiontable/tactiontable.nim
index e2f19a099..4560d0f7f 100644
--- a/tests/actiontable/tactiontable.nim
+++ b/tests/actiontable/tactiontable.nim
@@ -4,24 +4,23 @@ discard """
 
 import tables
 
-proc action1(arg: string) = 
+proc action1(arg: string) =
   echo "action 1 ", arg
 
-proc action2(arg: string) = 
+proc action2(arg: string) =
   echo "action 2 ", arg
 
-proc action3(arg: string) = 
+proc action3(arg: string) =
   echo "action 3 ", arg
 
-proc action4(arg: string) = 
+proc action4(arg: string) =
   echo "action 4 ", arg
 
 var
   actionTable = {
-    "A": action1, 
-    "B": action2, 
-    "C": action3, 
+    "A": action1,
+    "B": action2,
+    "C": action3,
     "D": action4}.toTable
 
 actionTable["C"]("arg")
-
diff --git a/tests/collections/ttables.nim b/tests/collections/ttables.nim
index 3a923610e..e4cff7c7e 100644
--- a/tests/collections/ttables.nim
+++ b/tests/collections/ttables.nim
@@ -22,15 +22,15 @@ const
     "---00": 346677844,
     "0": 34404,
     "1": 344004,
-    "10": 34484, 
+    "10": 34484,
     "11": 34474,
     "12": 789,
     "19": 34464,
-    "2": 344774, "20": 34454, 
+    "2": 344774, "20": 34454,
     "3": 342244, "30": 34141244,
     "34": 123456,
     "4": 3412344, "40": 344114,
-    "5": 341232144, "50": 344490, 
+    "5": 341232144, "50": 344490,
     "6": 34214544, "60": 344491,
     "7": 3434544, "70": 344492,
     "8": 344544, "80": 344497,
@@ -46,7 +46,7 @@ block tableTest1:
   for x in 0..1:
     for y in 0..1:
       assert t[(x,y)] == $x & $y
-  assert($t == 
+  assert($t ==
     "{(x: 0, y: 1): 01, (x: 0, y: 0): 00, (x: 1, y: 0): 10, (x: 1, y: 1): 11}")
 
 block tableTest2:
@@ -55,14 +55,17 @@ block tableTest2:
   t["111"] = 1.000043
   t["123"] = 1.23
   t.del("111")
-  
+
   t["012"] = 67.9
   t["123"] = 1.5 # test overwriting
-  
+
   assert t["123"] == 1.5
-  assert t["111"] == 0.0 # deleted
+  try:
+    echo t["111"] # deleted
+  except KeyError:
+    discard
   assert(not hasKey(t, "111"))
-  
+
   for key, val in items(data): t[key] = val.toFloat
   for key, val in items(data): assert t[key] == val.toFloat
 
diff --git a/tests/collections/ttablesref.nim b/tests/collections/ttablesref.nim
index 16b0d831e..92bc65da3 100644
--- a/tests/collections/ttablesref.nim
+++ b/tests/collections/ttablesref.nim
@@ -22,15 +22,15 @@ const
     "---00": 346677844,
     "0": 34404,
     "1": 344004,
-    "10": 34484, 
+    "10": 34484,
     "11": 34474,
     "12": 789,
     "19": 34464,
-    "2": 344774, "20": 34454, 
+    "2": 344774, "20": 34454,
     "3": 342244, "30": 34141244,
     "34": 123456,
     "4": 3412344, "40": 344114,
-    "5": 341232144, "50": 344490, 
+    "5": 341232144, "50": 344490,
     "6": 34214544, "60": 344491,
     "7": 3434544, "70": 344492,
     "8": 344544, "80": 344497,
@@ -46,7 +46,7 @@ block tableTest1:
   for x in 0..1:
     for y in 0..1:
       assert t[(x,y)] == $x & $y
-  assert($t == 
+  assert($t ==
     "{(x: 0, y: 1): 01, (x: 0, y: 0): 00, (x: 1, y: 0): 10, (x: 1, y: 1): 11}")
 
 block tableTest2:
@@ -55,17 +55,20 @@ block tableTest2:
   t["111"] = 1.000043
   t["123"] = 1.23
   t.del("111")
-  
+
   t["012"] = 67.9
   t["123"] = 1.5 # test overwriting
-  
+
   assert t["123"] == 1.5
-  assert t["111"] == 0.0 # deleted
+  try:
+    echo t["111"] # deleted
+  except KeyError:
+    discard
   assert(not hasKey(t, "111"))
-  
+
   for key, val in items(data): t[key] = val.toFloat
   for key, val in items(data): assert t[key] == val.toFloat
-  
+
 
 block orderedTableTest1:
   var t = newOrderedTable[string, int](2)
diff --git a/tests/misc/teventemitter.nim b/tests/misc/teventemitter.nim
index c1cc3d3a9..7da1a2522 100644
--- a/tests/misc/teventemitter.nim
+++ b/tests/misc/teventemitter.nim
@@ -13,21 +13,20 @@ proc emit*(emitter: EventEmitter, event: string, args: EventArgs) =
   for fn in nodes(emitter.events[event]):
     fn.value(args) #call function with args.
 
-proc on*(emitter: var EventEmitter, event: string, 
+proc on*(emitter: var EventEmitter, event: string,
          fn: proc(e: EventArgs) {.nimcall.}) =
   if not hasKey(emitter.events, event):
     var list: DoublyLinkedList[proc(e: EventArgs) {.nimcall.}]
     add(emitter.events, event, list) #if not, add it.
-  append(emitter.events.mget(event), fn)
+  append(emitter.events[event], fn)
 
 proc initEmitter(emitter: var EventEmitter) =
-  emitter.events = initTable[string, 
+  emitter.events = initTable[string,
     DoublyLinkedList[proc(e: EventArgs) {.nimcall.}]]()
 
-var 
+var
   ee: EventEmitter
   args: EventArgs
 initEmitter(ee)
 ee.on("print", proc(e: EventArgs) = echo("pie"))
 ee.emit("print", args)
-
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