Skip to content
Permalink
Browse files

Merge pull request #199 from francisdb/scalanative

scalanative + utest - specs2
  • Loading branch information...
sirthias committed Mar 11, 2019
2 parents a8fd4c3 + bae49ff commit 809cfbd159b7b6858a4cdd8f7073e9bf01eeeac3
Showing with 2,603 additions and 2,176 deletions.
  1. +8 −2 .travis.yml
  2. +48 −13 build.sbt
  3. +20 −17 examples/src/test/scala/org/parboiled2/examples/CsvParserSpec.scala
  4. +41 −38 examples/src/test/scala/org/parboiled2/examples/JsonParserSpec.scala
  5. +174 −170 parboiled-core/src/test/scala/org/parboiled2/ActionSpec.scala
  6. +169 −158 parboiled-core/src/test/scala/org/parboiled2/BasicSpec.scala
  7. +62 −57 parboiled-core/src/test/scala/org/parboiled2/CalculatorSpec.scala
  8. +51 −45 parboiled-core/src/test/scala/org/parboiled2/CharPredicateSpec.scala
  9. +44 −21 parboiled-core/src/test/scala/org/parboiled2/CharUtilsSpec.scala
  10. +246 −241 parboiled-core/src/test/scala/org/parboiled2/CombinatorSpec.scala
  11. +21 −16 parboiled-core/src/test/scala/org/parboiled2/CustomCharAndStringExpansionSpec.scala
  12. +18 −13 parboiled-core/src/test/scala/org/parboiled2/CutSpec.scala
  13. +8 −5 parboiled-core/src/test/scala/org/parboiled2/DefaultArgumentsSpec.scala
  14. +249 −244 parboiled-core/src/test/scala/org/parboiled2/ErrorReportingSpec.scala
  15. +14 −9 parboiled-core/src/test/scala/org/parboiled2/MetaRuleSpec.scala
  16. +10 −7 parboiled-core/src/test/scala/org/parboiled2/ReductionTypeSpec.scala
  17. +21 −16 parboiled-core/src/test/scala/org/parboiled2/RunSubParserSpec.scala
  18. +23 −20 parboiled-core/src/test/scala/org/parboiled2/RunningSpec.scala
  19. +16 −11 parboiled-core/src/test/scala/org/parboiled2/TailrecSpec.scala
  20. +28 −16 parboiled-core/src/test/scala/org/parboiled2/TestParserSpec.scala
  21. +150 −111 parboiled-core/src/test/scala/org/parboiled2/ValueStackSpec.scala
  22. +7 −5 parboiled-core/src/test/scala/org/parboiled2/nestedpackage/AlienPackageParserSpec.scala
  23. +12 −11 parboiled-core/src/test/scala/org/parboiled2/util/Base64Spec.scala
  24. +16 −12 parboiled/src/test/scala/org/parboiled2/Base64ParsingSpec.scala
  25. +50 −47 parboiled/src/test/scala/org/parboiled2/DynamicRuleDispatchSpec.scala
  26. +4 −0 project/plugins.sbt
  27. +32 −31 scalaParser/src/test/scala/scalaparser/RealSourcesSpec.scala
  28. +1,061 −840 scalaParser/src/test/scala/scalaparser/SnippetSpec.scala
@@ -9,5 +9,11 @@ script:
- sbt "++ ${TRAVIS_SCALA_VERSION}" test "scalaParser/testOnly scalaparser.SnippetSpec"
matrix:
include:
- jdk: openjdk11
scala: 2.12.8
- name: "2.11.12 native"
scala: 2.11.12
before_script:
- curl https://raw.githubusercontent.com/scala-native/scala-native/master/scripts/travis_setup.sh | bash -x
script:
- sbt "++ ${TRAVIS_SCALA_VERSION}" parboiledCoreNative/test parboiledNative/test "scalaParser/testOnly scalaparser.SnippetSpec"
- scala: 2.12.8
jdk: openjdk11
@@ -1,7 +1,9 @@
import com.typesafe.sbt.SbtScalariform.ScalariformKeys

import scalariform.formatter.preferences._

import scala.xml.transform._
import scala.xml.{Node => XNode, NodeSeq}
import scala.xml.{NodeSeq, Node => XNode}
import sbtcrossproject.CrossPlugin.autoImport.{CrossType, crossProject}
import sbtcrossproject.CrossPlugin.autoImport._

@@ -73,12 +75,18 @@ val noPublishingSettings = Seq(
publishArtifact := false,
publishTo := Some(Resolver.file("Unused transient repository", file("target/unusedrepo"))))

val utestSettings = Seq(
testFrameworks := Seq(new TestFramework("utest.runner.Framework")))

/////////////////////// DEPENDENCIES /////////////////////////

def scalaReflect(v: String) = "org.scala-lang" % "scala-reflect" % v % "provided"
val shapeless = Def.setting("com.chuusai" %%% "shapeless" % "2.3.3" % "compile")
val specs2Core = Def.setting("org.specs2" %%% "specs2-core" % "4.4.1" % "test")
val specs2ScalaCheck = Def.setting("org.specs2" %%% "specs2-scalacheck" % "4.4.1" % "test")
val shapeless = Def.setting("com.chuusai" %%% "shapeless" % "2.3.3" % "compile")
val utest = Def.setting("com.lihaoyi" %%% "utest" % "0.6.6" % Test)
val scalaCheck = Def.setting("org.scalacheck" %%% "scalacheck" % "1.14.0" % Test)
// since ScalaCheck native is not available from the original authors @lolgab made a release
// see https://github.com/rickynils/scalacheck/issues/396#issuecomment-467782592
val scalaCheckNative = Def.setting("com.github.lolgab" %%% "scalacheck" % "1.14.1" % Test)

/////////////////////// PROJECTS /////////////////////////

@@ -93,7 +101,8 @@ lazy val examples = project
.dependsOn(parboiledJVM)
.settings(commonSettings)
.settings(noPublishingSettings)
.settings(libraryDependencies ++= Seq(specs2Core.value, "io.spray" %% "spray-json" % "1.3.5"))
.settings(libraryDependencies ++= Seq(utest.value, "io.spray" %% "spray-json" % "1.3.5"))
.settings(utestSettings)

lazy val bench = inputKey[Unit]("Runs the JSON parser benchmark with a simple standard config")

@@ -112,7 +121,8 @@ lazy val scalaParser = project
.dependsOn(parboiledJVM)
.settings(commonSettings)
.settings(noPublishingSettings)
.settings(libraryDependencies ++= Seq(shapeless.value, specs2Core.value))
.settings(libraryDependencies ++= Seq(shapeless.value, utest.value))
.settings(utestSettings)

lazy val parboiledOsgiSettings = osgiSettings ++ Seq(
OsgiKeys.exportPackage := Seq("org.parboiled2.*;version=${Bundle-Version}"),
@@ -121,7 +131,8 @@ lazy val parboiledOsgiSettings = osgiSettings ++ Seq(

lazy val parboiledJVM = parboiled.jvm
lazy val parboiledJS = parboiled.js
lazy val parboiled = crossProject(JSPlatform, JVMPlatform)
lazy val parboiledNative = parboiled.native
lazy val parboiled = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.crossType(CrossType.Pure)
.dependsOn(parboiledCore)
.settings(commonSettings)
@@ -137,8 +148,16 @@ lazy val parboiled = crossProject(JSPlatform, JVMPlatform)
mappings in (Compile, packageSrc) ++= (mappings in (parboiledCoreJS.project, Compile, packageSrc)).value,
mappings in (Compile, packageDoc) ++= (mappings in (parboiledCoreJS.project, Compile, packageDoc)).value
)
.nativeSettings(
mappings in (Compile, packageBin) ++= (mappings in (parboiledCoreNative.project, Compile, packageBin)).value,
mappings in (Compile, packageSrc) ++= (mappings in (parboiledCoreNative.project, Compile, packageSrc)).value,
mappings in (Compile, packageDoc) ++= (mappings in (parboiledCoreNative.project, Compile, packageDoc)).value,
nativeLinkStubs := true,
scalaVersion := "2.11.12",
crossScalaVersions := Seq("2.11.12")
)
.settings(
libraryDependencies ++= Seq(scalaReflect(scalaVersion.value), shapeless.value, specs2Core.value),
libraryDependencies ++= Seq(scalaReflect(scalaVersion.value), shapeless.value, utest.value),
mappings in (Compile, packageBin) ~= (_.groupBy(_._2).toSeq.map(_._2.head)), // filter duplicate outputs
mappings in (Compile, packageDoc) ~= (_.groupBy(_._2).toSeq.map(_._2.head)), // filter duplicate outputs
pomPostProcess := { // we need to remove the dependency onto the parboiledCore module from the POM
@@ -147,19 +166,35 @@ lazy val parboiled = crossProject(JSPlatform, JVMPlatform)
}
new RuleTransformer(filter).transform(_).head
}
).
enablePlugins(SbtOsgi).settings(parboiledOsgiSettings:_*)
)
.settings(utestSettings)
.enablePlugins(SbtOsgi).settings(parboiledOsgiSettings:_*)

lazy val generateActionOps = taskKey[Seq[File]]("Generates the ActionOps boilerplate source file")

lazy val parboiledCore = crossProject(JSPlatform, JVMPlatform).crossType(CrossType.Pure).in(file("parboiled-core"))
lazy val parboiledCore = crossProject(JSPlatform, JVMPlatform, NativePlatform).crossType(CrossType.Pure).in(file("parboiled-core"))
.settings(commonSettings)
.settings(formattingSettings)
.settings(noPublishingSettings)
.settings(utestSettings)
.settings(
libraryDependencies ++= Seq(scalaReflect(scalaVersion.value), shapeless.value, specs2Core.value, specs2ScalaCheck.value),
libraryDependencies ++= Seq(scalaReflect(scalaVersion.value), shapeless.value, utest.value),
generateActionOps := ActionOpsBoilerplate((sourceManaged in Compile).value, streams.value),
(sourceGenerators in Compile) += generateActionOps.taskValue)
(sourceGenerators in Compile) += generateActionOps.taskValue
)
.jvmSettings(
libraryDependencies ++= Seq(scalaCheck.value)
)
.jsSettings(
libraryDependencies ++= Seq(scalaCheck.value)
)
.nativeSettings(
nativeLinkStubs := true,
scalaVersion := "2.11.12",
crossScalaVersions := Seq("2.11.12"),
libraryDependencies ++= Seq(scalaCheckNative.value)
)

lazy val parboiledCoreJVM = parboiledCore.jvm
lazy val parboiledCoreJS = parboiledCore.js
lazy val parboiledCoreNative = parboiledCore.native
@@ -17,25 +17,28 @@
package org.parboiled2.examples

import org.parboiled2.examples.CsvParser.{Record, CsvFile}
import org.specs2.mutable.Specification
import utest._

class CsvParserSpec extends Specification {
object CsvParserSpec extends TestSuite {

"The CsvParser" should {
"correctly parse simple CSV test input" in {
CsvParser {
""""first_name","last_name","company_name","address","city","county","state","zip","phone1","phone2","email","web"
|"James","Butt", "Benton, John B Jr","6649 N Blue Gum St","New Orleans","Orleans","LA",70116,"504-621-8927","504-845-1427","jbutt@gmail.com","http://www.bentonjohnbjr.com"
|"Josephine","Darakjy","Chanay, Jeffrey A Esq","4 B Blue Ridge Blvd","Brighton","Livingston","MI",48116,"810-292-9388","810-374-9840","josephine_darakjy@darakjy.org","http://www.chanayjeffreyaesq.com"
|Art,"Venere","Chemel, James L Cpa","8 W Cerritos Ave #54","Bridgeport","Gloucester","NJ",08014 ,"856-636-8749","856-264-4130","art@venere.org","http://www.chemeljameslcpa.com"
|"Lenna","Paprocki","Feltz ""Printing"" Service", 639 Main St,"Anchorage","Anchorage","AK",99501,"907-385-4412","907-921-2010","lpaprocki@hotmail.com","http://www.feltzprintingservice.com"
|""".stripMargin
} === file(
record("first_name","last_name","company_name","address","city","county","state","zip","phone1","phone2","email","web"),
record("James","Butt", "Benton, John B Jr","6649 N Blue Gum St","New Orleans","Orleans","LA","70116","504-621-8927","504-845-1427","jbutt@gmail.com","http://www.bentonjohnbjr.com"),
record("Josephine","Darakjy","Chanay, Jeffrey A Esq","4 B Blue Ridge Blvd","Brighton","Livingston","MI","48116","810-292-9388","810-374-9840","josephine_darakjy@darakjy.org","http://www.chanayjeffreyaesq.com"),
record("Art","Venere","Chemel, James L Cpa","8 W Cerritos Ave #54","Bridgeport","Gloucester","NJ","08014 ","856-636-8749","856-264-4130","art@venere.org","http://www.chemeljameslcpa.com"),
record("Lenna","Paprocki","Feltz \"Printing\" Service"," 639 Main St","Anchorage","Anchorage","AK","99501","907-385-4412","907-921-2010","lpaprocki@hotmail.com","http://www.feltzprintingservice.com"))
val tests = Tests{

"The CsvParser" - {
"correctly parse simple CSV test input" - {
CsvParser {
""""first_name","last_name","company_name","address","city","county","state","zip","phone1","phone2","email","web"
|"James","Butt", "Benton, John B Jr","6649 N Blue Gum St","New Orleans","Orleans","LA",70116,"504-621-8927","504-845-1427","jbutt@gmail.com","http://www.bentonjohnbjr.com"
|"Josephine","Darakjy","Chanay, Jeffrey A Esq","4 B Blue Ridge Blvd","Brighton","Livingston","MI",48116,"810-292-9388","810-374-9840","josephine_darakjy@darakjy.org","http://www.chanayjeffreyaesq.com"
|Art,"Venere","Chemel, James L Cpa","8 W Cerritos Ave #54","Bridgeport","Gloucester","NJ",08014 ,"856-636-8749","856-264-4130","art@venere.org","http://www.chemeljameslcpa.com"
|"Lenna","Paprocki","Feltz ""Printing"" Service", 639 Main St,"Anchorage","Anchorage","AK",99501,"907-385-4412","907-921-2010","lpaprocki@hotmail.com","http://www.feltzprintingservice.com"
|""".stripMargin
} ==> file(
record("first_name","last_name","company_name","address","city","county","state","zip","phone1","phone2","email","web"),
record("James","Butt", "Benton, John B Jr","6649 N Blue Gum St","New Orleans","Orleans","LA","70116","504-621-8927","504-845-1427","jbutt@gmail.com","http://www.bentonjohnbjr.com"),
record("Josephine","Darakjy","Chanay, Jeffrey A Esq","4 B Blue Ridge Blvd","Brighton","Livingston","MI","48116","810-292-9388","810-374-9840","josephine_darakjy@darakjy.org","http://www.chanayjeffreyaesq.com"),
record("Art","Venere","Chemel, James L Cpa","8 W Cerritos Ave #54","Bridgeport","Gloucester","NJ","08014 ","856-636-8749","856-264-4130","art@venere.org","http://www.chemeljameslcpa.com"),
record("Lenna","Paprocki","Feltz \"Printing\" Service"," 639 Main St","Anchorage","Anchorage","AK","99501","907-385-4412","907-921-2010","lpaprocki@hotmail.com","http://www.feltzprintingservice.com"))
}
}
}

@@ -17,49 +17,52 @@
package org.parboiled2.examples

import scala.util.{Failure, Success}
import org.specs2.mutable.Specification
import utest._
import spray.json.{JsonParser => _, _}
import org.parboiled2._

class JsonParserSpec extends Specification {
object JsonParserSpec extends TestSuite {

"The JsonParser" should {
"parse 'null' to JsNull" in {
parse("null") === JsNull
}
"parse 'true' to JsTrue" in {
parse("true") === JsTrue
}
"parse 'false' to JsFalse" in {
parse("false") === JsFalse
}
"parse '0' to JsNumber" in {
parse("0") === JsNumber(0)
}
"parse '1.23' to JsNumber" in {
parse("1.23") === JsNumber(1.23)
}
"parse '-1E10' to JsNumber" in {
parse("-1E10") === JsNumber("-1E+10")
}
"parse '12.34e-10' to JsNumber" in {
parse("12.34e-10") === JsNumber("1.234E-9")
}
"parse \"xyz\" to JsString" in {
parse("\"xyz\"") === JsString("xyz")
}
"parse escapes in a JsString" in {
parse(""""\"\\/\b\f\n\r\t"""") === JsString("\"\\/\b\f\n\r\t")
parse("\"L\\" + "u00e4nder\"") === JsString("Länder")
val tests = Tests{

"The JsonParser" - {
"parse 'null' to JsNull" - {
parse("null") ==> JsNull
}
"parse 'true' to JsTrue" - {
parse("true") ==> JsTrue
}
"parse 'false' to JsFalse" - {
parse("false") ==> JsFalse
}
"parse '0' to JsNumber" - {
parse("0") ==> JsNumber(0)
}
"parse '1.23' to JsNumber" - {
parse("1.23") ==> JsNumber(1.23)
}
"parse '-1E10' to JsNumber" - {
parse("-1E10") ==> JsNumber("-1E+10")
}
"parse '12.34e-10' to JsNumber" - {
parse("12.34e-10") ==> JsNumber("1.234E-9")
}
"parse \"xyz\" to JsString" - {
parse("\"xyz\"") ==> JsString("xyz")
}
"parse escapes in a JsString" - {
parse(""""\"\\/\b\f\n\r\t"""") ==> JsString("\"\\/\b\f\n\r\t")
parse("\"L\\" + "u00e4nder\"") ==> JsString("Länder")
}
"properly parse a simple JsObject" - (
parse(""" { "key" :42, "key2": "value" }""") ==>
JsObject("key" -> JsNumber(42), "key2" -> JsString("value"))
)
"properly parse a simple JsArray" - (
parse("""[null, 1.23 ,{"key":true } ] """) ==>
JsArray(JsNull, JsNumber(1.23), JsObject("key" -> JsTrue))
)
}
"properly parse a simple JsObject" in (
parse(""" { "key" :42, "key2": "value" }""") ===
JsObject("key" -> JsNumber(42), "key2" -> JsString("value"))
)
"properly parse a simple JsArray" in (
parse("""[null, 1.23 ,{"key":true } ] """) ===
JsArray(JsNull, JsNumber(1.23), JsObject("key" -> JsTrue))
)
}

def parse(s: String): JsValue = {
Oops, something went wrong.

0 comments on commit 809cfbd

Please sign in to comment.
You can’t perform that action at this time.