Skip to content
This repository was archived by the owner on Oct 24, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
on:
push:
branches:
- master
pull_request:
branches:
- master


jobs:
ci:
strategy:
matrix:
jvm:
- temurin:1.8.0-422
- temurin:1.21
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: coursier/cache-action@v6
- uses: coursier/setup-action@v1
with:
jvm: ${{ matrix.jvm }}
apps: sbt
- name: Run tests
run: sbt +test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ lib_managed/
src_managed/
project/boot/
project/plugins/project/
/.bsp

# Scala-IDE specific
.scala_dependencies
Expand Down
55 changes: 21 additions & 34 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
// shadow sbt-scalajs' crossProject and CrossType from Scala.js 0.6.x
import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType}

val Scala2_11 = "2.11.12"
val Scala2_12 = "2.12.10"
val Scala2_13 = "2.13.1"
val FastParse = "1.0.1"
val Shapeless = "2.3.3"
val ScalaCheck = "1.14.2"
val ScalaTest = "3.0.8"
val ScalaTestNative = "3.2.0-SNAP10"
val Scala2_12 = "2.12.19"
val Scala2_13 = "2.13.14"
val Scala3 = "3.3.3"
val FastParse = "3.1.1"
val Shapeless = "2.3.12"
val ScalaCheck = "1.18.1"
val ScalaTest = "3.2.19"

val ScalaTestScalaCheck = s"$ScalaTest.0"

val SharedSettings = Seq(
name := "toml-scala",
organization := "tech.sparse",

scalaVersion := Scala2_13,
crossScalaVersions := Seq(Scala2_13, Scala2_12, Scala2_11),
crossScalaVersions := Seq(Scala3, Scala2_13, Scala2_12),

pomExtra :=
<url>https://github.com/sparsetech/toml-scala</url>
Expand All @@ -40,37 +41,23 @@ val SharedSettings = Seq(
lazy val root = project.in(file("."))
.aggregate(toml.js, toml.jvm, toml.native)
.settings(SharedSettings: _*)
.settings(skip in publish := true)
.settings(publish / skip := true)

lazy val toml =
crossProject(JSPlatform, JVMPlatform, NativePlatform)
.in(file("."))
.settings(SharedSettings)
.settings(
libraryDependencies ++= Seq(
"org.scalameta" %%% "fastparse" % FastParse,
"com.chuusai" %%% "shapeless" % Shapeless
)
)
.jsSettings(
libraryDependencies ++= Vector(
"org.scalacheck" %%% "scalacheck" % ScalaCheck % "test",
"org.scalatest" %%% "scalatest" % ScalaTest % "test"
)
)
.jvmSettings(
libraryDependencies ++= Vector(
"org.scalacheck" %% "scalacheck" % ScalaCheck % "test",
"org.scalatest" %% "scalatest" % ScalaTest % "test"
)
)
.nativeSettings(
scalaVersion := Scala2_11,
crossScalaVersions := Seq(Scala2_11),
// See https://github.com/scalalandio/chimney/issues/78#issuecomment-419705142
nativeLinkStubs := true,
libraryDependencies ++= Vector(
"org.scalatest" %%% "scalatest" % ScalaTestNative % "test"
"com.lihaoyi" %%% "fastparse" % FastParse,
"org.scalacheck" %%% "scalacheck" % ScalaCheck % Test,
"org.scalatest" %%% "scalatest" % ScalaTest % Test,
"org.scalatestplus" %%% s"scalacheck-${ScalaCheck.split('.').take(2).mkString("-")}" % ScalaTestScalaCheck % Test
),
excludeFilter in Test := "*GeneratedSpec*" || "*Generators*"
libraryDependencies ++= {
if(scalaVersion.value.startsWith("3."))
Seq.empty
else
Seq("com.chuusai" %%% "shapeless" % Shapeless)
}
)
7 changes: 7 additions & 0 deletions js-native/src/main/scala/toml/PlatformRules.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package toml

import fastparse._

trait PlatformRules {
def date[$: P] = P(CharIn()).map(_ => null.asInstanceOf[Value])
}
7 changes: 0 additions & 7 deletions js/src/main/scala/toml/PlatformRules.scala

This file was deleted.

13 changes: 7 additions & 6 deletions jvm/src/main/scala/toml/PlatformRules.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package toml

import java.time._

import scala.meta.internal.fastparse.all._
import fastparse._
import fastparse.NoWhitespace._

trait PlatformRules { this: Rules =>
private val TenPowers =
List(1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000)

val localTime: Parser[Value.Time] = P(
def localTime[$: P]: P[Value.Time] = P(
digit.rep(2).! ~ ":" ~ digit.rep(2).! ~ ":" ~ digit.rep(2).! ~ ("." ~ digit.rep.!).?
).map { case (h, m, s, ns) =>
val nano = ns.map { str =>
Expand All @@ -19,24 +20,24 @@ trait PlatformRules { this: Rules =>
Value.Time(LocalTime.of(h.toInt, m.toInt, s.toInt, nano))
}

val localDate: Parser[Value.Date] = P(
def localDate[$: P]: P[Value.Date] = P(
digit.rep(4).! ~ "-" ~ digit.rep(2).! ~ "-" ~ digit.rep(2).!
).map { case (y, m, d) =>
Value.Date(LocalDate.of(y.toInt, m.toInt, d.toInt))
}

val localDateTime: Parser[Value.DateTime] = P(
def localDateTime[$: P]: P[Value.DateTime] = P(
localDate ~ "T" ~ localTime
).map { case (date, time) =>
Value.DateTime(LocalDateTime.of(date.value, time.value))
}

val offsetDateTime: Parser[Value.OffsetDateTime] = P(
def offsetDateTime[$: P]: P[Value.OffsetDateTime] = P(
localDateTime ~ ("Z" | (("-" | "+") ~ digit.rep(2) ~ ":" ~ digit.rep(2))).!
).map { case (dateTime, offset) =>
Value.OffsetDateTime(
OffsetDateTime.of(dateTime.value, ZoneOffset.of(offset)))
}

val date = P(offsetDateTime | localDateTime | localDate | localTime)
def date[$: P] = P(offsetDateTime | localDateTime | localDate | localTime)
}
20 changes: 20 additions & 0 deletions jvm/src/test/scala-2/toml/DateSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package toml

import java.time._

import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
import fastparse.Parsed._

class DateSpec extends AnyFunSuite with Matchers {
import TestHelpers._

test("Codec derivation") {
import Codecs._

case class Root(ld: LocalDate)

val toml = "ld = 1979-05-27"
assert(Toml.parseAs[Root](toml) == Right(Root(LocalDate.of(1979, 5, 27))))
}
}
13 changes: 7 additions & 6 deletions jvm/src/test/scala/toml/DateGenSpec.scala
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
package toml

import org.scalatest.prop._
import org.scalatest.{Matchers, PropSpec}
import org.scalatest.propspec.AnyPropSpec
import org.scalatest.matchers.should.Matchers
import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks

import scala.meta.internal.fastparse.all._
import scala.meta.internal.fastparse.core.Parsed.{Failure, Success}
import fastparse._
import fastparse.Parsed.{Failure, Success}

class DateGenSpec extends PropSpec with ScalaCheckPropertyChecks with Matchers {
class DateGenSpec extends AnyPropSpec with ScalaCheckPropertyChecks with Matchers {
import TestHelpers._

property("parse dates following the RFC 3339 spec (`date` parser)") {
import Generators.Dates._
forAll(dateFormatGen) { s =>
shouldBeSuccess(Rules.offsetDateTime.parse(s))
shouldBeSuccess(parse(s, Rules.offsetDateTime(_)))
}
}

property("parse dates following the RFC 3339 spec") {
import Generators.Dates._
forAll(dateFormatGen) { s =>
shouldBeSuccess(Rules.elem.parse(s))
shouldBeSuccess(parse(s, Rules.elem(_)))
}
}
}
77 changes: 0 additions & 77 deletions jvm/src/test/scala/toml/DateSpec.scala

This file was deleted.

7 changes: 4 additions & 3 deletions jvm/src/test/scala/toml/FileSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package toml
import java.time._
import java.io.File

import org.scalatest.{FunSuite, Matchers}
import scala.meta.internal.fastparse.core.Parsed._
import org.scalatest.matchers.should.Matchers
import org.scalatest.funsuite.AnyFunSuite
import fastparse.Parsed._

class FileSpec extends FunSuite with Matchers {
class FileSpec extends AnyFunSuite with Matchers {
import TestHelpers._

test("Parse multi-line strings") {
Expand Down
3 changes: 0 additions & 3 deletions native/src/main/scala/toml/PlatformCodecs.scala

This file was deleted.

7 changes: 0 additions & 7 deletions native/src/main/scala/toml/PlatformRules.scala

This file was deleted.

3 changes: 0 additions & 3 deletions native/src/main/scala/toml/PlatformValue.scala

This file was deleted.

2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 1.2.8
sbt.version = 1.10.0
8 changes: 4 additions & 4 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
logLevel := Level.Warn

addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.1")
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "0.6.1")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.29")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.3.9")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.3.0")
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.3.0")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.16.0")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.5.4")
Loading