Skip to content

Commit

Permalink
Scala 2.13.0-M4
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Jul 27, 2018
1 parent 245a3fb commit 5da8594
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ scala:
- 2.10.7
- 2.11.12
- 2.12.6
- 2.13.0-M3
- 2.13.0-M4
script:
- sbt "++ ${TRAVIS_SCALA_VERSION}!" test mimaReportBinaryIssues
jdk:
Expand Down
16 changes: 4 additions & 12 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,16 @@ scalacOptions ++= Seq("-feature", "-language:_", "-unchecked", "-deprecation", "

resolvers += Opts.resolver.sonatypeReleases

libraryDependencies ++=
(CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, n)) if n >= 13 =>
Seq("org.scala-lang.modules" %% "scala-parallel-collections" % "0.1.2")
case _ =>
Nil
})

libraryDependencies ++= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 10)) => Seq(
"org.specs2" %% "specs2-core" % "3.8.9" % "test",
"org.specs2" %% "specs2-scalacheck" % "3.8.9" % "test",
"org.scalacheck" %% "scalacheck" % "1.13.4" % "test"
)
case Some((2, n)) if n >= 11 => Seq(
"org.specs2" %% "specs2-core" % "4.0.2" % "test",
"org.specs2" %% "specs2-scalacheck" % "4.0.2" % "test",
"org.scalacheck" %% "scalacheck" % "1.13.5" % "test"
"org.specs2" %% "specs2-core" % "4.3.2" % "test",
"org.specs2" %% "specs2-scalacheck" % "4.3.2" % "test",
"org.scalacheck" %% "scalacheck" % "1.14.0" % "test"
)
case _ => Nil
})
Expand Down Expand Up @@ -77,7 +69,7 @@ mimaBinaryIssueFilters := Seq(
// publishing
///////////////

crossScalaVersions := Seq("2.10.7", "2.11.12", "2.12.6", "2.13.0-M3")
crossScalaVersions := Seq("2.10.7", "2.11.12", "2.12.6", "2.13.0-M4")

scalaBinaryVersion := {
val sV = scalaVersion.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ trait ProductFormatsInstances { self: ProductFormats with StandardFormats =>
fields.sizeHint(1 * 2)
[#fields ++= productElement##2Field[P1](fieldName1, p, 0)#
]
JsObject(fields: _*)
JsObject(fields.toSeq: _*)
}
def read(value: JsValue) = {
[#val p1V = fromField[P1](value, fieldName1)#
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/spray/json/CollectionFormats.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ trait CollectionFormats {
implicit def listFormat[T :JsonFormat] = new RootJsonFormat[List[T]] {
def write(list: List[T]) = JsArray(list.map(_.toJson).toVector)
def read(value: JsValue): List[T] = value match {
case JsArray(elements) => elements.map(_.convertTo[T])(collection.breakOut)
case JsArray(elements) => elements.toIterator.map(_.convertTo[T]).toList
case x => deserializationError("Expected List as JsArray, but got " + x)
}
}
Expand Down Expand Up @@ -59,7 +59,7 @@ trait CollectionFormats {
def read(value: JsValue) = value match {
case x: JsObject => x.fields.map { field =>
(JsString(field._1).convertTo[K], field._2.convertTo[V])
} (collection.breakOut)
}
case x => deserializationError("Expected Map as JsObject, but got " + x)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/spray/json/JsValue.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ sealed abstract class JsValue {
*/
case class JsObject(fields: Map[String, JsValue]) extends JsValue {
override def asJsObject(errorMsg: String) = this
def getFields(fieldNames: String*): immutable.Seq[JsValue] = fieldNames.flatMap(fields.get)(collection.breakOut)
def getFields(fieldNames: String*): immutable.Seq[JsValue] = fieldNames.toIterator.flatMap(fields.get).toList
}
object JsObject {
val empty = JsObject(Map.empty[String, JsValue])
Expand Down
14 changes: 12 additions & 2 deletions src/test/scala/spray/json/AdditionalFormatsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,18 @@ class AdditionalFormatsSpec extends Specification {
"The lazyFormat wrapper" should {
"enable recursive format definitions" in {
import FooProtocol._
Foo(1, "a", Some(Foo(2, "b", Some(Foo(3, "c") :: Nil)) :: Foo(4, "d") :: Nil)).toJson.toString mustEqual
"""{"id":1,"name":"a","foos":[{"id":2,"name":"b","foos":[{"id":3,"name":"c"}]},{"id":4,"name":"d"}]}"""
val json = Foo(1, "a", Some(Foo(2, "b", Some(Foo(3, "c") :: Nil)) :: Foo(4, "d") :: Nil)).toJson.toString

val v = scala.util.Properties.versionNumberString
// TODO this test depeneds on internal implementations of scala.Map
// https://github.com/scala/scala/commit/6a570b6f1f59222cae4f
if (v != "2.13.0-M4") {
json mustEqual
"""{"id":1,"name":"a","foos":[{"id":2,"name":"b","foos":[{"id":3,"name":"c"}]},{"id":4,"name":"d"}]}"""
} else {
json mustEqual
"""{"name":"a","foos":[{"name":"b","foos":[{"name":"c","id":3}],"id":2},{"name":"d","id":4}],"id":1}"""
}
}
}
}
7 changes: 6 additions & 1 deletion src/test/scala/spray/json/CollectionFormatsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ class CollectionFormatsSpec extends Specification with DefaultJsonProtocol {
val set = Set(1, 2, 3)
val json = JsArray(JsNumber(1), JsNumber(2), JsNumber(3))
"convert a Set[Int] to a JsArray of JsNumbers" in {
set.toJson mustEqual json
set.toJson match {
case JsArray(values) =>
values.toSet mustEqual json.elements.toSet
case other =>
sys.error(other.toString)
}
}
"convert a JsArray of JsNumbers to a Set[Int]" in {
json.convertTo[Set[Int]] mustEqual set
Expand Down
13 changes: 9 additions & 4 deletions src/test/scala/spray/json/JsonParserSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,16 @@ class JsonParserSpec extends Specification {
JsonParser(json.prettyPrint.getBytes("UTF-8")) === json
}
"be reentrant" in {
import scala.concurrent.{Await, Future}
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global

val largeJsonSource = scala.io.Source.fromInputStream(getClass.getResourceAsStream("/test.json")).mkString
import scala.collection.parallel.immutable.ParSeq
ParSeq.fill(20)(largeJsonSource).map(JsonParser(_)).toList.map {
_.asInstanceOf[JsObject].fields("questions").asInstanceOf[JsArray].elements.size
} === List.fill(20)(100)
val list = Await.result(
Future.traverse(List.fill(20)(largeJsonSource))(src => Future(JsonParser(src))),
5.seconds
).toList
list.map(_.asInstanceOf[JsObject].fields("questions").asInstanceOf[JsArray].elements.size) === List.fill(20)(100)
}

"produce proper error messages" in {
Expand Down
9 changes: 8 additions & 1 deletion src/test/scala/spray/json/ProductFormatsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,14 @@ class ProductFormatsSpec extends Specification {
import TestProtocol1._
val json = """{"ü$bavf$u56ú$":true,"=><+-*/!@#%^&~?|":1.0,"foo-bar!":42,"-x-":26,"User ID":"Karl"}"""
"produce the correct JSON" in {
TestMangled(42, "Karl", true, 26, 1.0f).toJson.compactPrint === json
val v = scala.util.Properties.versionNumberString
val value = TestMangled(42, "Karl", true, 26, 1.0f).toJson.compactPrint
// TODO this test depeneds on internal implementations of scala.Map
if (v.matches("2\\.1[012].*")) {
value === json
} else {
value === """{"ü$bavf$u56ú$":true,"=><+-*/!@#%^&~?|":1.0,"User ID":"Karl","foo-bar!":42,"-x-":26}"""
}
}
"convert a JsObject to the respective case class instance" in {
json.parseJson.convertTo[TestMangled] === TestMangled(42, "Karl", true, 26, 1.0f)
Expand Down

0 comments on commit 5da8594

Please sign in to comment.