Skip to content

Commit

Permalink
Merge pull request #9084 from lrytz/merge-2.12-to-2.13-jun-24
Browse files Browse the repository at this point in the history
Merge 2.12 to 2.13
  • Loading branch information
SethTisue committed Jun 24, 2020
2 parents d175aec + 223c359 commit d23424c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/library/scala/collection/Map.scala
Expand Up @@ -338,7 +338,7 @@ trait MapOps[K, +V, +CC[_, _] <: IterableOps[_, AnyConstr, _], +C]
case that: Iterable[(K, V1)] => that
case that => View.from(that)
}
mapFactory.from(new View.Concat(toIterable, thatIterable))
mapFactory.from(new View.Concat(thatIterable, toIterable))
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/junit/scala/collection/MapTest.scala
Expand Up @@ -42,7 +42,7 @@ class MapTest {
val m = ListMap(1 -> "one")
val mm = Map(2 -> "two") ++: m
assert(mm.isInstanceOf[ListMap[Int,String]])
assertEquals(mm.mkString("[", ", ", "]"), "[1 -> one, 2 -> two]")
assertEquals(mm.mkString("[", ", ", "]"), "[2 -> two, 1 -> one]")
}

@deprecated("Tests deprecated API", since="2.13")
Expand Down
31 changes: 30 additions & 1 deletion test/junit/scala/collection/immutable/HashMapTest.scala
@@ -1,5 +1,7 @@
package scala.collection.immutable

import java.util.Collections

import org.junit.Assert._
import org.junit.{Ignore, Test}
import org.junit.runner.RunWith
Expand Down Expand Up @@ -280,7 +282,7 @@ class HashMapTest extends AllocationTest{
"i" -> 9,
"j" -> 10
)
assertSame(nonEmpty2, nonAllocating(nonEmpty1 ++ nonEmpty2))
assertSame(nonEmpty1, nonAllocating(nonEmpty1 ++ nonEmpty2))
}

@Test
Expand Down Expand Up @@ -310,4 +312,31 @@ class HashMapTest extends AllocationTest{
val m3 = m2 ++ m1
assertEquals(1, m3.apply(2))
}

@Test
def retainLeft(): Unit = {
case class C(a: Int)(override val toString: String)
implicit val ordering: Ordering[C] = Ordering.by(_.a)
val c0l = C(0)("l")
val c0r = C(0)("r")
def assertIdenticalKeys(expected: Map[C, Unit], actual: Map[C, Unit]): Unit = {
val expected1, actual1 = Collections.newSetFromMap[C](new java.util.IdentityHashMap())
expected.keys.foreach(expected1.add)
actual.keys.foreach(actual1.add)
assertEquals(expected1, actual1)
}
assertIdenticalKeys(Map((c0l, ())), HashMap((c0l, ())).updated(c0r, ()))

def check(factory: Seq[(C, Unit)] => Map[C, Unit]): Unit = {
val c0LMap = factory(Seq((c0l, ())))
val c0RMap = factory(Seq((c0r, ())))
assertIdenticalKeys(Map((c0l, ())), HashMap((c0l, ())).++(c0RMap))
assertIdenticalKeys(Map((c0l, ())), HashMap.newBuilder[C, Unit].++=(HashMap((c0l, ()))).++=(c0RMap).result())
assertIdenticalKeys(Map((c0l, ())), HashMap((c0l, ())).++(c0RMap))
assertIdenticalKeys(Map((c0l, ())), c0LMap ++: HashMap((c0r, ())))
}
check(cs => HashMap(cs: _*)) // exercise special case for HashMap/HashMap
check(cs => TreeMap(cs: _*)) // exercise special case for HashMap/HasForEachEntry
check(cs => HashMap(cs: _*).withDefault(_ => ???)) // default cases
}
}
2 changes: 1 addition & 1 deletion test/junit/scala/collection/immutable/TreeMapTest.scala
Expand Up @@ -206,7 +206,7 @@ class TreeMapTest extends AllocationTest {
}

@Test
def unionAndIntersectRetainLeft(): Unit = {
def retainLeft(): Unit = {
case class C(a: Int)(override val toString: String)
implicit val ordering: Ordering[C] = Ordering.by(_.a)
val c0l = C(0)("l")
Expand Down
4 changes: 4 additions & 0 deletions test/junit/scala/collection/immutable/TreeSetTest.scala
Expand Up @@ -274,6 +274,10 @@ class TreeSetTest extends AllocationTest {
assertIdenticalElements(Set(c0l), TreeSet(c0l).union(HashSet(c0r)))
assertIdenticalElements(Set(c0l), TreeSet(c0l).union(TreeSet(c0r)))

assertIdenticalElements(Set(c0l), HashSet(c0l).+(c0r))
assertIdenticalElements(Set(c0l), TreeSet(c0l).+(c0r))
assertIdenticalElements(Set(c0l), TreeSet(c0l).+(c0r))

assertIdenticalElements(Set(c0l), HashSet(c0l).++(HashSet(c0r)))
assertIdenticalElements(Set(c0l), TreeSet(c0l).++(HashSet(c0r)))
assertIdenticalElements(Set(c0l), TreeSet(c0l).++(TreeSet(c0r)))
Expand Down

0 comments on commit d23424c

Please sign in to comment.