From eaf64fb2258785c91506f8d8113abaa17ecdc17f Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Tue, 29 Nov 2016 06:31:02 +0300 Subject: [PATCH] MapTest: Uncomment cases that pass now, add more cases. --- .../stdlib/jre8/test/collections/MapTest.kt | 51 ++++++++++++------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/libraries/stdlib/jre8/test/collections/MapTest.kt b/libraries/stdlib/jre8/test/collections/MapTest.kt index 47351319b94..7962136bd30 100644 --- a/libraries/stdlib/jre8/test/collections/MapTest.kt +++ b/libraries/stdlib/jre8/test/collections/MapTest.kt @@ -69,43 +69,56 @@ class MapTest { } @Test fun computeIfAbsent() { - val map = mutableMapOf(2 to "x", 3 to null) + val map = mutableMapOf(2 to "x") assertEquals("x", map.computeIfAbsent(2) { it.toString() }) assertEquals("3", map.computeIfAbsent(3) { it.toString() }) - assertEquals(null, map.computeIfAbsent(0) { null }) + // prohibited: map.computeIfAbsent(0) { null } + + val map2 = mutableMapOf(2 to "x", 3 to null) + assertEquals("x", map2.computeIfAbsent(2) { it.toString() }) + assertEquals("3", map2.computeIfAbsent(3) { it.toString() }) + assertEquals(null, map2.computeIfAbsent(0) { null }) + assertFalse(0 in map2) } @Test fun computeIfPresent() { val map = mutableMapOf(2 to "x") assertEquals("2x", map.computeIfPresent(2) { k, v -> k.toString() + v }) assertEquals(null, map.computeIfPresent(3) { k, v -> k.toString() + v }) - // fails due to KT-12144 - // assertEquals(null, map.computeIfPresent(2) { k, v -> null }) - // assertFalse(2 in map) + assertEquals(null, map.computeIfPresent(2) { k, v -> null }) + assertFalse(2 in map) + + val map2 = mutableMapOf(2 to "x") + assertEquals("2x", map2.computeIfPresent(2) { k, v -> k.toString() + v }) + assertEquals(null, map2.computeIfPresent(3) { k, v -> k.toString() + v }) + assertEquals(null, map2.computeIfPresent(2) { k, v -> null }) + assertFalse(2 in map2) } @Test fun compute() { val map = mutableMapOf(2 to "x") assertEquals("2x", map.compute(2) { k, v -> k.toString() + v }) - // fails due to KT-12144 - // assertEquals(null, map.compute(2) { k, v -> null }) - // assertFalse { 2 in map } + assertEquals(null, map.compute(2) { k, v -> null }) + assertFalse { 2 in map } assertEquals("1null", map.compute(1) { k, v -> k.toString() + v }) } @Test fun merge() { val map = mutableMapOf(2 to "x") - // fails due to KT-12144 -// assertEquals("y", map.merge(3, "y") { old, new -> null }) -// assertEquals(null, map.merge(3, "z") { old, new -> -// assertEquals("y", old) -// assertEquals("z", new) -// null -// }) - // assertFalse(3 in map) + assertEquals("y", map.merge(3, "y") { old, new -> null }) + assertEquals(null, map.merge(3, "z") { old, new -> + assertEquals("y", old) + assertEquals("z", new) + null + }) + assertFalse(3 in map) - val map2 = mutableMapOf(1 to null) - // new value must be V!! - assertFails { map2.merge(1, null) { k, v -> 2 } } + // fails due to KT-12144 + val map2 = mutableMapOf(1 to null) + // new value must be V&Any + assertEquals("e", map2.merge(1, "e") { old, new -> (old.length + new.length).toString() ?: null }) + assertEquals("3", map2.merge(1, "fg") { old, new -> (old.length + new.length).toString() ?: null }) + assertEquals(null, map2.merge(1, "3") { old, new -> null }) + assertFalse(1 in map) } } \ No newline at end of file