Merge branch 'mget' of https://github.com/def-/Nim into def--mget

Conflicts:
	lib/pure/collections/critbits.nim
	lib/pure/collections/tables.nim
	lib/pure/xmltree.nim
	lib/system/sets.nim
	tests/collections/ttables.nim
	tests/collections/ttablesref.nim
This commit is contained in:
Araq 2015-10-13 00:22:27 +02:00
commit d8b0edc323
12 changed files with 279 additions and 66 deletions

View file

@ -24,4 +24,3 @@ var
"D": action4}.toTable
actionTable["C"]("arg")

View file

@ -60,8 +60,12 @@ block tableTest2:
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"))
assert "123" in t
assert("111" notin t)

View file

@ -60,8 +60,10 @@ block tableTest2:
t["123"] = 1.5 # test overwriting
assert t["123"] == 1.5
assert t["111"] == 0.0 # deleted
assert "123" in t
try:
echo t["111"] # deleted
except KeyError:
discard
assert(not hasKey(t, "111"))
assert "111" notin t

View file

@ -18,7 +18,7 @@ proc on*(emitter: var EventEmitter, event: string,
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,
@ -30,4 +30,3 @@ var
initEmitter(ee)
ee.on("print", proc(e: EventArgs) = echo("pie"))
ee.emit("print", args)

141
tests/stdlib/tmget.nim Normal file
View file

@ -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

View file

@ -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