Fixed == for PTables, added test.
This commit is contained in:
parent
ac3f872fa3
commit
f59ca2736d
2 changed files with 14 additions and 2 deletions
|
|
@ -246,7 +246,8 @@ template equalsImpl() =
|
||||||
# different insertion orders mean different 'data' seqs, so we have
|
# different insertion orders mean different 'data' seqs, so we have
|
||||||
# to use the slow route here:
|
# to use the slow route here:
|
||||||
for key, val in s:
|
for key, val in s:
|
||||||
if not hasKey(t, key): return false
|
# prefix notation leads to automatic dereference in case of PTable
|
||||||
|
if not t.hasKey(key): return false
|
||||||
if t[key] != val: return false
|
if t[key] != val: return false
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
|
@ -332,7 +333,9 @@ proc `$`*[A, B](t: PTable[A, B]): string =
|
||||||
dollarImpl()
|
dollarImpl()
|
||||||
|
|
||||||
proc `==`*[A, B](s, t: PTable[A, B]): bool =
|
proc `==`*[A, B](s, t: PTable[A, B]): bool =
|
||||||
equalsImpl()
|
if isNil(s): result = isNil(t)
|
||||||
|
elif isNil(t): result = false
|
||||||
|
else: equalsImpl()
|
||||||
|
|
||||||
proc newTableFrom*[A, B, C](collection: A, index: proc(x: B): C): PTable[C, B] =
|
proc newTableFrom*[A, B, C](collection: A, index: proc(x: B): C): PTable[C, B] =
|
||||||
## Index the collection with the proc provided.
|
## Index the collection with the proc provided.
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,15 @@ block countTableTest1:
|
||||||
block SyntaxTest:
|
block SyntaxTest:
|
||||||
var x = newTable[int, string]({:})
|
var x = newTable[int, string]({:})
|
||||||
|
|
||||||
|
block nilTest:
|
||||||
|
var i, j: PTable[int, int] = nil
|
||||||
|
assert i == j
|
||||||
|
j = newTable[int, int]()
|
||||||
|
assert i != j
|
||||||
|
assert j != i
|
||||||
|
i = newTable[int, int]()
|
||||||
|
assert i == j
|
||||||
|
|
||||||
proc orderedTableSortTest() =
|
proc orderedTableSortTest() =
|
||||||
var t = newOrderedTable[string, int](2)
|
var t = newOrderedTable[string, int](2)
|
||||||
for key, val in items(data): t[key] = val
|
for key, val in items(data): t[key] = val
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue