fix Scala 2.12 / 3 version of LineNumberSpec (#165)

Fixes #163
This commit is contained in:
Johannes Rudolph 2023-02-10 16:52:24 +01:00 committed by GitHub
parent 8024c08c55
commit 5a8c0146f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 7 additions and 155 deletions

View file

@ -1,68 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* license agreements; and to You under the Apache License, version 2.0:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* This file is part of the Apache Pekko project, derived from Akka.
*/
/*
* Copyright (C) 2014-2022 Lightbend Inc. <https://www.lightbend.com>
*/
package org.apache.pekko.util
import org.apache.pekko
import pekko.testkit.PekkoSpec
import pekko.util.LineNumbers._
class LineNumberSpec extends PekkoSpec {
"LineNumbers" when {
"writing Scala" must {
import LineNumberSpecCodeForScala._
"work for small functions" in {
LineNumbers(oneline) should ===(SourceFileLines("LineNumberSpecCodeForScala.scala", 13, 13))
}
"work for larger functions" in {
val result = LineNumbers(twoline)
result should ===(SourceFileLines("LineNumberSpecCodeForScala.scala", 15, 15))
}
"work for partial functions" in {
LineNumbers(partial) should ===(SourceFileLines("LineNumberSpecCodeForScala.scala", 20, 22))
}
"work for `def`" in {
val result = LineNumbers(method("foo"))
result should ===(SourceFileLines("LineNumberSpecCodeForScala.scala", 26, 27))
}
}
"writing Java" must {
val l = new LineNumberSpecCodeForJava
"work for small functions" in {
// because how java Lambdas are implemented/designed
LineNumbers(l.f1()) should ===(SourceFileLines("LineNumberSpecCodeForJava.java", 20, 20))
}
"work for larger functions" in {
// because how java Lambdas are implemented/designed
LineNumbers(l.f2()) should ===(SourceFileLines("LineNumberSpecCodeForJava.java", 25, 26))
}
"work for anonymous classes" in {
LineNumbers(l.f3()) should ===(SourceFileLines("LineNumberSpecCodeForJava.java", 31, 36))
}
}
}
}

View file

@ -1,80 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* license agreements; and to You under the Apache License, version 2.0:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* This file is part of the Apache Pekko project, derived from Akka.
*/
/*
* Copyright (C) 2015-2022 Lightbend Inc. <https://www.lightbend.com>
*/
package org.apache.pekko.util
import org.scalactic.TypeCheckedTripleEquals
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
object TypedMultiMapSpec {
trait AbstractKey { type Type }
final case class Key[T](t: T) extends AbstractKey { final override type Type = T }
final case class MyValue[T](t: T)
type KV[K <: AbstractKey] = MyValue[K#Type]
}
class TypedMultiMapSpec extends AnyWordSpec with Matchers with TypeCheckedTripleEquals {
import TypedMultiMapSpec._
"A TypedMultiMap" must {
"retain and remove values for the same key" in {
val m1 = TypedMultiMap.empty[AbstractKey, KV]
val m2 = m1.inserted(Key(1))(MyValue(42))
m2.get(Key(1)) should ===(Set(MyValue(42)))
m2.removed(Key(1))(MyValue(42)).get(Key(1)) should ===(Set.empty[MyValue[Int]])
val m3 = m2.inserted(Key(1))(MyValue(43))
m3.get(Key(1)) should ===(Set(MyValue(42), MyValue(43)))
m3.removed(Key(1))(MyValue(42)).get(Key(1)) should ===(Set(MyValue(43)))
}
"retain and remove values for multiple keys" in {
val m1 = TypedMultiMap.empty[AbstractKey, KV]
val m2 = m1.inserted(Key(1))(MyValue(42)).inserted(Key(2))(MyValue(43))
m2.get(Key(1)) should ===(Set(MyValue(42)))
m2.removed(Key(1))(MyValue(42)).get(Key(1)) should ===(Set.empty[MyValue[Int]])
m2.get(Key(2)) should ===(Set(MyValue(43)))
m2.removed(Key(1))(MyValue(42)).get(Key(2)) should ===(Set(MyValue(43)))
}
"remove a value from all keys" in {
val m1 = TypedMultiMap.empty[AbstractKey, KV]
val m2 = m1.inserted(Key(1))(MyValue(42)).inserted(Key(2))(MyValue(43)).inserted(Key(2))(MyValue(42))
val m3 = m2.valueRemoved(MyValue(42))
m3.get(Key(1)) should ===(Set.empty[MyValue[Int]])
m3.get(Key(2)) should ===(Set(MyValue(43)))
m3.keySet should ===(Set[AbstractKey](Key(2)))
}
"remove all values from a key" in {
val m1 = TypedMultiMap.empty[AbstractKey, KV]
val m2 = m1.inserted(Key(1))(MyValue(42)).inserted(Key(2))(MyValue(43)).inserted(Key(2))(MyValue(42))
val m3 = m2.keyRemoved(Key(1))
m3.get(Key(1)) should ===(Set.empty[MyValue[Int]])
m3.get(Key(2)) should ===(Set(MyValue(42), MyValue(43)))
m3.keySet should ===(Set[AbstractKey](Key(2)))
}
"reject invalid insertions" in {
"TypedMultiMap.empty[AbstractKey, KV].inserted(Key(1))(MyValue(42L))" shouldNot compile
}
"reject invalid removals" in {
"TypedMultiMap.empty[AbstractKey, KV].removed(Key(1))(MyValue(42L))" shouldNot compile
}
}
}

View file

@ -25,21 +25,21 @@ class LineNumberSpec extends PekkoSpec {
import LineNumberSpecCodeForScala._
"work for small functions" in {
LineNumbers(oneline) should ===(SourceFileLines("LineNumberSpecCodeForScala.scala", 13, 13))
LineNumbers(oneline) should ===(SourceFileLines("LineNumberSpecCodeForScala.scala", 22, 22))
}
"work for larger functions" in {
val result = LineNumbers(twoline)
result should ===(SourceFileLines("LineNumberSpecCodeForScala.scala", 15, 17))
result should ===(SourceFileLines("LineNumberSpecCodeForScala.scala", 24, 26))
}
"work for partial functions" in {
LineNumbers(partial) should ===(SourceFileLines("LineNumberSpecCodeForScala.scala", 20, 22))
LineNumbers(partial) should ===(SourceFileLines("LineNumberSpecCodeForScala.scala", 29, 31))
}
"work for `def`" in {
val result = LineNumbers(method("foo"))
result should ===(SourceFileLines("LineNumberSpecCodeForScala.scala", 25, 27))
result should ===(SourceFileLines("LineNumberSpecCodeForScala.scala", 34, 36))
}
}
@ -49,16 +49,16 @@ class LineNumberSpec extends PekkoSpec {
"work for small functions" in {
// because how java Lambdas are implemented/designed
LineNumbers(l.f1()) should ===(SourceFileLines("LineNumberSpecCodeForJava.java", 20, 20))
LineNumbers(l.f1()) should ===(SourceFileLines("LineNumberSpecCodeForJava.java", 29, 29))
}
"work for larger functions" in {
// because how java Lambdas are implemented/designed
LineNumbers(l.f2()) should ===(SourceFileLines("LineNumberSpecCodeForJava.java", 25, 26))
LineNumbers(l.f2()) should ===(SourceFileLines("LineNumberSpecCodeForJava.java", 34, 35))
}
"work for anonymous classes" in {
LineNumbers(l.f3()) should ===(SourceFileLines("LineNumberSpecCodeForJava.java", 31, 36))
LineNumbers(l.f3()) should ===(SourceFileLines("LineNumberSpecCodeForJava.java", 40, 45))
}
}