diff options
author | Felix Krause <contact@flyx.org> | 2016-11-18 23:42:15 +0100 |
---|---|---|
committer | Felix Krause <contact@flyx.org> | 2016-11-18 23:42:15 +0100 |
commit | 93a998204c62ce473e125f059250f4a64a10ce0a (patch) | |
tree | 73e02805fac1c93d4262c8b83ddb1a310be71bf4 /tests | |
parent | 7c1b5b3c2ba0e76c55cd3ea34dd1ac5beea1af42 (diff) | |
download | Nim-93a998204c62ce473e125f059250f4a64a10ce0a.tar.gz |
Fixes #5035
Diffstat (limited to 'tests')
-rw-r--r-- | tests/collections/ttables.nim | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/tests/collections/ttables.nim b/tests/collections/ttables.nim index 4f286d0ed..ef5ed92f5 100644 --- a/tests/collections/ttables.nim +++ b/tests/collections/ttables.nim @@ -112,7 +112,7 @@ block orderedTableTest2: block countTableTest1: var s = data.toTable var t = initCountTable[string]() - + for k in s.keys: t.inc(k) for k in t.keys: assert t[k] == 1 t.inc("90", 3) @@ -167,6 +167,29 @@ block mpairsTableTest1: block SyntaxTest: var x = toTable[int, string]({:}) +block zeroHashKeysTest: + proc doZeroHashValueTest[T, K, V](t: T, nullHashKey: K, value: V) = + let initialLen = t.len + var testTable = t + testTable[nullHashKey] = value + assert testTable[nullHashKey] == value + assert testTable.len == initialLen + 1 + testTable.del(nullHashKey) + assert testTable.len == initialLen + + # with empty table + doZeroHashValueTest(toTable[int,int]({:}), 0, 42) + doZeroHashValueTest(toTable[string,int]({:}), "", 23) + doZeroHashValueTest(toOrderedTable[int,int]({:}), 0, 42) + doZeroHashValueTest(toOrderedTable[string,int]({:}), "", 23) + + # with non-empty table + doZeroHashValueTest(toTable[int,int]({1:2}), 0, 42) + doZeroHashValueTest(toTable[string,string]({"foo": "bar"}), "", "zero") + doZeroHashValueTest(toOrderedTable[int,int]({3:4}), 0, 42) + doZeroHashValueTest(toOrderedTable[string,string]({"egg": "sausage"}), + "", "spam") + # Until #4448 is fixed, these tests will fail when false: block clearTableTest: |