From bc3589d3ebab7735fbbb130fbb7c8ccb1146eef7 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Sun, 27 Sep 2015 18:52:23 -0700 Subject: SI-9492 REPL paste here doc Simple here documentish syntax for REPL paste. This makes it easier to paste a block of script (as opposed to transcript). It also means you won't accidentally ctl-D out of the REPL and then out of SBT and then out of the terminal window. ``` scala> :paste < EOF // Entering paste mode (EOF to finish) class C { def c = 42 } EOF // Exiting paste mode, now interpreting. defined class C scala> new C().c res0: Int = 42 scala> :paste <| EOF // Entering paste mode (EOF to finish) |class D { def d = 42 } EOF // Exiting paste mode, now interpreting. defined class D scala> new D().d res1: Int = 42 scala> :quit ``` --- test/files/run/repl-paste-5.check | 28 ++++++++++++++++++++++++++++ test/files/run/repl-paste-5.scala | 18 ++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 test/files/run/repl-paste-5.check create mode 100644 test/files/run/repl-paste-5.scala (limited to 'test') diff --git a/test/files/run/repl-paste-5.check b/test/files/run/repl-paste-5.check new file mode 100644 index 0000000000..8b97b8888d --- /dev/null +++ b/test/files/run/repl-paste-5.check @@ -0,0 +1,28 @@ + +scala> :paste < EOF +// Entering paste mode (EOF to finish) + +class C { def c = 42 } +EOF + +// Exiting paste mode, now interpreting. + +defined class C + +scala> new C().c +res0: Int = 42 + +scala> :paste <| EOF +// Entering paste mode (EOF to finish) + + |class D { def d = 42 } +EOF + +// Exiting paste mode, now interpreting. + +defined class D + +scala> new D().d +res1: Int = 42 + +scala> :quit diff --git a/test/files/run/repl-paste-5.scala b/test/files/run/repl-paste-5.scala new file mode 100644 index 0000000000..890f47f141 --- /dev/null +++ b/test/files/run/repl-paste-5.scala @@ -0,0 +1,18 @@ + +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + //def code = ":paste < EOF\n" + ( + def code = + """ +:paste < EOF +class C { def c = 42 } +EOF +new C().c +:paste <| EOF + |class D { def d = 42 } +EOF +new D().d + """ + //) +} -- cgit v1.2.3 From 1fb32fcf04386f52e72522bd688e69edafd95414 Mon Sep 17 00:00:00 2001 From: Performant Data LLC Date: Sat, 10 Oct 2015 00:02:25 -0700 Subject: SI-9513 decrement "deleted" count in OpenHashMap.put() when slot reused --- .../scala/collection/mutable/OpenHashMap.scala | 6 +++- .../scala/collection/mutable/OpenHashMapTest.scala | 42 ++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 test/junit/scala/collection/mutable/OpenHashMapTest.scala (limited to 'test') diff --git a/src/library/scala/collection/mutable/OpenHashMap.scala b/src/library/scala/collection/mutable/OpenHashMap.scala index 24f5761cf5..094f7eb63e 100644 --- a/src/library/scala/collection/mutable/OpenHashMap.scala +++ b/src/library/scala/collection/mutable/OpenHashMap.scala @@ -136,7 +136,11 @@ extends AbstractMap[Key, Value] None } else { val res = entry.value - if (entry.value == None) { size += 1; modCount += 1 } + if (entry.value == None) { + size += 1 + deleted -= 1 + modCount += 1 + } entry.value = Some(value) res } diff --git a/test/junit/scala/collection/mutable/OpenHashMapTest.scala b/test/junit/scala/collection/mutable/OpenHashMapTest.scala new file mode 100644 index 0000000000..5e72727183 --- /dev/null +++ b/test/junit/scala/collection/mutable/OpenHashMapTest.scala @@ -0,0 +1,42 @@ +package scala.collection.mutable + +import org.junit.Test +import org.junit.Assert._ +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +/** Tests for [[OpenHashMap]]. */ +@RunWith(classOf[JUnit4]) +class OpenHashMapTest { + /** Test that an [[OpenHashMap]] correctly maintains its internal `deleted` count. */ + @Test + def maintainsDeletedCount { + import scala.reflect.runtime.{universe => ru} + + val m = OpenHashMap.empty[Int, Int] + + // Reflect to get the private `deleted` field's value, which should be zero. + + /* TODO Doesn't work, due to SI-9306. + val mirror = ru.runtimeMirror(m.getClass.getClassLoader) + val mapType = ru.typeOf[OpenHashMap[Int, Int]] + val termSym = mapType.decls + .filterNot { s => s.isMethod } + .filter { s => s.fullName.endsWith("deleted") } + .head.asTerm + + val fieldMirror = mirror.reflect(m).reflectField(termSym) + */ + // Use Java reflection instead for now. + val field = m.getClass.getDeclaredField("scala$collection$mutable$OpenHashMap$$deleted") + field.setAccessible(true) + + m.put(0, 0) + m.remove(0) + assertEquals(1, field.getInt(m)) + + m.put(0, 0) // Add an entry with the same key + // TODO assertEquals(0, fieldMirror.get.asInstanceOf[Int]) + assertEquals(0, field.getInt(m)) + } +} -- cgit v1.2.3 From 9c97a7fbf67a9710b87b48e1020bb3c00a1f07a2 Mon Sep 17 00:00:00 2001 From: Performant Data LLC Date: Wed, 14 Oct 2015 21:17:42 -0700 Subject: Suppress unneeded import. --- test/junit/scala/collection/mutable/OpenHashMapTest.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/junit/scala/collection/mutable/OpenHashMapTest.scala b/test/junit/scala/collection/mutable/OpenHashMapTest.scala index 5e72727183..1459c14d78 100644 --- a/test/junit/scala/collection/mutable/OpenHashMapTest.scala +++ b/test/junit/scala/collection/mutable/OpenHashMapTest.scala @@ -11,13 +11,13 @@ class OpenHashMapTest { /** Test that an [[OpenHashMap]] correctly maintains its internal `deleted` count. */ @Test def maintainsDeletedCount { - import scala.reflect.runtime.{universe => ru} - val m = OpenHashMap.empty[Int, Int] // Reflect to get the private `deleted` field's value, which should be zero. /* TODO Doesn't work, due to SI-9306. + import scala.reflect.runtime.{universe => ru} + val mirror = ru.runtimeMirror(m.getClass.getClassLoader) val mapType = ru.typeOf[OpenHashMap[Int, Int]] val termSym = mapType.decls -- cgit v1.2.3