Skip to content

Commit

Permalink
Merge pull request #87 from xuwei-k/scala-native
Browse files Browse the repository at this point in the history
support scala-native
  • Loading branch information
johnynek authored Jul 9, 2018
2 parents 12fb20b + 3c0983a commit 0d041ce
Show file tree
Hide file tree
Showing 6 changed files with 363 additions and 355 deletions.
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ matrix:
env: PLATFORM="js"
script: sbt "++ ${TRAVIS_SCALA_VERSION}!" coreJS/test catsJS/test doc

- scala: 2.11.12
language: scala
jdk: oraclejdk8
env: PLATFORM="native"
sudo: required
before_install:
- curl https://raw.githubusercontent.com/scala-native/scala-native/d1b17c78b7e1a/scripts/travis_setup.sh | bash -
script: sbt "++ ${TRAVIS_SCALA_VERSION}!" coreNative/test

- scala: 2.12.6
language: scala
jdk: oraclejdk8
Expand Down
27 changes: 22 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ lazy val noPublish = Seq(
publishLocal := {},
publishArtifact := false)

val Scala211 = "2.11.12"

lazy val paigesSettings = Seq(
organization := "org.typelevel",
scalaVersion := "2.12.6",
crossScalaVersions := Seq("2.10.7", "2.11.12", "2.12.6"),
libraryDependencies ++= Seq(
"org.scalatest" %%% "scalatest" % "3.0.5" % Test,
"org.scalacheck" %%% "scalacheck" % "1.13.5" % Test),
crossScalaVersions := Seq("2.10.7", Scala211, "2.12.6"),
scalacOptions ++= Seq(
"-deprecation",
"-encoding", "UTF-8",
Expand Down Expand Up @@ -142,7 +141,7 @@ lazy val paigesJS = project
.dependsOn(coreJS, catsJS)
.enablePlugins(ScalaJSPlugin)

lazy val core = crossProject(JSPlatform, JVMPlatform).crossType(CrossType.Pure)
lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform).crossType(CrossType.Pure)
.in(file("core"))
.settings(name := "paiges-core")
.settings(moduleName := "paiges-core")
Expand All @@ -152,9 +151,27 @@ lazy val core = crossProject(JSPlatform, JVMPlatform).crossType(CrossType.Pure)
.jsSettings(commonJsSettings:_*)
.jsSettings(coverageEnabled := false)
.jvmSettings(commonJvmSettings:_*)
.platformsSettings(JVMPlatform, JSPlatform)(
libraryDependencies ++= Seq(
"org.scalatest" %%% "scalatest" % "3.0.5" % Test,
"org.scalacheck" %%% "scalacheck" % "1.13.5" % Test
)
)
.nativeSettings(
scalaVersion := Scala211,
crossScalaVersions := Seq(Scala211),
nativeLinkStubs := true,
sources in Test ~= {
_.filter(f => Set("JsonTest.scala", "PaigesTest.scala").contains(f.getName))
},
libraryDependencies ++= Seq(
"org.scalatest" %%% "scalatest" % "3.2.0-SNAP10" % Test
)
)

lazy val coreJVM = core.jvm
lazy val coreJS = core.js
lazy val coreNative = core.native

lazy val cats = crossProject(JSPlatform, JVMPlatform).crossType(CrossType.Pure)
.in(file("cats"))
Expand Down
42 changes: 6 additions & 36 deletions core/src/test/scala/org/typelevel/paiges/JsonTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ object Json {
case class JString(str: String) extends Json {
def toDoc = text("\"%s\"".format(escape(str)))
}
case class JNumber(toDouble: Double) extends Json {
case class JDouble(toDouble: Double) extends Json {
def toDoc = str(toDouble)
}
case class JInt(toInt: Int) extends Json {
def toDoc = str(toInt)
}
case class JBool(toBoolean: Boolean) extends Json {
def toDoc = str(toBoolean)
}
Expand Down Expand Up @@ -53,11 +56,10 @@ class JsonTest extends FunSuite {
import Json._

test("test nesteded array json example") {
val inner = JArray((1 to 20).map { i => JNumber(i.toDouble) }.toVector)
val inner = JArray((1 to 20).map { i => JInt(i) }.toVector)
val outer = JArray(Vector(inner, inner, inner))

if (1.0.toString == "1") {
assert(outer.toDoc.render(20) == """[
assert(outer.toDoc.render(20) == """[
[ 1, 2, 3, 4, 5,
6, 7, 8, 9, 10,
11, 12, 13, 14,
Expand All @@ -73,37 +75,5 @@ class JsonTest extends FunSuite {
11, 12, 13, 14,
15, 16, 17, 18,
19, 20 ] ]""")


} else {
assert(outer.toDoc.render(20) == """[
[ 1.0, 2.0, 3.0,
4.0, 5.0, 6.0,
7.0, 8.0, 9.0,
10.0, 11.0,
12.0, 13.0,
14.0, 15.0,
16.0, 17.0,
18.0, 19.0,
20.0 ],
[ 1.0, 2.0, 3.0,
4.0, 5.0, 6.0,
7.0, 8.0, 9.0,
10.0, 11.0,
12.0, 13.0,
14.0, 15.0,
16.0, 17.0,
18.0, 19.0,
20.0 ],
[ 1.0, 2.0, 3.0,
4.0, 5.0, 6.0,
7.0, 8.0, 9.0,
10.0, 11.0,
12.0, 13.0,
14.0, 15.0,
16.0, 17.0,
18.0, 19.0,
20.0 ] ]""")
}
}
}
Loading

0 comments on commit 0d041ce

Please sign in to comment.