Skip to content

Commit

Permalink
enable some Scala 3 tests (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k authored Mar 6, 2022
1 parent 51199bc commit 376b2b0
Show file tree
Hide file tree
Showing 32 changed files with 105 additions and 98 deletions.
16 changes: 5 additions & 11 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ lazy val root = project
description := "A Scala-friendly wrapper companion for Typesafe config",
startYear := Some(2013),
scalacOptions ++= Seq(
"-language:implicitConversions",
"-feature",
"-deprecation",
"-unchecked",
Expand Down Expand Up @@ -106,12 +107,12 @@ lazy val root = project
libraryDependencies ++=
(if (scalaVersion.value.startsWith("2.10"))
Seq("org.specs2" %% "specs2-core" % "3.10.0" % Test, "org.specs2" %% "specs2-scalacheck" % "3.10.0" % Test)
else
else if (Set("2.11", "2.12", "2.13").contains(scalaBinaryVersion.value))
Seq("org.specs2" %% "specs2-core" % "4.8.3" % Test, "org.specs2" %% "specs2-scalacheck" % "4.8.3" % Test)
.map(_ cross CrossVersion.for3Use2_13)) ++
else
Seq("org.specs2" %% "specs2-core" % "5.0.0" % Test, "org.specs2" %% "specs2-scalacheck" % "5.0.0" % Test)) ++
Seq(
"org.scalacheck" %% "scalacheck" % "1.14.1" % Test cross CrossVersion.for3Use2_13,
"com.typesafe" % "config" % "1.3.4"
"com.typesafe" % "config" % "1.3.4"
) ++
(if (Set("2.10", "2.11", "2.12").contains(scalaBinaryVersion.value))
Seq(
Expand All @@ -136,13 +137,6 @@ lazy val root = project
toPath != "application.conf"
}
},
Test / sources := {
if (scalaBinaryVersion.value == "3") {
Nil // TODO
} else {
(Test / sources).value
}
},
Publish.settings,
releaseCrossBuild := true,
mimaPreviousArtifacts :=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ class FicusConfigSpec extends Spec {
cfg.as[Boolean]("myValue") must beTrue
}

def readAValue = prop { b: Boolean =>
def readAValue = prop { (b: Boolean) =>
val cfg = ConfigFactory.parseString(s"myValue = $b")
cfg.as[Boolean]("myValue") must beEqualTo(b)
}

def getAsSome = prop { b: Boolean =>
def getAsSome = prop { (b: Boolean) =>
val cfg = ConfigFactory.parseString(s"myValue = $b")
cfg.getAs[Boolean]("myValue") must beSome(b)
}
Expand Down Expand Up @@ -60,7 +60,7 @@ class FicusConfigSpec extends Spec {
cfg.getOrElse("myValue", default) must beEqualTo(124.toByte)
}

def acceptAConfigKey = prop { b: Boolean =>
def acceptAConfigKey = prop { (b: Boolean) =>
val cfg = ConfigFactory.parseString(s"myValue = $b")
val key: ConfigKey[Boolean] = SimpleConfigKey("myValue")
cfg(key) must beEqualTo(b)
Expand Down
3 changes: 3 additions & 0 deletions src/test/scala-2/net/ceedubs/ficus/Scala3Compat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package net.ceedubs.ficus

trait Scala3Compat
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ArbitraryTypeReaderSpec extends Spec {

import ArbitraryTypeReaderSpec._

def instantiateSingleParamApply = prop { foo2: String =>
def instantiateSingleParamApply = prop { (foo2: String) =>
import Ficus.stringValueReader
import ArbitraryTypeReader._
val cfg = ConfigFactory.parseString(s"simple { foo2 = ${foo2.asConfigValue} }")
Expand All @@ -39,7 +39,7 @@ class ArbitraryTypeReaderSpec extends Spec {
instance.foo must_== foo2
}

def instantiateSingleParamApplyFromSelf = prop { foo2: String =>
def instantiateSingleParamApplyFromSelf = prop { (foo2: String) =>
import Ficus.stringValueReader
import ArbitraryTypeReader._
val cfg = ConfigFactory.parseString(s"simple { foo2 = ${foo2.asConfigValue} }")
Expand All @@ -48,7 +48,7 @@ class ArbitraryTypeReaderSpec extends Spec {
instance.foo must_== foo2
}

def instantiateSingleParamConstructor = prop { foo: String =>
def instantiateSingleParamConstructor = prop { (foo: String) =>
import Ficus.stringValueReader
import ArbitraryTypeReader._
val cfg = ConfigFactory.parseString(s"singleParam { foo = ${foo.asConfigValue} }")
Expand Down Expand Up @@ -80,7 +80,7 @@ class ArbitraryTypeReaderSpec extends Spec {
(instance.foo must_== foo) and (instance.bar must_== bar)
}

def multipleApply = prop { foo: String =>
def multipleApply = prop { (foo: String) =>
import Ficus.stringValueReader
import ArbitraryTypeReader._
val cfg = ConfigFactory.parseString(s"withMultipleApply { foo = ${foo.asConfigValue} }")
Expand All @@ -89,7 +89,7 @@ class ArbitraryTypeReaderSpec extends Spec {
instance.foo must_== foo
}

def multipleConstructors = prop { foo: String =>
def multipleConstructors = prop { (foo: String) =>
import Ficus.stringValueReader
import ArbitraryTypeReader._
val cfg = ConfigFactory.parseString(s"withMultipleConstructors { foo = ${foo.asConfigValue} }")
Expand Down Expand Up @@ -133,14 +133,14 @@ class ArbitraryTypeReaderSpec extends Spec {
arbitraryTypeValueReader[WithOption].value.read(cfg, "withOption").option must_== Some("here")
}

def ignoreApplyParamDefault = prop { foo: String =>
def ignoreApplyParamDefault = prop { (foo: String) =>
import Ficus.{optionValueReader, stringValueReader}
import ArbitraryTypeReader._
val cfg = ConfigFactory.parseString(s"withDefault { foo = ${foo.asConfigValue} }")
arbitraryTypeValueReader[WithDefault].value.read(cfg, "withDefault").foo must_== foo
}

def ignoreConstructorParamDefault = prop { foo: String =>
def ignoreConstructorParamDefault = prop { (foo: String) =>
import Ficus.{optionValueReader, stringValueReader}
import ArbitraryTypeReader._
val cfg = ConfigFactory.parseString(s"withDefault { foo = ${foo.asConfigValue} }")
Expand Down Expand Up @@ -172,7 +172,7 @@ class ArbitraryTypeReaderSpec extends Spec {
WithReaderInCompanion("from-companion") ==== cfg.as[WithReaderInCompanion]("withReaderInCompanion")
}

def useNameMapper = prop { foo: String =>
def useNameMapper = prop { (foo: String) =>
import Ficus.stringValueReader
import ArbitraryTypeReader._
implicit val nameMapper: NameMapper = new NameMapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ class CaseClassReadersSpec extends Spec {
cfg.as[SimpleCaseClass]("simple") must_== SimpleCaseClass(bool = false)
}

def hydrateSimpleCaseClass = prop { bool: Boolean =>
def hydrateSimpleCaseClass = prop { (bool: Boolean) =>
val cfg = ConfigFactory.parseString(s"simple { bool = $bool }")
cfg.as[SimpleCaseClass]("simple") must_== SimpleCaseClass(bool = bool)
}

def hydrateSimpleCaseClassFromSelf = prop { bool: Boolean =>
def hydrateSimpleCaseClassFromSelf = prop { (bool: Boolean) =>
val cfg = ConfigFactory.parseString(s"simple { bool = $bool }")
cfg.getConfig("simple").as[SimpleCaseClass] must_== SimpleCaseClass(bool = bool)
}
Expand All @@ -74,12 +74,12 @@ class CaseClassReadersSpec extends Spec {
cfg.as[MultipleFields]("multipleFields") must_== MultipleFields(string = foo, long = long)
}

def withOptionField = prop { s: String =>
def withOptionField = prop { (s: String) =>
val cfg = ConfigFactory.parseString(s"""withOption { option = ${s.asConfigValue} }""")
cfg.as[WithOption]("withOption") must_== WithOption(Some(s))
}

def withNestedCaseClass = prop { bool: Boolean =>
def withNestedCaseClass = prop { (bool: Boolean) =>
val cfg = ConfigFactory.parseString(s"""
|withNested {
| simple {
Expand All @@ -90,12 +90,12 @@ class CaseClassReadersSpec extends Spec {
cfg.as[WithNestedCaseClass]("withNested") must_== WithNestedCaseClass(simple = SimpleCaseClass(bool = bool))
}

def topLevelValueClass = prop { int: Int =>
def topLevelValueClass = prop { (int: Int) =>
val cfg = ConfigFactory.parseString(s"valueClass { int = $int }")
cfg.as[ValueClass]("valueClass") must_== ValueClass(int)
}

def nestedValueClass = prop { int: Int =>
def nestedValueClass = prop { (int: Int) =>
val cfg = ConfigFactory.parseString(s"""
|withNestedValueClass {
| valueClass = {
Expand All @@ -108,12 +108,12 @@ class CaseClassReadersSpec extends Spec {
)
}

def companionImplicitTopLevel = prop { int: Int =>
def companionImplicitTopLevel = prop { (int: Int) =>
val cfg = ConfigFactory.parseString(s"value = $int ")
cfg.as[CompanionImplicit]("value") must_== CompanionImplicit(int)
}

def nestedCompanionImplicit = prop { int: Int =>
def nestedCompanionImplicit = prop { (int: Int) =>
val cfg = ConfigFactory.parseString(s"""
|withNestedCompanionImplicit {
| value = $int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ConfigReaderSpec extends Spec {
implicitly read a ficus config itself $implicitlyReadFicusConfigFromSelf
"""

def readConfig = prop { i: Int =>
def readConfig = prop { (i: Int) =>
val cfg = ConfigFactory.parseString(s"""
|myConfig {
| myValue = $i
Expand All @@ -23,7 +23,7 @@ class ConfigReaderSpec extends Spec {
configValueReader.read(cfg, "myConfig").getInt("myValue") must beEqualTo(i)
}

def implicitlyReadConfig = prop { i: Int =>
def implicitlyReadConfig = prop { (i: Int) =>
val cfg = ConfigFactory.parseString(s"""
|myConfig {
| myValue = $i
Expand All @@ -32,7 +32,7 @@ class ConfigReaderSpec extends Spec {
cfg.as[Config]("myConfig").getInt("myValue") must beEqualTo(i)
}

def readFicusConfig = prop { i: Int =>
def readFicusConfig = prop { (i: Int) =>
val cfg = ConfigFactory.parseString(s"""
|myConfig {
| myValue = $i
Expand All @@ -41,7 +41,7 @@ class ConfigReaderSpec extends Spec {
ficusConfigValueReader.read(cfg, "myConfig").as[Int]("myValue") must beEqualTo(i)
}

def implicitlyReadFicusConfig = prop { i: Int =>
def implicitlyReadFicusConfig = prop { (i: Int) =>
val cfg = ConfigFactory.parseString(s"""
|myConfig {
| myValue = $i
Expand All @@ -50,7 +50,7 @@ class ConfigReaderSpec extends Spec {
cfg.as[FicusConfig]("myConfig").as[Int]("myValue") must beEqualTo(i)
}

def implicitlyReadFicusConfigFromSelf = prop { i: Int =>
def implicitlyReadFicusConfigFromSelf = prop { (i: Int) =>
val cfg = ConfigFactory.parseString(s"""
|myConfig {
| myValue = $i
Expand Down
9 changes: 9 additions & 0 deletions src/test/scala-3/net/ceedubs/ficus/Scala3Compat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.ceedubs.ficus

import org.specs2._

trait Scala3Compat extends Specification {
implicit final class MustEqualExtension[A](a1: A) {
def must_==(a2: A) = a1 must beEqualTo(a2)
}
}
14 changes: 8 additions & 6 deletions src/test/scala/net/ceedubs/ficus/ConfigSerializer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ object ConfigSerializer {
s"[${elements.mkString(", ")}]"
}

implicit val stringSerializer = apply[String](ConfigUtil.quoteString)
implicit val booleanSerializer = fromToString[Boolean]
implicit val intSerializer = fromToString[Int]
implicit val longSerializer = fromToString[Long]
implicit val doubleSerializer = fromToString[Double]
implicit val stringSerializer: ConfigSerializer[String] = apply[String](ConfigUtil.quoteString)
implicit val booleanSerializer: ConfigSerializer[Boolean] = fromToString[Boolean]
implicit val intSerializer: ConfigSerializer[Int] = fromToString[Int]
implicit val longSerializer: ConfigSerializer[Long] = fromToString[Long]
implicit val doubleSerializer: ConfigSerializer[Double] = fromToString[Double]

implicit def listSerializer[A: ConfigSerializer]: ConfigSerializer[List[A]] = apply[List[A]](serializeIterable)
implicit def serializerForSets[A: ConfigSerializer]: ConfigSerializer[Set[A]] = apply[Set[A]](serializeIterable)
Expand All @@ -36,7 +36,9 @@ object ConfigSerializer {
}
def iterableSerializer[A: ConfigSerializer]: ConfigSerializer[Iterable[A]] = apply[Iterable[A]](serializeIterable)

implicit def stringKeyMapSerializer[A](implicit valueSerializer: ConfigSerializer[A]) =
implicit def stringKeyMapSerializer[A](implicit
valueSerializer: ConfigSerializer[A]
): ConfigSerializer[Map[String, A]] =
new ConfigSerializer[Map[String, A]] {
def serialize(map: Map[String, A]): String = {
val lines = map.toIterable.map(
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/net/ceedubs/ficus/Spec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package net.ceedubs.ficus
import org.specs2.matcher.MustMatchers
import org.specs2.{ScalaCheck, Specification}

trait Spec extends Specification with MustMatchers with ScalaCheck
trait Spec extends Specification with MustMatchers with ScalaCheck with Scala3Compat
14 changes: 7 additions & 7 deletions src/test/scala/net/ceedubs/ficus/readers/AnyValReadersSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,39 @@ class AnyValReadersSpec extends Spec with AnyValReaders {
read an int as a double $readIntAsDouble
"""

def readBoolean = prop { b: Boolean =>
def readBoolean = prop { (b: Boolean) =>
val cfg = ConfigFactory.parseString(s"myValue = $b")
booleanValueReader.read(cfg, "myValue") must beEqualTo(b)
}

def readInt = prop { i: Int =>
def readInt = prop { (i: Int) =>
val cfg = ConfigFactory.parseString(s"myValue = $i")
intValueReader.read(cfg, "myValue") must beEqualTo(i)
}

def readDoubleAsInt = prop { d: Double =>
def readDoubleAsInt = prop { (d: Double) =>
(d >= Int.MinValue && d <= Int.MaxValue) ==> {
val cfg = ConfigFactory.parseString(s"myValue = $d")
intValueReader.read(cfg, "myValue") must beEqualTo(d.toInt)
}
}

def readLong = prop { l: Long =>
def readLong = prop { (l: Long) =>
val cfg = ConfigFactory.parseString(s"myValue = $l")
longValueReader.read(cfg, "myValue") must beEqualTo(l)
}

def readIntAsLong = prop { i: Int =>
def readIntAsLong = prop { (i: Int) =>
val cfg = ConfigFactory.parseString(s"myValue = $i")
longValueReader.read(cfg, "myValue") must beEqualTo(i.toLong)
}

def readDouble = prop { d: Double =>
def readDouble = prop { (d: Double) =>
val cfg = ConfigFactory.parseString(s"myValue = $d")
doubleValueReader.read(cfg, "myValue") must beEqualTo(d)
}

def readIntAsDouble = prop { i: Int =>
def readIntAsDouble = prop { (i: Int) =>
val cfg = ConfigFactory.parseString(s"myValue = $i")
doubleValueReader.read(cfg, "myValue") must beEqualTo(i.toDouble)
}
Expand Down
Loading

0 comments on commit 376b2b0

Please sign in to comment.